Class: KubeDeployTools::Deployment
- Inherits:
-
KubernetesResource
- Object
- KubernetesResource
- KubeDeployTools::Deployment
- Defined in:
- lib/kube_deploy_tools/kubernetes_resource/deployment.rb
Constant Summary collapse
- TIMEOUT =
'60s'
Instance Attribute Summary collapse
-
#found ⇒ Object
Returns the value of attribute found.
-
#local_replicas ⇒ Object
Returns the value of attribute local_replicas.
-
#recorded_replicas ⇒ Object
Returns the value of attribute recorded_replicas.
-
#remote_replicas ⇒ Object
Returns the value of attribute remote_replicas.
Attributes inherited from KubernetesResource
#annotations, #definition, #kind, #name, #namespace
Instance Method Summary collapse
Methods inherited from KubernetesResource
build, #create_definition_tempfile, #file, #filepath, #initialize
Constructor Details
This class inherits a constructor from KubeDeployTools::KubernetesResource
Instance Attribute Details
#found ⇒ Object
Returns the value of attribute found.
10 11 12 |
# File 'lib/kube_deploy_tools/kubernetes_resource/deployment.rb', line 10 def found @found end |
#local_replicas ⇒ Object
Returns the value of attribute local_replicas.
10 11 12 |
# File 'lib/kube_deploy_tools/kubernetes_resource/deployment.rb', line 10 def local_replicas @local_replicas end |
#recorded_replicas ⇒ Object
Returns the value of attribute recorded_replicas.
10 11 12 |
# File 'lib/kube_deploy_tools/kubernetes_resource/deployment.rb', line 10 def recorded_replicas @recorded_replicas end |
#remote_replicas ⇒ Object
Returns the value of attribute remote_replicas.
10 11 12 |
# File 'lib/kube_deploy_tools/kubernetes_resource/deployment.rb', line 10 def remote_replicas @remote_replicas end |
Instance Method Details
#sync ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |