Skip to content

Commit

Permalink
Rename --filename back to --template for RunnerTask
Browse files Browse the repository at this point in the history
  • Loading branch information
dirceu committed Nov 18, 2019
1 parent 8994eb1 commit 564c3cc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lib/krane/cli/run_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RunCommand
},
"verify-result" => { type: :boolean, desc: "Wait for completion and verify pod success", default: true },
"command" => { type: :array, desc: "Override the default command in the container image" },
"filename" => {
"template" => {
type: :string,
desc: "The template file you'll be rendering",
required: true,
Expand All @@ -43,7 +43,7 @@ def self.from_options(namespace, context, options)

runner.run!(
verify_result: options['verify-result'],
filename: options['filename'],
template: options['template'],
command: options['command'],
arguments: options['arguments']&.split(" "),
env_vars: options['env-vars'].split(','),
Expand Down
8 changes: 4 additions & 4 deletions lib/krane/runner_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ def run(*args)

# Runs the task, raising exceptions in case of issues
#
# @param filename [String] The filename of the template you'll be rendering (*required*)
# @param template [String] The filename of the template you'll be rendering (*required*)
# @param command [Array<String>] Override the default command in the container image
# @param arguments [Array<String>] Override the default arguments for the command
# @param env_vars [Array<String>] List of env vars
# @param verify_result [Boolean] Wait for completion and verify pod success
#
# @return [nil]
def run!(filename:, command:, arguments:, env_vars: [], verify_result: true)
def run!(template:, command:, arguments:, env_vars: [], verify_result: true)
start = Time.now.utc
@logger.reset

@logger.phase_heading("Initializing task")

@logger.info("Validating configuration")
verify_config!(filename)
verify_config!(template)
@logger.info("Using namespace '#{@namespace}' in context '#{@context}'")

pod = build_pod(filename, command, arguments, env_vars, verify_result)
pod = build_pod(template, command, arguments, env_vars, verify_result)
validate_pod(pod)

@logger.phase_heading("Running pod")
Expand Down
16 changes: 8 additions & 8 deletions test/exe/run_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def test_run_parses_arguments
krane_run!(flags: '--arguments hello')
end

def test_run_parses_filename
set_krane_run_expectations(run_args: { filename: 'some-name' })
krane_run!(flags: '--filename some-name')
def test_run_parses_template
set_krane_run_expectations(run_args: { template: 'some-name' })
krane_run!(flags: '--template some-name')
end

def test_run_parses_env_vars
Expand All @@ -45,21 +45,21 @@ def test_run_parses_env_vars
end

def test_run_failure_with_not_enough_arguments_as_black_box
out, err, status = krane_black_box('run', '--filename some_template not_enough_arguments')
out, err, status = krane_black_box('run', '--template some_template not_enough_arguments')
assert_equal(1, status.exitstatus)
assert_empty(out)
assert_match("ERROR", err)
end

def test_run_failure_with_too_many_args_as_black_box
out, err, status = krane_black_box('run', '--filename some_template ns ctx some_extra_arg')
out, err, status = krane_black_box('run', '--template some_template ns ctx some_extra_arg')
assert_equal(1, status.exitstatus)
assert_empty(out)
assert_match("ERROR", err)
end

def test_run_failure_with_bad_timeout_as_black_box
out, err, status = krane_black_box('run', '--filename some_template ns ctx --global-timeout=mittens')
out, err, status = krane_black_box('run', '--template some_template ns ctx --global-timeout=mittens')
assert_equal(1, status.exitstatus)
assert_empty(out)
assert_match("Error parsing duration", err)
Expand All @@ -75,7 +75,7 @@ def set_krane_run_expectations(new_args: {}, run_args: {})
end

def krane_run!(flags: '')
flags += " --filename #{TASK_TEMPLATE}" unless flags.include?('--filename')
flags += " --template #{TASK_TEMPLATE}" unless flags.include?('--template')
krane = Krane::CLI::Krane.new(
[run_task_config.namespace, run_task_config.context],
flags.split
Expand All @@ -96,7 +96,7 @@ def default_options(new_args = {}, run_args = {})
}.merge(new_args),
run_args: {
verify_result: true,
filename: TASK_TEMPLATE,
template: TASK_TEMPLATE,
command: nil,
arguments: nil,
env_vars: [],
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/task_runner_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def build_task_runner(context: KubeclientHelper::TEST_CONTEXT, ns: @namespace, g

def run_params(log_lines: 5, log_interval: 0.1, verify_result: true)
{
filename: 'hello-cloud-template-runner',
template: 'hello-cloud-template-runner',
command: ['/bin/sh', '-c'],
arguments: [
"i=1; " \
Expand Down
2 changes: 1 addition & 1 deletion test/integration/krane_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_run_success_black_box
assert_deploy_success(deploy_fixtures("hello-cloud", subset: ["template-runner.yml", "configmap-data.yml"]))
template = "hello-cloud-template-runner"
out, err, status = krane_black_box("run",
"#{@namespace} #{KubeclientHelper::TEST_CONTEXT} --filename #{template} --command ls --arguments '-a /'")
"#{@namespace} #{KubeclientHelper::TEST_CONTEXT} --template #{template} --command ls --arguments '-a /'")
assert_match("Success", err)
assert_empty(out)
assert_predicate(status, :success?)
Expand Down
6 changes: 3 additions & 3 deletions test/integration/runner_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_run_fails_if_namespace_is_missing

def test_run_fails_if_template_is_blank
task_runner = build_task_runner
result = task_runner.run(filename: '',
result = task_runner.run(template: '',
command: ['/bin/sh', '-c'],
arguments: nil,
env_vars: ["MY_CUSTOM_VARIABLE=MITTENS"])
Expand All @@ -224,7 +224,7 @@ def test_run_fails_if_template_is_blank
def test_run_bang_fails_if_template_is_invalid
task_runner = build_task_runner
assert_raises(Krane::TaskConfigurationError) do
task_runner.run!(filename: '',
task_runner.run!(template: '',
command: ['/bin/sh', '-c'],
arguments: nil,
env_vars: ["MY_CUSTOM_VARIABLE=MITTENS"])
Expand Down Expand Up @@ -271,7 +271,7 @@ def test_run_adds_env_vars_provided_to_the_task_container

task_runner = build_task_runner
result = task_runner.run(
filename: 'hello-cloud-template-runner',
template: 'hello-cloud-template-runner',
command: ['/bin/sh', '-c'],
arguments: ['echo "The value is: $MY_CUSTOM_VARIABLE"'],
env_vars: ["MY_CUSTOM_VARIABLE=MITTENS"]
Expand Down

0 comments on commit 564c3cc

Please sign in to comment.