Skip to content

Commit

Permalink
Update argument names for DeployTask
Browse files Browse the repository at this point in the history
  • Loading branch information
dirceu committed Nov 11, 2019
1 parent cf58402 commit f57a0e6
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions exe/kubernetes-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ begin
namespace: namespace,
context: context,
current_sha: current_sha,
template_paths: paths,
filenames: paths,
bindings: bindings,
logger: logger,
max_watch_seconds: max_watch_seconds,
global_timeout: max_watch_seconds,
selector: selector,
allow_globals: true
)
Expand Down
4 changes: 2 additions & 2 deletions lib/krane/cli/deploy_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def self.from_options(namespace, context, options)
namespace: namespace,
context: context,
current_sha: options['current-sha'],
template_paths: paths,
filenames: paths,
bindings: bindings_parser.parse,
logger: logger,
max_watch_seconds: ::Krane::DurationParser.new(options["global-timeout"]).parse!.to_i,
global_timeout: ::Krane::DurationParser.new(options["global-timeout"]).parse!.to_i,
selector: selector,
protected_namespaces: protected_namespaces,
)
Expand Down
12 changes: 6 additions & 6 deletions lib/krane/deprecated_deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ def server_version
# @param logger [Object] Logger object (defaults to an instance of Krane::FormattedLogger)
# @param kubectl_instance [Kubectl] Kubectl instance
# @param bindings [Hash] Bindings parsed by Krane::BindingsParser
# @param max_watch_seconds [Integer] Timeout in seconds
# @param global_timeout [Integer] Timeout in seconds
# @param selector [Hash] Selector(s) parsed by Krane::LabelSelector
# @param template_paths [Array<String>] An array of template paths
# @param filenames [Array<String>] An array of template paths
# @param template_dir [String] Path to a directory with templates (deprecated)
# @param protected_namespaces [Array<String>] Array of protected Kubernetes namespaces (defaults
# to Krane::DeployTask::PROTECTED_NAMESPACES)
# @param render_erb [Boolean] Enable ERB rendering
def initialize(namespace:, context:, current_sha:, logger: nil, kubectl_instance: nil, bindings: {},
max_watch_seconds: nil, selector: nil, template_paths: [], template_dir: nil, protected_namespaces: nil,
global_timeout: nil, selector: nil, filenames: [], template_dir: nil, protected_namespaces: nil,
render_erb: true, allow_globals: false)
template_dir = File.expand_path(template_dir) if template_dir
template_paths = (template_paths.map { |path| File.expand_path(path) } << template_dir).compact
template_paths = (filenames.map { |path| File.expand_path(path) } << template_dir).compact

