Sha256: 8cb718247482083a00851bc528ea90debdb477c6a4c5bd8ca0de00e18534f7c8

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

class KuberKit::Actions::KubectlDescribe
  include KuberKit::Import[
    "shell.kubectl_commands",
    "shell.local_shell",
    "ui"
  ]

  Contract Maybe[String], Hash => Any
  def call(resource_name, options)
    kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
    deployer_namespace = KuberKit.current_configuration.deployer_namespace

    if !resource_name 
      resource_name  = get_resource_name
    end

    args = nil
    if options[:follow]
      args = "-f"
    end

    kubectl_commands.describe(
      local_shell, resource_name,
      args: args,
      kubeconfig_path: kubeconfig_path, 
      namespace: deployer_namespace
    )

    true
  rescue KuberKit::Error => e
    ui.print_error("Error", e.message)
    
    false
  end

  def get_resource_name
    deployments     = kubectl_commands.get_resources(local_shell, "deployments", jsonpath: ".items[*].metadata.name")
    options  = deployments.split(" ").map{|d| "deploy/#{d}" }
    options  += ["ingresses", "pods"]
    option  = ui.prompt("Please select resource to describe", options)

    if option == "ingresses"
      ingresses = kubectl_commands.get_resources(local_shell, "ingresses", jsonpath: ".items[*].metadata.name")
      options   = ingresses.split(" ").map{|d| "ingresses/#{d}" }
      return ui.prompt("Please select ingress to describe", options)
    end

    if option == "pods"
      ingresses = kubectl_commands.get_resources(local_shell, "pods", jsonpath: ".items[*].metadata.name")
      options   = ingresses.split(" ").map{|d| "pods/#{d}" }
      return ui.prompt("Please select pod to describe", options)
    end
    
    option
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kuber_kit-0.4.5 lib/kuber_kit/actions/kubectl_describe.rb