Add StatefulSet pod index as pod label (#119232)

* add statefulset pod index as pod label

* change statefulset pod index label name

* check 3 pods

* change label variable name
This commit is contained in:
Daniel Vega-Myhre
2023-07-17 12:47:10 -07:00
committed by GitHub
parent 56f6030125
commit 7698fe7639
3 changed files with 32 additions and 2 deletions

View File

@@ -390,12 +390,16 @@ func initIdentity(set *apps.StatefulSet, pod *v1.Pod) {
// updateIdentity updates pod's name, hostname, and subdomain, and StatefulSetPodNameLabel to conform to set's name
// and headless service.
func updateIdentity(set *apps.StatefulSet, pod *v1.Pod) {
pod.Name = getPodName(set, getOrdinal(pod))
ordinal := getOrdinal(pod)
pod.Name = getPodName(set, ordinal)
pod.Namespace = set.Namespace
if pod.Labels == nil {
pod.Labels = make(map[string]string)
}
pod.Labels[apps.StatefulSetPodNameLabel] = pod.Name
if utilfeature.DefaultFeatureGate.Enabled(features.PodIndexLabel) {
pod.Labels[apps.PodIndexLabel] = strconv.Itoa(ordinal)
}
}
// isRunningAndReady returns true if pod is in the PodRunning Phase, if it has a condition of PodReady.