Class: KuberKit::CLI

Inherits:
Thor show all
Defined in:
lib/kuber_kit/cli.rb

Constant Summary collapse

APP_CONFIG_FILENAME =
"config.rb".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/kuber_kit/cli.rb', line 210

def self.exit_on_failure?
  true
end

Instance Method Details

#apply(file_path) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/kuber_kit/cli.rb', line 129

def apply(file_path)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    KuberKit::Container['actions.kubectl_applier'].call(File.expand_path(file_path), options)
  end
end

#attach(pod_name = nil) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/kuber_kit/cli.rb', line 138

def attach(pod_name = nil)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    KuberKit::Container['actions.kubectl_attacher'].call(pod_name, options)
  end
end

#checkObject



110
111
112
113
114
115
116
# File 'lib/kuber_kit/cli.rb', line 110

def check()
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    KuberKit::Container['actions.service_checker'].call(options)
  end
end

#compile(image_names_str) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kuber_kit/cli.rb', line 17

def compile(image_names_str)
  setup(options)
  
  started_at = Time.now.to_i
  image_names = image_names_str.split(",").map(&:strip).map(&:to_sym)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    action_result = KuberKit::Container['actions.image_compiler'].call(image_names, options)
  end

  clean_artifacts(options)

  if action_result && action_result.succeeded?
    time = (Time.now.to_i - started_at)
    print_result("Image compilation finished! (#{time}s)", result: {
      images:       action_result.finished_tasks,
      compilation:  action_result.all_results
    })
  else
    exit 1
  end
end

#console(pod_name = nil) ⇒ Object



147
148
149
150
151
152
153
# File 'lib/kuber_kit/cli.rb', line 147

def console(pod_name = nil)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
    KuberKit::Container['actions.kubectl_console'].call(pod_name, options)
  end
end

#deployObject



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
# File 'lib/kuber_kit/cli.rb', line 49

def deploy
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    require_confirmation = options[:require_confirmation] || 
                           KuberKit.current_configuration.deployer_require_confirmation ||
                           false
    require_confirmation = false if options[:skip_confirmation]
    started_at = Time.now.to_i
    action_result = KuberKit::Container['actions.service_deployer'].call(
      services:             (options[:services] || []).flatten.uniq, 
      tags:                 (options[:tags] || []).flatten.uniq,
      skip_services:        (options[:skip_services] || []).flatten.uniq, 
      skip_compile:         options[:skip_compile] || false,
      skip_dependencies:    options[:skip_dependencies] || false,
      skip_deployment:      options[:skip_deployment] || false,
      require_confirmation: require_confirmation
    )
  end

  clean_artifacts(options)

  if action_result && action_result.succeeded?
    time = (Time.now.to_i - started_at)
    print_result("Service deployment finished! (#{time}s)", result: {
      services:   action_result.finished_tasks, 
      deployment: action_result.all_results
    })
  else
    exit 1
  end
end

#describe(pod_name = nil) ⇒ Object



166
167
168
169
170
171
172
# File 'lib/kuber_kit/cli.rb', line 166

def describe(pod_name = nil)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
    KuberKit::Container['actions.kubectl_describe'].call(pod_name, options)
  end
end

#envObject



175
176
177
178
179
180
181
# File 'lib/kuber_kit/cli.rb', line 175

def env()
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
    KuberKit::Container['actions.kubectl_env'].call(options)
  end
end

#envfile(env_file_name) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/kuber_kit/cli.rb', line 83

def envfile(env_file_name)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    KuberKit::Container['actions.env_file_reader'].call(env_file_name.to_sym, options)
  end
end

#generate(service_name, path) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/kuber_kit/cli.rb', line 120

def generate(service_name, path)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    KuberKit::Container['actions.service_generator'].call(service_name.to_sym, path)
  end
end

#get(pod_name = nil) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/kuber_kit/cli.rb', line 193

def get(pod_name = nil)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
    pods = KuberKit::Container['actions.kubectl_get'].call(pod_name, options)

    print_result("Fetched list of pods", result: {
      pods: pods
    })
  end
end

#logs(pod_name = nil) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/kuber_kit/cli.rb', line 157

def logs(pod_name = nil)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
    KuberKit::Container['actions.kubectl_logs'].call(pod_name, options)
  end
end

#service(service_name) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/kuber_kit/cli.rb', line 101

def service(service_name)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    KuberKit::Container['actions.service_reader'].call(service_name.to_sym, options)
  end
end

#shObject



184
185
186
187
188
189
190
# File 'lib/kuber_kit/cli.rb', line 184

def sh()
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
    KuberKit::Container['actions.shell_launcher'].call()
  end
end

#template(template_name) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/kuber_kit/cli.rb', line 92

def template(template_name)
  setup(options)

  if KuberKit::Container['actions.configuration_loader'].call(options)
    KuberKit::Container['actions.template_reader'].call(template_name.to_sym, options)
  end
end

#versionObject



206
207
208
# File 'lib/kuber_kit/cli.rb', line 206

def version
  puts KuberKit::VERSION
end