class KubeDeployTools::Deployment

Constants

TIMEOUT

Attributes

found[RW]
local_replicas[RW]
recorded_replicas[RW]
remote_replicas[RW]

Public Instance Methods

sync() click to toggle source
# File lib/kube_deploy_tools/kubernetes_resource/deployment.rb, line 15
def sync
  @local_replicas = @definition["spec"]["replicas"]

  raw_json, _err, st = @kubectl.run("get", "-f", filepath, "--output=json", print_cmd: false, timeout: TIMEOUT)
  @found = st.success?

  if st.success?
    deployment_data = JSON.parse(raw_json)
    @remote_replicas = deployment_data["spec"]["replicas"]
  end

  raw_json, _err, st = @kubectl.run("apply", "view-last-applied", "-f", filepath, "--output=json", print_cmd: false, timeout: TIMEOUT)
  if st.success?
    raw_json = fix_kubectl_apply_view_last_applied_output(raw_json)
    deployment_data = JSON.parse(raw_json)
    @recorded_replicas = deployment_data["spec"]["replicas"]
  end
end
warn_replicas_mismatch() click to toggle source
# File lib/kube_deploy_tools/kubernetes_resource/deployment.rb, line 34
def warn_replicas_mismatch
  if @found
    if @local_replicas.present? && @local_replicas.to_i != @remote_replicas.to_i
      warning = "Deployment replica count mismatch! Will scale deployment/#{@name} from #{@remote_replicas} to #{@local_replicas}"
      Logger.warn(warning)
    elsif @local_replicas.nil? && !@recorded_replicas.nil?
      # Check if we're converting to a replicaless Deployment
      warning = "Deployment replica count mismatch! Will scale deployment/#{@name} from #{@remote_replicas} to 1. Run `kubectl apply set-last-applied -f #{@filepath}` first."
      Logger.warn(warning)
    end
  end
end