derailed 2021-03-22 09:13:01 -06:00
parent 66e4528244
commit 89ff119977
1 changed files with 18 additions and 7 deletions

View File

@ -13,6 +13,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/1.5/pkg/api"
mv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
)
@ -121,7 +122,7 @@ func (p Pod) Render(o interface{}, ns string, row *Row) error {
mapToStr(po.Labels),
asStatus(p.diagnose(phase, cr, len(ss))),
asNominated(po.Status.NominatedNodeName),
asReadinessGate(po.Spec.ReadinessGates),
asReadinessGate(po),
toAge(po.ObjectMeta.CreationTimestamp),
}
@ -149,15 +150,25 @@ func asNominated(n string) string {
return n
}
func asReadinessGate(gg []v1.PodReadinessGate) string {
if len(gg) == 0 {
func asReadinessGate(pod v1.Pod) string {
if len(pod.Spec.ReadinessGates) == 0 {
return MissingValue
}
ss := make([]string, 0, len(gg))
for _, g := range gg {
ss = append(ss, string(g.ConditionType))
trueConditions := 0
for _, readinessGate := range pod.Spec.ReadinessGates {
conditionType := readinessGate.ConditionType
for _, condition := range pod.Status.Conditions {
if condition.Type == conditionType {
if condition.Status == api.ConditionTrue {
trueConditions++
}
break
}
}
}
return strings.Join(ss, ",")
return strconv.Itoa(trueConditions) + "/" + strconv.Itoa(len(pod.Spec.ReadinessGates))
}
// PodWithMetrics represents a pod and its metrics.