Only consider running pods when checking version

Some clusters may have failed pods that are not garbage collected. These
pods should not be considered when determining version numbers.

Signed-off-by: John Chadwick <86682572+johnwchadwick@users.noreply.github.com>
This commit is contained in:
John Chadwick
2021-11-23 11:32:10 -05:00
parent 5ad5ef4fb9
commit d094e20611
2 changed files with 7 additions and 0 deletions
+4
View File
@@ -53,6 +53,10 @@ func (o *versionChecker) extractVersionFromService(
}
for _, pod := range pods.Items {
if pod.Status.Phase != corev1.PodRunning {
continue
}
if label := extractVersionFromLabels(pod.Labels); label != "" {
o.versionSources["webhookPodLabelVersion"] = label
}
@@ -51,6 +51,9 @@ func getPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Objec
Name: prefix + cmutil.RandStringRunes(5),
Finalizers: desiredFinalizers,
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
},
}
if controllerRef != nil {
pod.OwnerReferences = append(pod.OwnerReferences, *controllerRef)