Class: KTools::Tools::Spy

Inherits:
Object
  • Object
show all
Defined in:
lib/ktools/tools/spy.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Spy

Returns a new instance of Spy.



8
9
10
11
12
13
14
# File 'lib/ktools/tools/spy.rb', line 8

def initialize(args)
  @args = args
  @action = "#{args[0]} #{args[1]}"
  @subject = args[2]
  @env = args[3]
  @cfg = KTools::KDB.read
end

Class Method Details

.start(args) ⇒ Object



4
5
6
# File 'lib/ktools/tools/spy.rb', line 4

def self.start(args)
  self.new(args).start
end

Instance Method Details

#startObject



16
17
18
19
20
21
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ktools/tools/spy.rb', line 16

def start
  case @action
  when 'drop registry'
    puts "Deleting Docker Registry for #{@subject}..."
    puts ""

    registry_name = "#{@subject}-registry"

    Sh.ell("kubectl delete secret #{registry_name} -n foxbox")
  when 'create registry'
    puts "Creating Docker Registry for #{@subject}..."
    puts ""

    registry_name = "#{@subject}-registry"
    env_path = "#{@cfg["secrets"]}/#{@env}/#{@subject}"
    registry_file = "#{env_path}/create_registry.json"

    puts Sh.ellb!("kubectl create -f #{registry_file} -n foxbox")
  when 'drop config'
    puts "Deleting configMap for #{@subject}..."
    puts ""

    config_name = "#{@subject}-config-map"

    Sh.ell("kubectl delete configMap #{config_name} -n foxbox")
  when 'apply config'
    puts "Updating/Creating configMap for #{@subject}..."

    unless @env
      puts ""
      puts "Please, express the environment."
      puts "It can be 'production' or 'staging', like:"
      puts "$ kt spy apply config appslug staging"
      exit 1
    end

    env_path = "#{@cfg["secrets"]}/#{@env}/#{@subject}"
    config_map_file = "#{env_path}/config_map.yml"

    Sh.ell("kubectl apply -f #{config_map_file} -n foxbox")
  when 'drop ingress'
    puts "Deleting ingress for #{@subject}..."
    puts ""

    ingress_name = "#{@subject}-ingress"

    Sh.ell("kubectl delete ingress #{ingress_name} -n foxbox")
  when 'apply ingress'
    puts "Updating/Creating ingress for #{@subject}..."

    unless @env
      puts ""
      puts "Please, express the environment."
      puts "It can be 'production' or 'staging', like:"
      puts "$ kt spy apply ingress appslug staging"
      exit 1
    end

    env_path = "#{@cfg["secrets"]}/#{@env}/#{@subject}"
    ingress_file = "#{env_path}/ingress.yml"

    Sh.ell("kubectl apply -f #{ingress_file} -n foxbox")
  when 'drop all'
    puts "Deleting ALL Kubernetes resources of #{@subject}..."

    puts ""
    puts "Ctrl-C to cancel in 5 seconds..."
    sleep 5
    puts "Starting..."

    drop_cmd = "      kubectl delete deployment \#{@subject}-deployment -n foxbox &&\n      kubectl delete configMap \#{@subject}-config-map -n foxbox &&\n      kubectl delete ingress \#{@subject}-ingress -n foxbox &&\n      kubectl delete service \#{@subject}-service -n foxbox &&\n      kubectl delete secret \#{@subject}-registry -n foxbox\n    HEREDOC\n\n    Sh.ellb!(drop_cmd)\n  else\n    Help.display\n  end\nend\n"