diff --git a/lib/kubernetes-deploy/restart_task.rb b/lib/kubernetes-deploy/restart_task.rb index 179dee81f..3dc4e50fc 100644 --- a/lib/kubernetes-deploy/restart_task.rb +++ b/lib/kubernetes-deploy/restart_task.rb @@ -112,12 +112,8 @@ def build_watchables(kubeclient_resources, started) def verify_namespace kubeclient.get_namespace(@namespace) @logger.info("Namespace #{@namespace} found in context #{@context}") - rescue Kubeclient::HttpError => error - if error.error_code == 404 - raise NamespaceNotFoundError.new(@namespace, @context) - else - raise - end + rescue Kubeclient::ResourceNotFoundError + raise NamespaceNotFoundError.new(@namespace, @context) end def patch_deployment_with_restart(record) @@ -133,7 +129,7 @@ def patch_kubeclient_deployments(deployments) begin patch_deployment_with_restart(record) @logger.info("Triggered `#{record.metadata.name}` restart") - rescue Kubeclient::ResourceNotFoundError, Kubeclient::HttpError => e + rescue Kubeclient::HttpError => e raise RestartAPIError.new(record.metadata.name, e.message) end end @@ -144,12 +140,8 @@ def fetch_deployments(list) record = nil begin record = v1beta1_kubeclient.get_deployment(name, @namespace) - rescue Kubeclient::HttpError => error - if error.error_code == 404 - raise FatalRestartError, "Deployment `#{name}` not found in namespace `#{@namespace}`" - else - raise - end + rescue Kubeclient::ResourceNotFoundError + raise FatalRestartError, "Deployment `#{name}` not found in namespace `#{@namespace}`" end record end diff --git a/lib/kubernetes-deploy/runner_task.rb b/lib/kubernetes-deploy/runner_task.rb index 4935a95cf..a6eb3fa27 100644 --- a/lib/kubernetes-deploy/runner_task.rb +++ b/lib/kubernetes-deploy/runner_task.rb @@ -122,9 +122,11 @@ def validate_configuration(task_template, args) begin kubeclient.get_namespace(@namespace) if @namespace.present? @logger.info("Using namespace '#{@namespace}' in context '#{@context}'") - rescue Kubeclient::HttpError => e - msg = e.error_code == 404 ? "Namespace was not found" : "Could not connect to kubernetes cluster" - errors << msg + + rescue Kubeclient::ResourceNotFoundError + errors << "Namespace was not found" + rescue Kubeclient::HttpError + errors << "Could not connect to kubernetes cluster" end unless errors.empty? @@ -140,16 +142,13 @@ def validate_configuration(task_template, args) def get_template(template_name) pod_template = kubeclient.get_pod_template(template_name, @namespace) - pod_template.template + rescue Kubeclient::ResourceNotFoundError + msg = "Pod template `#{template_name}` not found in namespace `#{@namespace}`, context `#{@context}`" + @logger.summary.add_paragraph(msg) + raise TaskTemplateMissingError, msg rescue Kubeclient::HttpError => error - if error.error_code == 404 - msg = "Pod template `#{template_name}` not found in namespace `#{@namespace}`, context `#{@context}`" - @logger.summary.add_paragraph(msg) - raise TaskTemplateMissingError, msg - else - raise FatalKubeAPIError, "Error retrieving pod template: #{error.class.name}: #{error.message}" - end + raise FatalKubeAPIError, "Error retrieving pod template: #{error.class.name}: #{error.message}" end def build_pod_definition(base_template) diff --git a/test/helpers/fixture_set.rb b/test/helpers/fixture_set.rb index 224935523..c27b19e8c 100644 --- a/test/helpers/fixture_set.rb +++ b/test/helpers/fixture_set.rb @@ -33,8 +33,7 @@ def refute_resource_exists(type, name, beta: false) if res.metadata.deletionTimestamp.blank? flunk("#{type} #{name} unexpectedly existed and is not being deleted.") end - rescue Kubeclient::HttpError => e - raise unless e.to_s.include?("not found") + rescue Kubeclient::ResourceNotFoundError end def assert_pod_status(pod_name, status, count = 1) diff --git a/test/helpers/test_provisioner.rb b/test/helpers/test_provisioner.rb index b1091c497..a38128695 100644 --- a/test/helpers/test_provisioner.rb +++ b/test/helpers/test_provisioner.rb @@ -28,8 +28,7 @@ def claim_namespace(test_name) def delete_namespace(namespace) kubeclient.delete_namespace(namespace) if namespace.present? - rescue Kubeclient::HttpError => e - raise unless e.to_s.include?("not found") + rescue Kubeclient::ResourceNotFoundError end private