sensu-plugins / sensu-plugins-kubernetes

Sensu plugins for Kubernetes
http://sensu-plugins.io
MIT License
28 stars 36 forks source link

check-kube-pods-running.rb - undefined method `status' for nil:NilClass #39

Closed jkomara closed 6 years ago

jkomara commented 7 years ago

Testing scenario

A master with a single k8s node that has 3 pods deployed. All pods are in "Running" state and check-kube-pods-running.rb passes.

Delete a pod and then immediately run check-kube-pods-running.rb. Receive the following error:

Check failed to run: undefined method `status' for nil:NilClass, 
["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-kubernetes-2.0.0/bin/check-
kube-pods-running.rb:95:in `block in run'", 
"/opt/sensu/embedded/lib/ruby/2.3.0/delegate.rb:341:in `each'", 
"/opt/sensu/embedded/lib/ruby/2.3.0/delegate.rb:341:in `block in delegating_block'", 
"/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-kubernetes-2.0.0/bin/check-
kube-pods-running.rb:89:in `run'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-
plugin-1.4.2/lib/sensu-plugin/cli.rb:58:in `block in <class:CLI>'"]

Cause

This was because in my local environment I did not have enough resource to schedule the new pod until the old pod was deleted. The check is looking to see if pod.status.conditions[1].stats == 'False'. Since it was waiting to be scheduled pod.status.conditions[1] did not exist and threw this error.

Expected result

A critical that declares the pod is not scheduled because of insufficient resources. I feel like in the real world, if I had a pod that could not be schedule due to lack of resources until the existing pod was terminated, I would want to know about it.

If you need any more information please let me know.

Thank you.

replicant0wnz commented 6 years ago

This issue just popped up for me as well. Not sure what caused it. All pods are running correctly with plenty of resources. I'm disabling the monitor for now.

majormoses commented 6 years ago

fixed by #42

released: https://rubygems.org/gems/sensu-plugins-kubernetes/versions/3.0.1