Class: Kdep::Commands::Restart

Inherits:
Object
  • Object
show all
Defined in:
lib/kdep/commands/restart.rb

Constant Summary collapse

RESTARTABLE_PRESETS =
%w[web worker].freeze
NON_RESTARTABLE_PRESETS =
%w[job cronjob].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(global_options:, command_options:, args:) ⇒ Restart

Returns a new instance of Restart.



21
22
23
24
25
26
# File 'lib/kdep/commands/restart.rb', line 21

def initialize(global_options:, command_options:, args:)
  @global_options = global_options
  @command_options = command_options
  @args = args
  @ui = Kdep::UI.new(color: false)
end

Class Method Details

.option_parserObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kdep/commands/restart.rb', line 9

def self.option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: kdep restart [deploy] [--type TYPE]"
    opts.separator ""
    opts.separator "Triggers a rolling restart of a Deployment or StatefulSet."
    opts.separator ""
    opts.on("--type TYPE", "Resource type: deployment, statefulset (overrides preset)") do |_|
      # parsed via into: hash
    end
  end
end

Instance Method Details

#executeObject



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
# File 'lib/kdep/commands/restart.rb', line 28

def execute
  deploy_name = @args[0]

  # 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.message)
    exit 1
  end

  namespace = config["namespace"]
  app_name = config["name"]
  preset = config["preset"]

  # Determine resource type
  resource_type = determine_resource_type(preset)

  # Execute rollout restart
  Kdep::Kubectl.run("rollout", "restart", "#{resource_type}/#{app_name}", "-n", namespace)
  @ui.info("Restarted #{resource_type}/#{app_name} in #{namespace}")
end