From a9afaa1eee95e4b6f1b224372a52981c20573e48 Mon Sep 17 00:00:00 2001 From: Daniel Vega-Myhre Date: Tue, 27 Jun 2023 18:06:09 +0000 Subject: [PATCH] add feature gate --- pkg/controller/job/job_controller.go | 5 ++++- pkg/controller/job/job_controller_test.go | 5 ++++- pkg/features/kube_features.go | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/controller/job/job_controller.go b/pkg/controller/job/job_controller.go index cce20c08b5f..fa76c7ccff5 100644 --- a/pkg/controller/job/job_controller.go +++ b/pkg/controller/job/job_controller.go @@ -1482,7 +1482,10 @@ func (jm *Controller) manageJob(ctx context.Context, job *batch.Job, activePods if completionIndex != unknownCompletionIndex { template = podTemplate.DeepCopy() addCompletionIndexAnnotation(template, completionIndex) - addCompletionIndexLabel(template, completionIndex) + + if feature.DefaultFeatureGate.Enabled(features.PodIndexLabel) { + addCompletionIndexLabel(template, completionIndex) + } template.Spec.Hostname = fmt.Sprintf("%s-%d", job.Name, completionIndex) generateName = podGenerateNameWithIndex(job.Name, completionIndex) } diff --git a/pkg/controller/job/job_controller_test.go b/pkg/controller/job/job_controller_test.go index 8087c16e8d2..a0608acbad3 100644 --- a/pkg/controller/job/job_controller_test.go +++ b/pkg/controller/job/job_controller_test.go @@ -962,7 +962,9 @@ func checkIndexedJobPods(t *testing.T, control *controller.FakePodControl, wantI gotIndexes := sets.New[int]() for _, p := range control.Templates { checkJobCompletionEnvVariable(t, &p.Spec) - checkJobCompletionLabel(t, &p) + if feature.DefaultFeatureGate.Enabled(features.PodIndexLabel) { + checkJobCompletionLabel(t, &p) + } ix := getCompletionIndex(p.Annotations) if ix == -1 { t.Errorf("Created pod %s didn't have completion index", p.Name) @@ -4395,6 +4397,7 @@ func TestFinalizersRemovedExpectations(t *testing.T) { t.Errorf("Timeout waiting for expectations (-want, +got):\n%s", diff) } } + func checkJobCompletionLabel(t *testing.T, p *v1.PodTemplateSpec) { t.Helper() labels := p.GetLabels() diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 3827a55e388..26ea0409fe3 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -843,6 +843,13 @@ const ( // // Enables In-Place Pod Vertical Scaling InPlacePodVerticalScaling featuregate.Feature = "InPlacePodVerticalScaling" + + // owner: @danielvegamyhre + // kep: https://kep.k8s.io/4017 + // beta: v1.28 + // + // Set pod completion index as a pod label for Indexed Jobs and StatefulSets. + PodIndexLabel featuregate.Feature = "PodIndexLabel" ) func init() { @@ -1072,6 +1079,8 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS InPlacePodVerticalScaling: {Default: false, PreRelease: featuregate.Alpha}, + PodIndexLabel: {Default: true, PreRelease: featuregate.Beta}, + // inherited features from generic apiserver, relisted here to get a conflict if it is changed // unintentionally on either side: