krane 1.1.3 → 1.1.4

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
  SHA256:
3
- metadata.gz: d24b8a158239b66ab2f5ee126937935c9942dfea2336fe213410326e446c30dc
4
- data.tar.gz: 44ee52b5123fd507c62f266b371f14edc606f2738550e47c39b5e2995b907b0b
3
+ metadata.gz: 72b8d113bb3226dd5545832e6913a50e34110afd2402508f920f7ba9c11a3e50
4
+ data.tar.gz: e52d4e9f325942e94d2d5395111a73e248f649397116d50113a2ad0be3507aae
5
5
  SHA512:
6
- metadata.gz: 37c9f7d48d131277dac55b357ef895b63e5822ab7428954a1d7b871ce50594908df47bfc82320dd4f01b4e6d790b3383e9eb214ba42f98f03afd0c5332ebcb4c
7
- data.tar.gz: e3f98ac0a1c55fdb63f88977cc9fad4d72c3ec437f7795ceaffbcc2664387b60d7f4ea6e75e3cc596f73b823371063d7dcc5d80ba63efe44b000dd9b02498551
6
+ metadata.gz: e228d7cc83a98b9c35d7ecc6570dc85e0a73358b773b8331a12042ce50205bf10a403d88a0b380ef24298b1663d8651956d86aac54c61fd96f3c1d2196dba8b3
7
+ data.tar.gz: e90ced18d7509a66d630def61a9051bce06fb502652331ba8f2cc13b985b97595a19947285d8d438b7dfc04f1384eb49daa8fba23658e3148f25a021515b3b5f
@@ -1,5 +1,13 @@
1
1
  ## next
2
2
 
3
+ ## 1.1.4
4
+
5
+ *Bug Fixes*
6
+ - Properly look up constant on Krane namespace. [#720](https://github.com/Shopify/krane/pull/720)
7
+
8
+ *Enhancements*
9
+ - Allow to configure `image_tag` when using task runner. [#719](https://github.com/Shopify/krane/pull/719)
10
+
3
11
  ## 1.1.3
4
12
 
5
13
  *Bug Fixes*
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ module Krane
3
+ class ContainerOverrides
4
+ attr_reader :command, :arguments, :env_vars, :image_tag
5
+
6
+ def initialize(command: nil, arguments: nil, env_vars: [], image_tag: nil)
7
+ @command = command
8
+ @arguments = arguments
9
+ @env_vars = env_vars
10
+ @image_tag = image_tag
11
+ end
12
+
13
+ def apply!(container)
14
+ container.command = command if command
15
+ container.args = arguments if arguments
16
+
17
+ if image_tag
18
+ image = container.image
19
+ base_image, _old_tag = image.split(':')
20
+ new_image = "#{base_image}:#{image_tag}"
21
+
22
+ container.image = new_image
23
+ end
24
+
25
+ env_args = env_vars.map do |env|
26
+ key, value = env.split('=', 2)
27
+ { name: key, value: value }
28
+ end
29
+ container.env ||= []
30
+ container.env = container.env.map(&:to_h) + env_args
31
+ end
32
+ end
33
+ end
@@ -60,8 +60,8 @@ module Krane
60
60
  end
61
61
 
62
62
  def class_for_kind(kind)
63
- if Krane.const_defined?(kind)
64
- Krane.const_get(kind)
63
+ if Krane.const_defined?(kind, false)
64
+ Krane.const_get(kind, false)
65
65
  end
66
66
  rescue NameError
67
67
  nil
@@ -9,6 +9,7 @@ require 'krane/resource_watcher'
9
9
  require 'krane/kubernetes_resource'
10
10
  require 'krane/kubernetes_resource/pod'
11
11
  require 'krane/runner_task_config_validator'
12
+ require 'krane/container_overrides'
12
13
 
13
14
  module Krane
14
15
  # Run a pod that exits upon completing a task
@@ -50,7 +51,7 @@ module Krane
50
51
  # @param verify_result [Boolean] Wait for completion and verify pod success
51
52
  #
52
53
  # @return [nil]
53
- def run!(template:, command:, arguments:, env_vars: [], verify_result: true)
54
+ def run!(template:, command:, arguments:, env_vars: [], image_tag: nil, verify_result: true)
54
55
  start = Time.now.utc
55
56
  @logger.reset
56
57
 
@@ -59,8 +60,13 @@ module Krane
59
60
  @logger.info("Validating configuration")
60
61
  verify_config!(template)
61
62
  @logger.info("Using namespace '#{@namespace}' in context '#{@context}'")
62
-
63
- pod = build_pod(template, command, arguments, env_vars, verify_result)
63
+ container_overrides = ContainerOverrides.new(
64
+ command: command,
65
+ arguments: arguments,
66
+ env_vars: env_vars,
67
+ image_tag: image_tag
68
+ )
69
+ pod = build_pod(template, container_overrides, verify_result)
64
70
  validate_pod(pod)
65
71
 
66
72
  @logger.phase_heading("Running pod")
@@ -98,11 +104,12 @@ module Krane
98
104
  raise FatalDeploymentError, msg
99
105
  end
100
106
 
101
- def build_pod(template_name, command, args, env_vars, verify_result)
107
+ def build_pod(template_name, container_overrides, verify_result)
102
108
  task_template = get_template(template_name)
103
109
  @logger.info("Using template '#{template_name}'")
104
110
  pod_template = build_pod_definition(task_template)
105
- set_container_overrides!(pod_template, command, args, env_vars)
111
+ container = extract_task_runner_container(pod_template)
112
+ container_overrides.apply!(container)
106
113
  ensure_valid_restart_policy!(pod_template, verify_result)
107
114
  Pod.new(namespace: @namespace, context: @context, logger: @logger, stream_logs: true,
108
115
  definition: pod_template.to_hash.deep_stringify_keys, statsd_tags: [])
@@ -165,7 +172,7 @@ module Krane
165
172
  pod_definition
166
173
  end
167
174
 
168
- def set_container_overrides!(pod_definition, command, args, env_vars)
175
+ def extract_task_runner_container(pod_definition)
169
176
  container = pod_definition.spec.containers.find { |cont| cont.name == 'task-runner' }
170
177
  if container.nil?
171
178
  message = "Pod spec does not contain a template container called 'task-runner'"
@@ -173,15 +180,7 @@ module Krane
173
180
  raise TaskConfigurationError, message
174
181
  end
175
182
 
176
- container.command = command if command
177
- container.args = args if args
178
-
179
- env_args = env_vars.map do |env|
180
- key, value = env.split('=', 2)
181
- { name: key, value: value }
182
- end
183
- container.env ||= []
184
- container.env = container.env.map(&:to_h) + env_args
183
+ container
185
184
  end
186
185
 
187
186
  def ensure_valid_restart_policy!(template, verify)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Krane
3
- VERSION = "1.1.3"
3
+ VERSION = "1.1.4"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krane
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Verey
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-04-23 00:00:00.000000000 Z
13
+ date: 2020-06-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -436,6 +436,7 @@ files:
436
436
  - lib/krane/concerns/template_reporting.rb
437
437
  - lib/krane/concurrency.rb
438
438
  - lib/krane/container_logs.rb
439
+ - lib/krane/container_overrides.rb
439
440
  - lib/krane/deferred_summary_logging.rb
440
441
  - lib/krane/delayed_exceptions.rb
441
442
  - lib/krane/deploy_task.rb