Class: Kdep::Commands::Secrets

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Secrets.



27
28
29
30
31
32
# File 'lib/kdep/commands/secrets.rb', line 27

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kdep/commands/secrets.rb', line 8

def self.option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: kdep secrets <list|create|check> [deploy]"
    opts.separator ""
    opts.separator "Manage image pull secrets in the deploy namespace."
    opts.separator ""
    opts.separator "Sub-commands:"
    opts.separator "  list     List image pull secrets"
    opts.separator "  create   Create a docker-registry secret"
    opts.separator "  check    Decode and inspect an existing secret"
    opts.separator ""
    opts.separator "Options:"
    opts.on("--server=URL", "Docker registry server URL")
    opts.on("--username=NAME", "Registry username")
    opts.on("--password=PASS", "Registry password")
    opts.on("--name=SECRET_NAME", "Secret name (default: registry-credentials)")
  end
end

Instance Method Details

#executeObject



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
78
79
80
81
82
83
# File 'lib/kdep/commands/secrets.rb', line 34

def execute
  sub = @args.shift            # Sub-command first (list, create, check)
  deploy_name = @args.shift    # Deploy name second (optional)

  # If no sub-command given, show usage
  unless sub
    show_usage
    return
  end

  # Only proceed with deploy resolution for known sub-commands
  unless %w[list create check].include?(sub)
    show_usage
    return
  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.message)
    exit 1
  end

  @namespace = @config["namespace"]

  # Dispatch sub-command
  case sub
  when "list"   then list_secrets
  when "create" then create_secret
  when "check"  then check_secrets
  end
end