-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global command with a ResourceDeployer class
Use resource_deployer for normal deploys Add a common module Add tests
- Loading branch information
Showing
29 changed files
with
938 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module Krane | ||
module CLI | ||
class GlobalDeployCommand | ||
DEFAULT_DEPLOY_TIMEOUT = '300s' | ||
OPTIONS = { | ||
"filenames" => { type: :string, banner: '/tmp/my-resource.yml', aliases: :f, required: true, | ||
desc: "Path to file or directory 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.