kubernetes-deploy 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35d948d40aa56e5e5a6768970fd3337a23567aa5
4
- data.tar.gz: 69e976d7ff55b67d735e35def340386abb007168
3
+ metadata.gz: 845bf8bd854e94df070d5637d37a8678f9a92411
4
+ data.tar.gz: 32a57ce86b607e98133ec04875d88f4ffa37495c
5
5
  SHA512:
6
- metadata.gz: 69ff1c41cc62e2489680586a97f6392678c1110ac0cd729d5d90fcb3e0d27012eae5db56dccb7edd88e24dda0d7604ba7bc83a96ecc0b3ffab935c6128da4012
7
- data.tar.gz: 0fcf662530afff4ffff89a4f3eba3ef2b92dc61d3ca7f5c6bc4810987017405192350f9137d1a0da79b4bfeb75bf3fa3f4a9ac1462df2699bbd060535c39056c
6
+ metadata.gz: 8a6b635d9554e3737a5330fe4df509ec6ca5f5b1a0a3abac8016a199b084620d36ac47116e7863c9b8ebbda3e5a6a264b4b24da6262e772ee0250e2d98e48ea4
7
+ data.tar.gz: c479251f382257c6be386422f13d87ab4252f4adaa91b5d1600aa9df30b0d8687b9bb0612642275d2dc4860fc15871bb3afdad8f59e6311e1e120b3d9da11c7a
@@ -28,6 +28,14 @@ module KubernetesDeploy
28
28
  )
29
29
  end
30
30
 
31
+ def build_policy_v1beta1_kubeclient(context)
32
+ _build_kubeclient(
33
+ api_version: "v1beta1",
34
+ context: context,
35
+ endpoint_path: "/apis/policy/"
36
+ )
37
+ end
38
+
31
39
  def _build_kubeclient(api_version:, context:, endpoint_path: nil)
32
40
  config = GoogleFriendlyConfig.read(ENV.fetch("KUBECONFIG"))
33
41
  unless config.contexts.include?(context)
@@ -36,6 +36,7 @@ module KubernetesDeploy
36
36
  when 'persistentvolumeclaim' then PersistentVolumeClaim.new(name, namespace, context, file)
37
37
  when 'service' then Service.new(name, namespace, context, file)
38
38
  when 'podtemplate' then PodTemplate.new(name, namespace, context, file)
39
+ when 'poddisruptionbudget' then PodDisruptionBudget.new(name, namespace, context, file)
39
40
  else self.new(name, namespace, context, file).tap { |r| r.type = type }
40
41
  end
41
42
  end
@@ -99,6 +100,12 @@ module KubernetesDeploy
99
100
  false
100
101
  end
101
102
 
103
+ # Expected values: :apply, :replace, :replace_force
104
+ def deploy_method
105
+ # TPRs must use update for now: https://github.com/kubernetes/kubernetes/issues/39906
106
+ tpr? ? :replace : :apply
107
+ end
108
+
102
109
  def status_data
103
110
  {
104
111
  group: group_name,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module KubernetesDeploy
3
3
  class Cloudsql < KubernetesResource
4
- TIMEOUT = 5.minutes
4
+ TIMEOUT = 10.minutes
5
5
 
6
6
  def initialize(name, namespace, context, file)
7
7
  @name = name
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ module KubernetesDeploy
3
+ class PodDisruptionBudget < KubernetesResource
4
+ TIMEOUT = 10.seconds
5
+
6
+ def initialize(name, namespace, context, file)
7
+ @name = name
8
+ @namespace = namespace
9
+ @context = context
10
+ @file = file
11
+ end
12
+
13
+ def sync
14
+ _, _err, st = run_kubectl("get", type, @name)
15
+ @found = st.success?
16
+ @status = @found ? "Available" : "Unknown"
17
+ log_status
18
+ end
19
+
20
+ def deploy_succeeded?
21
+ exists?
22
+ end
23
+
24
+ def deploy_method
25
+ # Required until https://github.com/kubernetes/kubernetes/issues/45398 changes
26
+ :replace_force
27
+ end
28
+
29
+ def exists?
30
+ @found
31
+ end
32
+ end
33
+ end
@@ -31,6 +31,7 @@ module KubernetesDeploy
31
31
  @logger = logger
32
32
  @kubeclient = build_v1_kubeclient(context)
33
33
  @v1beta1_kubeclient = build_v1beta1_kubeclient(context)
34
+ @policy_v1beta1_kubeclient = build_policy_v1beta1_kubeclient(context)
34
35
  end
35
36
 
36
37
  def perform(deployments_names = nil)
@@ -17,6 +17,7 @@ require 'kubernetes-deploy/kubernetes_resource'
17
17
  service
18
18
  pod_template
19
19
  bugsnag
20
+ pod_disruption_budget
20
21
  ).each do |subresource|
