Class: KubernetesDeploy::Pod::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/kubernetes-deploy/kubernetes_resource/pod.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, init_container: false) ⇒ Container

Returns a new instance of Container.



167
168
169
170
171
172
173
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 167

def initialize(definition, init_container: false)
  @init_container = init_container
  @name = definition["name"]
  @image = definition["image"]
  @probe_location = definition.dig("readinessProbe", "httpGet", "path")
  @status = {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



165
166
167
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 165

def name
  @name
end

#probe_locationObject (readonly)

Returns the value of attribute probe_location.



165
166
167
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 165

def probe_location
  @probe_location
end

Instance Method Details

#doom_reasonObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 179

def doom_reason
  exit_code = @status.dig('lastState', 'terminated', 'exitCode')
  last_terminated_reason = @status.dig("lastState", "terminated", "reason")
  limbo_reason = @status.dig("state", "waiting", "reason")
  limbo_message = @status.dig("state", "waiting", "message")

  if last_terminated_reason == "ContainerCannotRun"
    # ref: https://github.com/kubernetes/kubernetes/blob/562e721ece8a16e05c7e7d6bdd6334c910733ab2/pkg/kubelet/dockershim/docker_container.go#L353
    "Failed to start (exit #{exit_code}): #{@status.dig('lastState', 'terminated', 'message')}"
  elsif limbo_reason == "CrashLoopBackOff"
    "Crashing repeatedly (exit #{exit_code}). See logs for more information."
  elsif %w(ImagePullBackOff ErrImagePull).include?(limbo_reason) &&
    limbo_message.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 limbo_message == "Generate Container Config Failed"
    # reason/message are backwards
    # Flip this after https://github.com/kubernetes/kubernetes/commit/df41787b1a3f51b73fb6db8a2203f0a7c7c92931
    "Failed to generate container configuration: #{limbo_reason}"
  end
end

#doomed?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 175

def doomed?
  doom_reason.present?
end

#init_container?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 205

def init_container?
  @init_container
end

#ready?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 201

def ready?
  @status['ready'] == "true"
end

#reset_statusObject



213
214
215
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 213

def reset_status
  @status = {}
end

#update_status(data) ⇒ Object



209
210
211
# File 'lib/kubernetes-deploy/kubernetes_resource/pod.rb', line 209

def update_status(data)
  @status = data || {}
end