Class: Kdep::Commands::Scale
- Inherits:
-
Object
- Object
- Kdep::Commands::Scale
- Defined in:
- lib/kdep/commands/scale.rb
Constant Summary collapse
- NON_SCALABLE_PRESETS =
%w[job cronjob].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(global_options:, command_options:, args:) ⇒ Scale
constructor
A new instance of Scale.
Constructor Details
#initialize(global_options:, command_options:, args:) ⇒ Scale
Returns a new instance of Scale.
20 21 22 23 24 25 |
# File 'lib/kdep/commands/scale.rb', line 20 def initialize(global_options:, command_options:, args:) @global_options = @command_options = @args = args @ui = Kdep::UI.new(color: false) end |
Class Method Details
.option_parser ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/kdep/commands/scale.rb', line 8 def self.option_parser OptionParser.new do |opts| opts. = "Usage: kdep scale [deploy] N [--type TYPE]" opts.separator "" opts.separator "Scales a Deployment or StatefulSet to N replicas." opts.separator "" opts.on("--type TYPE", "Resource type: deployment, statefulset (overrides preset)") do |_| # parsed via into: hash end end end |
Instance Method Details
#execute ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/kdep/commands/scale.rb', line 27 def execute if @args.length == 1 && @args[0] && @args[0].match?(/\A\d+\z/) deploy_name = nil @replica_count = @args[0].to_i else deploy_name = @args[0] end # Discover kdep/ directory discovery = Kdep::Discovery.new kdep_dir = discovery.find_kdep_dir unless kdep_dir @ui.error("No kdep/ directory found") exit 1 end # Resolve deploy directory deploy_dir = resolve_deploy_dir(kdep_dir, deploy_name, discovery) unless deploy_dir exit 1 end # Load config config = Kdep::Config.new(deploy_dir, nil).load # Validate context before any cluster operation begin Kdep::ContextGuard.new(config["context"]).validate! rescue Kdep::Kubectl::Error => e @ui.error(e.) exit 1 end namespace = config["namespace"] app_name = config["name"] preset = config["preset"] # Parse and validate replica count replicas = parse_replicas unless replicas @ui.error("Usage: kdep scale [deploy] N -- replica count required") exit 1 end # Determine resource type resource_type = determine_resource_type(preset) # Execute scale Kdep::Kubectl.run("scale", "#{resource_type}/#{app_name}", "--replicas=#{replicas}", "-n", namespace) @ui.info("Scaled #{resource_type}/#{app_name} to #{replicas} replicas in #{namespace}") end |