2019-06-17 20:02:10 +00:00
package basic
import (
"fmt"
"github.com/digitalocean/clusterlint/checks"
"github.com/digitalocean/clusterlint/kube"
corev1 "k8s.io/api/core/v1"
)
func init ( ) {
checks . Register ( & podStatusCheck { } )
}
type podStatusCheck struct { }
// Name returns a unique name for this check.
func ( p * podStatusCheck ) Name ( ) string {
return "pod-state"
}
// Groups returns a list of group names this check should be part of.
func ( p * podStatusCheck ) Groups ( ) [ ] string {
2019-06-20 19:28:24 +00:00
return [ ] string { "workload-health" }
2019-06-17 20:02:10 +00:00
}
// Description returns a detailed human-readable description of what this check
// does.
func ( p * podStatusCheck ) Description ( ) string {
return "Check if there are unhealthy pods in the cluster"
}
// Run runs this check on a set of Kubernetes objects. It can return warnings
// (low-priority problems) and errors (high-priority problems) as well as an
// error value indicating that the check failed to run.
2019-06-21 21:36:55 +00:00
func ( p * podStatusCheck ) Run ( objects * kube . Objects ) ( [ ] checks . Diagnostic , error ) {
var diagnostics [ ] checks . Diagnostic
2019-06-17 20:02:10 +00:00
for _ , pod := range objects . Pods . Items {
if corev1 . PodFailed == pod . Status . Phase || corev1 . PodUnknown == pod . Status . Phase {
2019-06-21 21:36:55 +00:00
d := checks . Diagnostic {
Severity : checks . Warning ,
Message : fmt . Sprintf ( "Pod '%s' in namespace '%s' has state: %s. Pod state should be `Running`, `Pending` or `Succeeded`." , pod . GetName ( ) , pod . GetNamespace ( ) , pod . Status . Phase ) ,
2019-06-25 14:35:34 +00:00
Kind : checks . Pod ,
Object : & pod . ObjectMeta ,
2019-06-21 21:36:55 +00:00
Owners : pod . ObjectMeta . GetOwnerReferences ( ) ,
}
diagnostics = append ( diagnostics , d )
2019-06-17 20:02:10 +00:00
}
}
2019-06-21 20:09:43 +00:00
return diagnostics , nil
2019-06-17 20:02:10 +00:00
}