kubernetes-deploy 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0614c3851898f064ec1dfbae1f25fdd1fda70740
4
- data.tar.gz: 973f4a9d5007d95b10771b3dcc5e42564d36744e
3
+ metadata.gz: 272fadd954c2e206c412aca3e26d5efde55fd9e1
4
+ data.tar.gz: 999e798b55468bdd5b5ffc91438b95c0560d6d6d
5
5
  SHA512:
6
- metadata.gz: a5b60bf891dfd6aef2edb0b7ec7f7df576c56eb93a4c04747d705e1ff4b2e476e26725e6f21ed0e4ab04e594f1a20019b21f571870b4d25e9b11377c323eaac2
7
- data.tar.gz: 683b10bf4f0dd1794fd819d53f8871623a75d0f4bb2fb7185584bf4b5113fa7d0e3022bf60e2a1d32d6e1523b16b7b95be5291fc3494b74ec2d4c0ae8a307a63
6
+ metadata.gz: a30a0c161a519c6c58779ea8d155bf0970d2afae90a8e2c68c8853ef8fa019ff46ea914c24262981329f1a28ab7bf4eac89d0e03f33fd96f771ba8fc6b87fbdb
7
+ data.tar.gz: e8ddd22ae6d095a5169a7ce0a131b40e2595d70cd9bf913486a2dd85b6c5dbe823917bb1ae2006cdf4d7b2c2f06c8b71d816ecb09e3d707d705ce33186935c55
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+ module KubernetesDeploy
3
+ class DaemonSet < KubernetesResource
4
+ TIMEOUT = 5.minutes
5
+
6
+ def sync
7
+ raw_json, _err, st = kubectl.run("get", type, @name, "--output=json")
8
+ @found = st.success?
9
+
10
+ if @found
11
+ daemonset_data = JSON.parse(raw_json)
12
+ @current_generation = daemonset_data["metadata"]["generation"]
13
+ @observed_generation = daemonset_data["status"]["observedGeneration"]
14
+ @rollout_data = daemonset_data["status"]
15
+ .slice("currentNumberScheduled", "desiredNumberScheduled", "numberReady")
16
+ @status = @rollout_data.map { |state_replicas, num| "#{num} #{state_replicas}" }.join(", ")
17
+ @pods = find_pods(daemonset_data)
18
+ else # reset
19
+ @rollout_data = { "currentNumberScheduled" => 0 }
20
+ @current_generation = 1 # to make sure the current and observed generations are different
21
+ @observed_generation = 0
22
+ @status = nil
23
+ @pods = []
24
+ end
25
+ end
26
+
27
+ def deploy_succeeded?
28
+ @rollout_data["desiredNumberScheduled"].to_i == @rollout_data["currentNumberScheduled"].to_i &&
29
+ @rollout_data["desiredNumberScheduled"].to_i == @rollout_data["numberReady"].to_i &&
30
+ @current_generation == @observed_generation
31
+ end
32
+
33
+ def deploy_failed?
34
+ @pods.present? && @pods.any?(&:deploy_failed?)
35
+ end
36
+
37
+ def failure_message
38
+ @pods.map(&:failure_message).compact.uniq.join("\n")
39
+ end
40
+
41
+ def timeout_message
42
+ @pods.map(&:timeout_message).compact.uniq.join("\n")
43
+ end
44
+
45
+ def deploy_timed_out?
46
+ super || @pods.present? && @pods.any?(&:deploy_timed_out?)
47
+ end
48
+
49
+ def exists?
50
+ @found
51
+ end
52
+
53
+ def fetch_events
54
+ own_events = super
55
+ return own_events unless @pods.present?
56
+ most_useful_pod = @pods.find(&:deploy_failed?) || @pods.find(&:deploy_timed_out?) || @pods.first
57
+ own_events.merge(most_useful_pod.fetch_events)
58
+ end
59
+
60
+ def fetch_logs
61
+ most_useful_pod = @pods.find(&:deploy_failed?) || @pods.find(&:deploy_timed_out?) || @pods.first
62
+ most_useful_pod.fetch_logs
63
+ end
64
+
65
+ private
66
+
67
+ def find_pods(ds_data)
68
+ label_string = ds_data["spec"]["selector"]["matchLabels"].map { |k, v| "#{k}=#{v}" }.join(",")
69
+ raw_json, _err, st = kubectl.run("get", "pods", "-a", "--output=json", "--selector=#{label_string}")
70
+ return [] unless st.success?
71
+
72
+ all_pods = JSON.parse(raw_json)["items"]
73
+ template_generation = ds_data["spec"]["templateGeneration"]
74
+
75
+ latest_pods = all_pods.find_all do |pod|
76
+ next unless owners = pod.dig("metadata", "ownerReferences")
77
+ owners.any? { |ref| ref["uid"] == ds_data["metadata"]["uid"] } &&
78
+ pod["metadata"]["labels"]["pod-template-generation"].to_i == template_generation.to_i
79
+ end
80
+ return unless latest_pods.present?
81
+
82
+ latest_pods.each_with_object([]) do |pod_data, relevant_pods|
83
+ pod = Pod.new(
84
+ namespace: namespace,
85
+ context: context,
86
+ definition: pod_data,
87
+ logger: @logger,
88
+ parent: "#{@name.capitalize} daemon set",
89
+ deploy_started: @deploy_started
90
+ )
91
+ pod.sync(pod_data)
92
+ relevant_pods << pod
93
+ end
94
+ end
95
+ end
96
+ end
@@ -20,6 +20,7 @@ require 'kubernetes-deploy/kubernetes_resource'
20
20
  pod_disruption_budget
21
21
  replica_set
22
22
  service_account
23
+ daemon_set
23
24
  ).each do |subresource|
24
25
  require "kubernetes-deploy/kubernetes_resource/#{subresource}"
25
26
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module KubernetesDeploy
3
- VERSION = "0.11.1"
3
+ VERSION = "0.11.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubernetes-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Verey
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-07-28 00:00:00.000000000 Z
12
+ date: 2017-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -214,6 +214,7 @@ files:
214
214
  - lib/kubernetes-deploy/kubernetes_resource/bugsnag.rb
215
215
  - lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb
216
216
  - lib/kubernetes-deploy/kubernetes_resource/config_map.rb
217
+ - lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb
217
218
  - lib/kubernetes-deploy/kubernetes_resource/deployment.rb
218
219
  - lib/kubernetes-deploy/kubernetes_resource/ingress.rb
219
220
  - lib/kubernetes-deploy/kubernetes_resource/persistent_volume_claim.rb