@logger = logger || Krane::FormattedLogger.build(namespace, context)
@template_sets = TemplateSets.from_dirs_and_files(paths: template_paths, logger: @logger)
Expand All @@ -140,7 +140,7 @@ def initialize(namespace:, context:, current_sha:, logger: nil, kubectl_instance
@context = context
@current_sha = current_sha
@kubectl = kubectl_instance
@max_watch_seconds = max_watch_seconds
@global_timeout = global_timeout
@selector = selector
@protected_namespaces = protected_namespaces || PROTECTED_NAMESPACES
@render_erb = render_erb
Expand Down Expand Up @@ -217,7 +217,7 @@ def run!(verify_result: true, allow_protected_ns: false, prune: true)

def resource_deployer
@resource_deployer ||= Krane::ResourceDeployer.new(task_config: @task_config,
prune_whitelist: prune_whitelist, max_watch_seconds: @max_watch_seconds,
prune_whitelist: prune_whitelist, global_timeout: @global_timeout,
selector: @selector, statsd_tags: statsd_tags, current_sha: @current_sha)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/krane/global_deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GlobalDeployTask
# @param context [String] Kubernetes context
# @param global_timeout [Integer] Timeout in seconds
# @param selector [Hash] Selector(s) parsed by Krane::LabelSelector
# @param template_paths [Array<String>] An array of template paths
# @param filenames [Array<String>] An array of template paths
def initialize(context:, global_timeout: nil, selector: nil, filenames: [], logger: nil)
template_paths = filenames.map { |path| File.expand_path(path) }

Expand Down Expand Up @@ -105,7 +105,7 @@ def run!(verify_result: true, prune: true)
def deploy!(resources, verify_result, prune)
prune_whitelist = []
resource_deployer = ResourceDeployer.new(task_config: @task_config,
prune_whitelist: prune_whitelist, max_watch_seconds: @global_timeout,
prune_whitelist: prune_whitelist, global_timeout: @global_timeout,
selector: @selector, statsd_tags: statsd_tags)
resource_deployer.deploy!(resources, verify_result, prune)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/krane/resource_deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class ResourceDeployer
delegate :logger, to: :@task_config
attr_reader :statsd_tags

def initialize(task_config:, prune_whitelist:, max_watch_seconds:, current_sha: nil, selector:, statsd_tags:)
def initialize(task_config:, prune_whitelist:, global_timeout:, current_sha: nil, selector:, statsd_tags:)
@task_config = task_config
@prune_whitelist = prune_whitelist
@max_watch_seconds = max_watch_seconds
@global_timeout = global_timeout
@current_sha = current_sha
@selector = selector
@statsd_tags = statsd_tags
Expand Down Expand Up @@ -119,7 +119,7 @@ def deploy_resources(resources, prune: false, verify:, record_summary: true)

if verify
watcher = Krane::ResourceWatcher.new(resources: resources, deploy_started_at: deploy_started_at,
timeout: @max_watch_seconds, task_config: @task_config, sha: @current_sha)
timeout: @global_timeout, task_config: @task_config, sha: @current_sha)
watcher.run(record_summary: record_summary)
end
end
Expand Down
12 changes: 6 additions & 6 deletions test/exe/deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def test_deploy_with_default_options
end

def test_deploy_parses_global_timeout
set_krane_deploy_expectations(new_args: { max_watch_seconds: 10 })
set_krane_deploy_expectations(new_args: { global_timeout: 10 })
krane_deploy!(flags: '--global-timeout 10s')
set_krane_deploy_expectations(new_args: { max_watch_seconds: 60**2 })
set_krane_deploy_expectations(new_args: { global_timeout: 60**2 })
krane_deploy!(flags: '--global-timeout 1h')
end

Expand Down Expand Up @@ -63,9 +63,9 @@ def test_deploy_passes_protected_namespaces
end

def test_deploy_passes_filename
set_krane_deploy_expectations(new_args: { template_paths: ['/my/file/path'] })
set_krane_deploy_expectations(new_args: { filenames: ['/my/file/path'] })
krane_deploy!(flags: '-f /my/file/path')
set_krane_deploy_expectations(new_args: { template_paths: ['/my/other/file/path'] })
set_krane_deploy_expectations(new_args: { filenames: ['/my/other/file/path'] })
krane_deploy!(flags: '--filenames /my/other/file/path')
end

