Class: KubernetesDeploy::Pod::Container
- Inherits:
-
Object
- Object
- KubernetesDeploy::Pod::Container
- Defined in:
- lib/kubernetes-deploy/kubernetes_resource/pod.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #doom_reason ⇒ Object
- #doomed? ⇒ Boolean
- #init_container? ⇒ Boolean
-
#initialize(definition, init_container: false) ⇒ Container
constructor
A new instance of Container.
- #readiness_fail_reason ⇒ Object
- #ready? ⇒ Boolean
- #reset_status ⇒ Object
- #update_status(data) ⇒ Object
Constructor Details
#initialize(definition, init_container: false) ⇒ Container
Returns a new instance of Container.
173 174 175 176 177 178 179 180 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 173 def initialize(definition, init_container: false) @init_container = init_container @name = definition["name"] @image = definition["image"] @http_probe_location = definition.dig("readinessProbe", "httpGet", "path") @exec_probe_command = definition.dig("readinessProbe", "exec", "command") @status = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
171 172 173 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 171 def name @name end |
Instance Method Details
#doom_reason ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 186 def doom_reason limbo_reason = @status.dig("state", "waiting", "reason") = @status.dig("state", "waiting", "message") if @status.dig("lastState", "terminated", "reason") == "ContainerCannotRun" # ref: https://github.com/kubernetes/kubernetes/blob/562e721ece8a16e05c7e7d6bdd6334c910733ab2/pkg/kubelet/dockershim/docker_container.go#L353 exit_code = @status.dig('lastState', 'terminated', 'exitCode') "Failed to start (exit #{exit_code}): #{@status.dig('lastState', 'terminated', 'message')}" elsif @status.dig("state", "terminated", "reason") == "ContainerCannotRun" exit_code = @status.dig('state', 'terminated', 'exitCode') "Failed to start (exit #{exit_code}): #{@status.dig('state', 'terminated', 'message')}" elsif limbo_reason == "CrashLoopBackOff" exit_code = @status.dig('lastState', 'terminated', 'exitCode') "Crashing repeatedly (exit #{exit_code}). See logs for more information." elsif %w(ImagePullBackOff ErrImagePull).include?(limbo_reason) && .match(/(?:not found)|(?:back-off)/i) "Failed to pull image #{@image}. "\ "Did you wait for it to be built and pushed to the registry before deploying?" elsif == "Generate Container Config Failed" # reason/message are backwards in <1.8.0 (next condition used by 1.8.0+) # Fixed by https://github.com/kubernetes/kubernetes/commit/df41787b1a3f51b73fb6db8a2203f0a7c7c92931 "Failed to generate container configuration: #{limbo_reason}" elsif limbo_reason == "CreateContainerConfigError" "Failed to generate container configuration: #{}" end end |
#doomed? ⇒ Boolean
182 183 184 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 182 def doomed? doom_reason.present? end |
#init_container? ⇒ Boolean
229 230 231 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 229 def init_container? @init_container end |
#readiness_fail_reason ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 213 def readiness_fail_reason return if ready? || init_container? return unless (@http_probe_location || @exec_probe_command).present? yellow_name = ColorizedString.new(name).yellow if @http_probe_location "> #{yellow_name} must respond with a good status code at '#{@http_probe_location}'" elsif @exec_probe_command "> #{yellow_name} must exit 0 from the following command: '#{@exec_probe_command.join(' ')}'" end end |
#ready? ⇒ Boolean
225 226 227 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 225 def ready? @status['ready'] == true end |
#reset_status ⇒ Object
237 238 239 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 237 def reset_status @status = {} end |
#update_status(data) ⇒ Object
233 234 235 |
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 233 def update_status(data) @status = data || {} end |