Skip to content

Commit

Permalink
Limit this PR to just disabling global deploys
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Sep 26, 2019
1 parent e394453 commit 3548995
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 109 deletions.
1 change: 1 addition & 0 deletions exe/kubernetes-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ begin
logger: logger,
max_watch_seconds: max_watch_seconds,
selector: selector,
allow_globals: true
)

runner.run!(
Expand Down
59 changes: 0 additions & 59 deletions lib/krane/cli/global_deploy_command.rb

This file was deleted.

8 changes: 0 additions & 8 deletions lib/krane/cli/krane.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ def deploy(namespace, context)
end
end

desc("global-deploy NAMESPACE CONTEXT", "Ship global resources to a cluster")
expand_options(GlobalDeployCommand::OPTIONS)
def global_deploy(context)
rescue_and_exit do
GlobalDeployCommand.from_options(context, options)
end
end

def self.exit_on_failure?
true
end
Expand Down
35 changes: 17 additions & 18 deletions lib/kubernetes-deploy/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def server_version

def initialize(namespace:, context:, current_sha:, logger: nil, kubectl_instance: nil, bindings: {},
max_watch_seconds: nil, selector: nil, template_paths: [], template_dir: nil, protected_namespaces: nil,
render_erb: true, only_globals: false)
render_erb: true, allow_globals: false)
template_dir = File.expand_path(template_dir) if template_dir
template_paths = (template_paths.map { |path| File.expand_path(path) } << template_dir).compact

Expand All @@ -128,7 +128,7 @@ def initialize(namespace:, context:, current_sha:, logger: nil, kubectl_instance
@selector = selector
@protected_namespaces = protected_namespaces || PROTECTED_NAMESPACES
@render_erb = render_erb
@only_globals = only_globals
@allow_globals = allow_globals
end

def run(*args)
Expand Down Expand Up @@ -275,27 +275,26 @@ def validate_resources(resources)
end
raise FatalDeploymentError, "Template validation failed"
end
validate_globals(resources)
end
measure_method(:validate_resources)

global, namespaced = resources.partition(&:global?)
if global.present? && !@only_globals
msgs = global.map do |resource|
"#{resource.name} (#{resource.class.kind}) in #{File.basename(resource.file_path)}"
end
warn_msg = msgs.join("\n")
@logger.summary.add_paragraph(ColorizedString.new("Global resources #{warn_msg}").yellow)
raise FatalDeploymentError, "Global resource found in namespaced deploy mode"
def validate_globals(resources)
return unless (global = resources.select(&:global?).presence)
global_names = global.map do |resource|
"#{resource.name} (#{resource.type}) in #{File.basename(resource.file_path)}"
end
global_names = FormattedLogger.indent_four(global_names.join("\n"))

if namespaced.present? && @only_globals
msgs = namespaced.map do |resource|
"#{resource.name} (#{resource.class.kind}) in #{File.basename(resource.file_path)}"
end
warn_msg = msgs.join("\n")
@logger.summary.add_paragraph(ColorizedString.new("Global resources #{warn_msg}").yellow)
raise FatalDeploymentError, "Namespaced resource found in global deploy mode"
if @allow_globals
msg = "The ability for this task to deploy global resources will be removed in the next version:"
msg += "\n#{global_names}"
@logger.summary.add_paragraph(ColorizedString.new(msg).yellow)
else
@logger.summary.add_paragraph(ColorizedString.new("Global resources:\n#{global_names}").yellow)
raise FatalDeploymentError, "Deploying global resource is not allowed from this command."
end
end
measure_method(:validate_resources)

def check_initial_status(resources)
cache = ResourceCache.new(@namespace, @context, @logger)
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/fixture_deploy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def deploy_raw_fixtures(set, wait: true, bindings: {}, subset: nil)

def deploy_dirs_without_profiling(dirs, wait: true, allow_protected_ns: false, prune: true, bindings: {},
sha: "k#{SecureRandom.hex(6)}", kubectl_instance: nil, max_watch_seconds: nil, selector: nil,
protected_namespaces: nil, render_erb: true, only_globals: false)
protected_namespaces: nil, render_erb: true, allow_globals: true)
kubectl_instance ||= build_kubectl

deploy = KubernetesDeploy::DeployTask.new(
Expand All @@ -77,7 +77,7 @@ def deploy_dirs_without_profiling(dirs, wait: true, allow_protected_ns: false, p
selector: selector,
protected_namespaces: protected_namespaces,
render_erb: render_erb,
only_globals: only_globals
allow_globals: allow_globals
)
deploy.run(
verify_result: wait,
Expand Down
4 changes: 0 additions & 4 deletions test/integration-serial/serial_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ def test_crd_pruning_deprecated
assert_deploy_success(deploy_fixtures("crd", subset: %w(mail.yml widgets_deprecated.yml)))
assert_logs_match_all([
"Phase 1: Initializing deploy",
"Detected non-namespaced resources which will never be pruned:",
" - CustomResourceDefinition/mail.stable.example.io",
"Phase 3: Deploying all resources",
"CustomResourceDefinition/mail.stable.example.io (timeout: 120s)",
%r{CustomResourceDefinition/mail.stable.example.io\s+Names accepted},
Expand All @@ -167,8 +165,6 @@ def test_crd_pruning
assert_deploy_success(deploy_fixtures("crd", subset: %w(mail.yml widgets.yml)))
assert_logs_match_all([
"Phase 1: Initializing deploy",
"Detected non-namespaced resources which will never be pruned:",
" - CustomResourceDefinition/mail.stable.example.io",
"Phase 3: Deploying all resources",
"CustomResourceDefinition/mail.stable.example.io (timeout: 120s)",
%r{CustomResourceDefinition/mail.stable.example.io\s+Names accepted},
Expand Down
27 changes: 9 additions & 18 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1593,31 +1593,22 @@ def test_fail_erb_templates_if_rendering_is_disabled
], in_order: true)
end

def test_deploy_only_globals
storage_class_name = 'testing-storage-class'
result = deploy_fixtures("globals", only_globals: true)
assert_deploy_success(result)
assert_logs_match_all([
'Successfully deployed 1 resources',
"StorageClass/#{storage_class_name}",
], in_order: true)
ensure
storage_v1_kubeclient.delete_storage_class(storage_class_name)
end

def test_deploy_only_globals_validation
def test_deploy_allow_globals_warns
result = deploy_fixtures("globals")
assert_deploy_failure(result)
assert_deploy_success(result)
assert_logs_match_all([
'Global resource found in namespaced deploy mode',
'The ability for this task to deploy global resources will be removed in the next version:',
' testing-storage-class (StorageClass) in ',
], in_order: true)
end

def test_deploy_globals_without_only_globals_validation
result = deploy_fixtures("hello-cloud", subset: ["unmanaged-pod-1.yml.erb"], only_globals: true)
def test_deploy_globals_without_allow_globals_fails
result = deploy_fixtures("globals", allow_globals: false)
assert_deploy_failure(result)
assert_logs_match_all([
'Namespaced resource found in global deploy mode',
'Deploying global resource is not allowed from this command',
'Global resources:',
' testing-storage-class (StorageClass) in ',
], in_order: true)
end

Expand Down

0 comments on commit 3548995

Please sign in to comment.