Sha256: fc9d995e3dda5e2904479d455c6f600f77dd8688e3d34d6937a1cf5991fa734a

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

require 'json'
require 'shellwords'

class KuberKit::Shell::KubectlCommands
  def apply_file(shell, file_path, kubeconfig_path: nil)
    command_parts = []
    if kubeconfig_path
      command_parts << "KUBECONFIG=#{kubeconfig_path}"
    end

    command_parts << "kubectl apply -f #{file_path}"

    shell.exec!(command_parts.join(" "))
  end

  def rolling_restart(shell, deployment_name, kubeconfig_path: nil)
    patch_deployment(shell, deployment_name, {
      spec: {
        template: {
          metadata: {
            labels: {
              redeploy: "$(date +%s)"
            }
          }
        }
      }
    }, kubeconfig_path: kubeconfig_path)
  end

  def patch_deployment(shell, deployment_name, specs, kubeconfig_path: nil)
    command_parts = []
    if kubeconfig_path
      command_parts << "KUBECONFIG=#{kubeconfig_path}"
    end

    specs_json = JSON.dump(specs).gsub('"', '\"')

    command_parts << %Q{kubectl patch deployment #{deployment_name} -p "#{specs_json}"}

    shell.exec!(command_parts.join(" "))
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kuber_kit-0.1.8 lib/kuber_kit/shell/kubectl_commands.rb
kuber_kit-0.1.7 lib/kuber_kit/shell/kubectl_commands.rb
kuber_kit-0.1.6 lib/kuber_kit/shell/kubectl_commands.rb
kuber_kit-0.1.5 lib/kuber_kit/shell/kubectl_commands.rb
kuber_kit-0.1.4 lib/kuber_kit/shell/kubectl_commands.rb