Skip to content

Commit

Permalink
Still use KubernetesDeploy public api for exes, errors and integratio…
Browse files Browse the repository at this point in the history
…n tests
  • Loading branch information
Douglas Soares de Andrade committed Oct 26, 2019
1 parent 6664b95 commit c80ae60
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 19 deletions.
10 changes: 5 additions & 5 deletions exe/kubernetes-deploy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'krane/deprecated_deploy_task'
require 'kubernetes-deploy/deploy_task'
require 'krane/options_helper'
require 'krane/bindings_parser'
require 'krane/label_selector'
Expand Down Expand Up @@ -69,7 +69,7 @@ template_paths = [template_dir] if template_paths.empty? && template_dir

begin
Krane::OptionsHelper.with_processed_template_paths(template_paths) do |paths|
runner = Krane::DeprecatedDeployTask.new(
runner = KubernetesDeploy::DeployTask.new(
namespace: namespace,
context: context,
current_sha: ENV["REVISION"],
Expand All @@ -87,11 +87,11 @@ begin
prune: prune
)
end
rescue Krane::DeploymentTimeoutError
rescue KubernetesDeploy::DeploymentTimeoutError
exit(70)
rescue Krane::FatalDeploymentError
rescue KubernetesDeploy::FatalDeploymentError
exit(1)
rescue Krane::OptionsHelper::OptionsError => e
rescue KubernetesDeploy::OptionsHelper::OptionsError => e
logger.error(e.message)
exit(1)
end
4 changes: 2 additions & 2 deletions exe/kubernetes-render
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'krane/render_task'
require 'kubernetes-deploy/render_task'
require 'krane/options_helper'
require 'krane/bindings_parser'

Expand All @@ -26,7 +26,7 @@ logger = Krane::FormattedLogger.build(verbose_prefix: false)

begin
Krane::OptionsHelper.with_processed_template_paths(template_dir) do |dir|
runner = Krane::RenderTask.new(
runner = KubernetesDeploy::RenderTask.new(
current_sha: ENV["REVISION"],
template_dir: dir.first,
bindings: bindings,
Expand Down
8 changes: 4 additions & 4 deletions exe/kubernetes-restart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require 'optparse'

require 'krane/restart_task'
require 'kubernetes-deploy/restart_task'
require 'krane/options_helper'
require 'krane/label_selector'

Expand All @@ -22,12 +22,12 @@ end
namespace = ARGV[0]
context = ARGV[1]

restart = Krane::RestartTask.new(namespace: namespace, context: context,
restart = KubernetesDeploy::RestartTask.new(namespace: namespace, context: context,
max_watch_seconds: max_watch_seconds)
begin
restart.run!(raw_deployments, selector: selector)
rescue Krane::DeploymentTimeoutError
rescue KubernetesDeploy::DeploymentTimeoutError
exit(70)
rescue Krane::FatalDeploymentError
rescue KubernetesDeploy::FatalDeploymentError
exit(1)
end
4 changes: 2 additions & 2 deletions exe/kubernetes-run
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'krane/runner_task'
require 'kubernetes-deploy/runner_task'
require 'krane/options_helper'
require 'optparse'

Expand All @@ -26,7 +26,7 @@ end
namespace = ARGV[0]
context = ARGV[1]

runner = Krane::RunnerTask.new(
runner = KubernetesDeploy::RunnerTask.new(
namespace: namespace,
context: context,
max_watch_seconds: max_watch_seconds
Expand Down
2 changes: 2 additions & 0 deletions lib/krane/errors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true
require 'kubernetes-deploy/errors'

module Krane
class FatalDeploymentError < StandardError; end
class FatalKubeAPIError < FatalDeploymentError; end
Expand Down
8 changes: 8 additions & 0 deletions lib/kubernetes-deploy/deploy_task.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# frozen_string_literal: true
require 'krane/deprecated_deploy_task'
require_relative 'rescue_krane_exceptions'

module KubernetesDeploy
class DeployTask < ::Krane::DeprecatedDeployTask
include RescueKraneExceptions

def run(*args)
super(*args)
rescue KubernetesDeploy::FatalDeploymentError
false
end
end
end
8 changes: 8 additions & 0 deletions lib/kubernetes-deploy/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module KubernetesDeploy
class FatalDeploymentError < StandardError; end
class FatalKubeAPIError < FatalDeploymentError; end
class KubectlError < StandardError; end
class DeploymentTimeoutError < FatalDeploymentError; end
end
8 changes: 8 additions & 0 deletions lib/kubernetes-deploy/render_task.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# frozen_string_literal: true
require 'krane/render_task'
require_relative 'rescue_krane_exceptions'

module KubernetesDeploy
class RenderTask < ::Krane::RenderTask
include RescueKraneExceptions

def run(*args)
super(*args)
rescue KubernetesDeploy::FatalDeploymentError
false
end
end
end
16 changes: 16 additions & 0 deletions lib/kubernetes-deploy/rescue_krane_exceptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true
require_relative 'errors'

module RescueKraneExceptions
def run!(*args)
super(*args)
rescue Krane::DeploymentTimeoutError => e
raise KubernetesDeploy::DeploymentTimeoutError, e.message
rescue Krane::FatalDeploymentError => e
raise KubernetesDeploy::FatalDeploymentError, e.message
rescue Krane::FatalKubeAPIError => e
raise KubernetesDeploy::FatalKubeAPIError, e.message
rescue Krane::KubectlError => e
raise KubernetesDeploy::KubectlError, e.message
end
end
8 changes: 8 additions & 0 deletions lib/kubernetes-deploy/restart_task.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# frozen_string_literal: true
require 'krane/restart_task'
require_relative 'rescue_krane_exceptions'

module KubernetesDeploy
class RestartTask < ::Krane::RestartTask
include RescueKraneExceptions

def run(*args)
super(*args)
rescue KubernetesDeploy::FatalDeploymentError
false
end
end
end
8 changes: 8 additions & 0 deletions lib/kubernetes-deploy/runner_task.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# frozen_string_literal: true
require 'krane/runner_task'
require_relative 'rescue_krane_exceptions'

module KubernetesDeploy
class RunnerTask < ::Krane::RunnerTask
include RescueKraneExceptions

def run(*args)
super(*args)
rescue KubernetesDeploy::DeploymentTimeoutError, KubernetesDeploy::FatalDeploymentError
false
end
end
end
8 changes: 4 additions & 4 deletions test/helpers/fixture_deploy_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true
require 'securerandom'
require 'krane/deprecated_deploy_task'
require 'kubernetes-deploy/deploy_task'

module FixtureDeployHelper
EJSON_FILENAME = Krane::EjsonSecretProvisioner::EJSON_SECRETS_FILE

# Deploys the specified set of fixtures via Krane::DeployTask.
# Deploys the specified set of fixtures via KubernetesDeploy::DeployTask.
#
# Optionally takes an array of filenames belonging to the fixture, and deploys that subset only.
# Example:
Expand Down Expand Up @@ -67,7 +67,7 @@ def deploy_dirs_without_profiling(dirs, wait: true, allow_protected_ns: false, p
protected_namespaces: nil, render_erb: false, allow_globals: true)
kubectl_instance ||= build_kubectl

deploy = Krane::DeprecatedDeployTask.new(
deploy = KubernetesDeploy::DeployTask.new(
namespace: @namespace,
current_sha: sha,
context: KubeclientHelper::TEST_CONTEXT,
Expand All @@ -88,7 +88,7 @@ def deploy_dirs_without_profiling(dirs, wait: true, allow_protected_ns: false, p
)
end

# Deploys all fixtures in the given directories via Krane::DeployTask
# Deploys all fixtures in the given directories via KubernetesDeploy::DeployTask
# Exposed for direct use only when deploy_fixtures cannot be used because the template cannot be loaded pre-deploy,
# for example because it contains an intentional syntax error
def deploy_dirs(*dirs, **args)
Expand Down
4 changes: 2 additions & 2 deletions test/integration-serial/serial_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def test_cr_failure_with_arbitrary_rollout_conditions
def test_deploying_crs_with_invalid_crd_conditions_fails
# Since CRDs are not always deployed along with their CRs and krane is not the only way CRDs are
# deployed, we need to model the case where poorly configured rollout_conditions are present before deploying a CR
Krane::DeprecatedDeployTask.any_instance.expects(:validate_resources).returns(:true)
KubernetesDeploy::DeployTask.any_instance.expects(:validate_resources).returns(:true)
crd_result = deploy_fixtures("crd", subset: ["with_custom_conditions.yml"]) do |resource|
crd = resource["with_custom_conditions.yml"]["CustomResourceDefinition"].first
crd["metadata"]["annotations"].merge!(
Expand All @@ -464,7 +464,7 @@ def test_deploying_crs_with_invalid_crd_conditions_fails
end

assert_deploy_success(crd_result)
Krane::DeprecatedDeployTask.any_instance.unstub(:validate_resources)
KubernetesDeploy::DeployTask.any_instance.unstub(:validate_resources)

cr_result = deploy_fixtures("crd", subset: ["with_custom_conditions_cr.yml", "with_custom_conditions_cr2.yml"])
assert_deploy_failure(cr_result)
Expand Down

0 comments on commit c80ae60

Please sign in to comment.