Expand Down Expand Up @@ -114,10 +114,10 @@ def default_options(new_args = {}, run_args = {})
namespace: deploy_task_config.namespace,
context: deploy_task_config.context,
current_sha: nil,
template_paths: ['/tmp'],
filenames: ['/tmp'],
bindings: {},
logger: logger,
max_watch_seconds: 300,
global_timeout: 300,
selector: nil,
protected_namespaces: ["default", "kube-system", "kube-public"],
}.merge(new_args),
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/fixture_deploy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ def deploy_raw_fixtures(set, wait: true, bindings: {}, subset: nil, render_erb:
end

def deploy_dirs_without_profiling(dirs, wait: true, allow_protected_ns: false, prune: true, bindings: {},
sha: "k#{SecureRandom.hex(6)}", kubectl_instance: nil, max_watch_seconds: nil, selector: nil,
sha: "k#{SecureRandom.hex(6)}", kubectl_instance: nil, global_timeout: nil, selector: nil,
protected_namespaces: nil, render_erb: false, allow_globals: true)
kubectl_instance ||= build_kubectl

deploy = KubernetesDeploy::DeployTask.new(
namespace: @namespace,
current_sha: sha,
context: KubeclientHelper::TEST_CONTEXT,
template_paths: dirs,
filenames: dirs,
logger: logger,
kubectl_instance: kubectl_instance,
bindings: bindings,
max_watch_seconds: max_watch_seconds,
global_timeout: global_timeout,
selector: selector,
protected_namespaces: protected_namespaces,
render_erb: render_erb,
Expand Down
2 changes: 1 addition & 1 deletion test/integration-serial/serial_task_run_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_timedout_statsd_metric_emitted
task_runner = build_task_runner(global_timeout: 0)

metrics = capture_statsd_calls(client: Krane::StatsD.client) do
result = task_runner.run(run_params.merge(args: ["sleep 5"]))
result = task_runner.run(run_params.merge(arguments: ["sleep 5"]))
assert_task_run_failure(result, :timed_out)
end

Expand Down
8 changes: 4 additions & 4 deletions test/integration/krane_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ def test_resource_watcher_reports_failed_after_timeout
result = deploy_fixtures(
"invalid",
subset: ["bad_probe.yml", "cannot_run.yml", "missing_volumes.yml", "config_map.yml"],
max_watch_seconds: 20
global_timeout: 20
) do |f|
bad_probe = f["bad_probe.yml"]["Deployment"].first
bad_probe["spec"]["progressDeadlineSeconds"] = 5
Expand All @@ -1336,7 +1336,7 @@ def test_resource_watcher_reports_failed_after_timeout
end

def test_resource_watcher_raises_after_timeout_seconds
result = deploy_fixtures("long-running", subset: ['undying-deployment.yml.erb'], max_watch_seconds: 5,
result = deploy_fixtures("long-running", subset: ['undying-deployment.yml.erb'], global_timeout: 5,
render_erb: true) do |fixtures|
deployment = fixtures['undying-deployment.yml.erb']['Deployment'].first
deployment['spec']['progressDeadlineSeconds'] = 100
Expand Down Expand Up @@ -1710,9 +1710,9 @@ def test_deploy_resource_using_generate_name_succeeds

private

def build_deploy_runner(context: KubeclientHelper::TEST_CONTEXT, ns: @namespace, max_watch_seconds: nil)
def build_deploy_runner(context: KubeclientHelper::TEST_CONTEXT, ns: @namespace, global_timeout: nil)
Krane::DeployTask.new(context: context, namespace: ns, logger: logger,
max_watch_seconds: max_watch_seconds, template_paths: ['./test/fixtures/hello-cloud'], current_sha: '123')
global_timeout: global_timeout, filenames: ['./test/fixtures/hello-cloud'], current_sha: '123')
end

def run_params
Expand Down
2 changes: 1 addition & 1 deletion test/unit/krane/deploy_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_initializer_without_valid_file
context: KubeclientHelper::TEST_CONTEXT,
logger: logger,
current_sha: "",
template_paths: ["unknown"],
filenames: ["unknown"],
).run
assert_logs_match("Configuration invalid")
assert_logs_match(/File (\S+) does not exist/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_hpa_is_whitelisted_for_pruning
.with("get", "CustomResourceDefinition", output: "json", attempts: 5, use_namespace: false)
.returns(['{ "items": [] }', "", SystemExit.new(0)])
task = Krane::DeployTask.new(namespace: 'test', context: KubeclientHelper::TEST_CONTEXT,
current_sha: 'foo', template_paths: [''], logger: logger)
current_sha: 'foo', filenames: [''], logger: logger)
assert(task.prune_whitelist.one? { |whitelisted_type| whitelisted_type.include?("HorizontalPodAutoscaler") })
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/krane/resource_deployer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def resource_deployer(kubectl_times: 2, prune_whitelist: [])
end
@deployer = Krane::ResourceDeployer.new(current_sha: 'test-sha',
statsd_tags: [], task_config: task_config, prune_whitelist: prune_whitelist,
max_watch_seconds: 1, selector: nil)
global_timeout: 1, selector: nil)
end

def build_mock_resource(final_status: "success", hits_to_complete: 0, name: "web-pod")
Expand Down

0 comments on commit f57a0e6

Please sign in to comment.