Class: Kdep::Commands::Status

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Status.



15
16
17
18
19
20
# File 'lib/kdep/commands/status.rb', line 15

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



7
8
9
10
11
12
13
# File 'lib/kdep/commands/status.rb', line 7

def self.option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: kdep status [deploy]"
    opts.separator ""
    opts.separator "Shows pod status, image versions, and resource usage."
  end
end

Instance Method Details

#executeObject



22
23
24
25
26
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
# File 'lib/kdep/commands/status.rb', line 22

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

  # Get pods
  namespace = config["namespace"]
  app_name = config["name"]
  data = Kdep::Kubectl.run_json("get", "pods", "-n", namespace, "-l", "app=#{app_name}")
  pods = data["items"]

  if pods.nil? || pods.empty?
    @ui.info("No pods found for #{app_name} in #{namespace}")
    return
  end

  # Try to get pod metrics
  metrics = fetch_pod_metrics(namespace, app_name)

  # Build and display table
  display_pod_table(pods, metrics)

  # Show replica summary
  running = pods.count { |p| p["status"]["phase"] == "Running" }
  total = pods.length
  @ui.info("Replicas: #{running}/#{total} ready")

  # Cluster health check
  health = Kdep::ClusterHealth.new
  health.report(@ui)
end