Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global deploy 2 #602

Merged
merged 9 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/krane.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
require 'krane/render_task'
require 'krane/restart_task'
require 'krane/runner_task'
require 'krane/global_deploy_task'
44 changes: 44 additions & 0 deletions lib/krane/cli/global_deploy_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

module Krane
module CLI
class GlobalDeployCommand
DEFAULT_DEPLOY_TIMEOUT = '300s'
OPTIONS = {
"filenames" => { type: :array, banner: 'config/deploy/production config/deploy/my-extra-resource.yml',
aliases: :f, required: true,
desc: "Directories and files that contains the configuration to apply" },
"global-timeout" => { type: :string, banner: "duration", default: DEFAULT_DEPLOY_TIMEOUT,
desc: "Max duration to monitor workloads correctly deployed" },
"verify-result" => { type: :boolean, default: true,
desc: "Verify workloads correctly deployed" },
"selector" => { type: :string, banner: "'label=value'", required: true,
desc: "Select workloads owned by selector(s)" },
}

def self.from_options(context, options)
require 'krane/global_deploy_task'
require 'krane/options_helper'
require 'krane/label_selector'
require 'krane/duration_parser'

selector = ::Krane::LabelSelector.parse(options[:selector])

::Krane::OptionsHelper.with_processed_template_paths(options[:filenames],
require_explicit_path: true) do |paths|
deploy = ::Krane::GlobalDeployTask.new(
context: context,
filenames: paths,
global_timeout: ::Krane::DurationParser.new(options["global-timeout"]).parse!.to_i,
selector: selector,
)

deploy.run!(
verify_result: options["verify-result"],
prune: false,
)
end
end
end
end
end
9 changes: 9 additions & 0 deletions lib/krane/cli/krane.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'krane/cli/run_command'
require 'krane/cli/render_command'
require 'krane/cli/deploy_command'
require 'krane/cli/global_deploy_command'

module Krane
module CLI
Expand Down Expand Up @@ -58,6 +59,14 @@ def deploy(namespace, context)
end
end

desc("global-deploy CONTEXT", "Ship non-namespaced 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
6 changes: 4 additions & 2 deletions lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def global_resource_kinds
private

def fetch_globals
raw, _, st = kubectl.run("api-resources", "--namespaced=false", output: "wide", attempts: 5)
raw, _, st = kubectl.run("api-resources", "--namespaced=false", output: "wide", attempts: 5,
use_namespace: false)
RyanBrushett marked this conversation as resolved.
Show resolved Hide resolved
if st.success?
rows = raw.split("\n")
header = rows[0]
Expand All @@ -42,7 +43,8 @@ def fetch_globals
end

def fetch_crds
raw_json, _, st = kubectl.run("get", "CustomResourceDefinition", output: "json", attempts: 5)
raw_json, _, st = kubectl.run("get", "CustomResourceDefinition", output: "json", attempts: 5,
use_namespace: false)
if st.success?
JSON.parse(raw_json)["items"]
else
Expand Down
29 changes: 29 additions & 0 deletions lib/krane/concerns/template_reporting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Krane
module TemplateReporting
def record_invalid_template(logger:, err:, filename:, content: nil)
debug_msg = ColorizedString.new("Invalid template: #{filename}\n").red
debug_msg += "> Error message:\n#{Krane::FormattedLogger.indent_four(err)}"
if content
debug_msg += if content =~ /kind:\s*Secret/
"\n> Template content: Suppressed because it may contain a Secret"
else
"\n> Template content:\n#{Krane::FormattedLogger.indent_four(content)}"
end
end
logger.summary.add_paragraph(debug_msg)
end

def record_warnings(logger:, warning:, filename:)
warn_msg = "Template warning: #{filename}\n"
warn_msg += "> Warning message:\n#{Krane::FormattedLogger.indent_four(warning)}"
logger.summary.add_paragraph(ColorizedString.new(warn_msg).yellow)
end

def add_para_from_list(logger:, action:, enum:)
logger.summary.add_action(action)
logger.summary.add_paragraph(enum.map { |e| "- #{e}" }.join("\n"))
end
end
end
Loading