Method: KubernetesCLI#delete_objects

Defined in:
lib/kubernetes-cli.rb

#delete_objects(type, namespace, match_labels = {}) ⇒ Object

T::Sig::WithoutRuntime.sig

params(
  type: String,
  namespace: T.any(String, Symbol),
  match_labels: T::Hash[String, String]
).void

[View source]

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/kubernetes-cli.rb', line 293

def delete_objects(type, namespace, match_labels = {})
  cmd = [executable, '--kubeconfig', kubeconfig_path]

  if namespace == :all
    cmd << '--all-namespaces'
  elsif namespace
    cmd += ['-n', namespace.to_s]
  end

  cmd += ['delete', type]

  unless match_labels.empty?
    cmd += ['--selector', match_labels.map { |key, value| "#{key}=#{value}" }.join(',')]
  end

  systemm(cmd)

  on_last_status_failure do |last_status|
    raise DeleteResourceError, "couldn't delete resources of type '#{type}' "\
      "in namespace #{namespace}: kubectl exited with status code #{last_status.exitstatus}"
  end
end