21
22
  require "kubernetes-deploy/kubernetes_resource/#{subresource}"
22
23
  end
@@ -295,25 +296,41 @@ MSG
295
296
  KubernetesDeploy.logger.info("All required parameters and files are present")
296
297
  end
297
298
 
298
- def update_tprs(resources)
299
- resources.each do |r|
299
+ def deploy_resources(resources, prune: false)
300
+ KubernetesDeploy.logger.info("Deploying resources:")
301
+
302
+ # Apply can be done in one large batch, the rest have to be done individually
303
+ applyables, individuals = resources.partition { |r| r.deploy_method == :apply }
304
+
305
+ individuals.each do |r|
300
306
  KubernetesDeploy.logger.info("- #{r.id}")
301
307
  r.deploy_started = Time.now.utc
302
- _, _, st = run_kubectl("replace", "-f", r.file.path)
308
+ case r.deploy_method
309
+ when :replace
310
+ _, _, st = run_kubectl("replace", "-f", r.file.path)
311
+ when :replace_force
312
+ _, _, st = run_kubectl("replace", "--force", "-f", r.file.path)
313
+ else
314
+ # Fail Fast! This is a programmer mistake.
315
+ raise ArgumentError, "Unexpected deploy method! (#{r.deploy_method.inspect})"
316
+ end
303
317
 
304
318
  unless st.success?
305
319
  # it doesn't exist so we can't replace it
306
- run_kubectl("create", "-f", r.file.path)
320
+ _, err, st = run_kubectl("create", "-f", r.file.path)
321
+ unless st.success?
322
+ raise FatalDeploymentError, <<-MSG.strip_heredoc
323
+ Failed to replace or create resource: #{r.id}
324
+ #{err}
325
+ MSG
326
+ end
307
327
  end
308
328
  end
309
- end
310
329
 
311
- def deploy_resources(resources, prune: false)
312
- KubernetesDeploy.logger.info("Deploying resources:")
330
+ apply_all(applyables, prune)
331
+ end
313
332
 
314
- # TPRs must use update for now: https://github.com/kubernetes/kubernetes/issues/39906
315
- tprs, resources = resources.partition(&:tpr?)
316
- update_tprs(tprs)
333
+ def apply_all(resources, prune)
317
334
  return unless resources.present?
318
335
 
319
336
  command = ["apply"]
@@ -1,3 +1,3 @@
1
1
  module KubernetesDeploy
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
3
3
  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.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kir Shatrov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-05-10 00:00:00.000000000 Z
13
+ date: 2017-05-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -188,6 +188,7 @@ files:
188
188
  - lib/kubernetes-deploy/kubernetes_resource/ingress.rb
189
189
  - lib/kubernetes-deploy/kubernetes_resource/persistent_volume_claim.rb
190
190
  - lib/kubernetes-deploy/kubernetes_resource/pod.rb
191
+ - lib/kubernetes-deploy/kubernetes_resource/pod_disruption_budget.rb
191
192
  - lib/kubernetes-deploy/kubernetes_resource/pod_template.rb
192
193
  - lib/kubernetes-deploy/kubernetes_resource/redis.rb
193
194
  - lib/kubernetes-deploy/kubernetes_resource/service.rb