Skip to content

Commit

Permalink
Merge pull request #423 from powerhome/invalid-context-error
Browse files Browse the repository at this point in the history
Invalid context when running task prints error
  • Loading branch information
dturn committed Feb 25, 2019
2 parents 6a0dd66 + eaa5709 commit d28b284
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/kubernetes-deploy/runner_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def validate_configuration(task_template, args)
errors << "Namespace was not found"
rescue Kubeclient::HttpError
errors << "Could not connect to kubernetes cluster"
rescue KubernetesDeploy::KubeclientBuilder::ContextMissingError
errors << "Could not connect to kubernetes cluster - context invalid"
end

unless errors.empty?
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/task_runner_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def deploy_task_template(subset = ["template-runner.yml", "configmap-data.yml"])
reset_logger
end

def build_task_runner(ns: @namespace, max_watch_seconds: nil)
KubernetesDeploy::RunnerTask.new(context: KubeclientHelper::TEST_CONTEXT, namespace: ns, logger: logger,
def build_task_runner(context: KubeclientHelper::TEST_CONTEXT, ns: @namespace, max_watch_seconds: nil)
KubernetesDeploy::RunnerTask.new(context: context, namespace: ns, logger: logger,
max_watch_seconds: max_watch_seconds)
end

Expand Down
13 changes: 13 additions & 0 deletions test/integration/runner_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ def test_run_bang_raises_exceptions_as_well_as_printing_failure
assert_equal(1, pods.length, "Expected 1 pod to exist, found #{pods.length}")
end

def test_run_fails_if_context_is_invalid
task_runner = build_task_runner(context: "missing")
assert_task_run_failure(task_runner.run(run_params))

assert_logs_match_all([
"Initializing task",
"Validating configuration",
"Result: FAILURE",
"Configuration invalid",
"- Could not connect to kubernetes cluster - context invalid",
], in_order: true)
end

def test_run_fails_if_namespace_is_missing
task_runner = build_task_runner(ns: "missing")
assert_task_run_failure(task_runner.run(run_params))
Expand Down

0 comments on commit d28b284

Please sign in to comment.