From eaa570921109d060a03603bd985aa4773ca42812 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Sun, 24 Feb 2019 17:26:36 -0300 Subject: [PATCH] Invalid context when running task prints error Fixes #417 --- lib/kubernetes-deploy/runner_task.rb | 2 ++ test/helpers/task_runner_test_helper.rb | 4 ++-- test/integration/runner_task_test.rb | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/kubernetes-deploy/runner_task.rb b/lib/kubernetes-deploy/runner_task.rb index a6eb3fa27..886413693 100644 --- a/lib/kubernetes-deploy/runner_task.rb +++ b/lib/kubernetes-deploy/runner_task.rb @@ -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? diff --git a/test/helpers/task_runner_test_helper.rb b/test/helpers/task_runner_test_helper.rb index 4321aebf4..fd39688f9 100644 --- a/test/helpers/task_runner_test_helper.rb +++ b/test/helpers/task_runner_test_helper.rb @@ -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 diff --git a/test/integration/runner_task_test.rb b/test/integration/runner_task_test.rb index 0c6655b8a..ced52c5a7 100644 --- a/test/integration/runner_task_test.rb +++ b/test/integration/runner_task_test.rb @@ -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))