mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	fix unit test bug
This commit is contained in:
		@@ -26,8 +26,10 @@ import (
 | 
			
		||||
	v1 "k8s.io/api/core/v1"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/util/sets"
 | 
			
		||||
	"k8s.io/apiserver/pkg/storage/names"
 | 
			
		||||
	"k8s.io/apiserver/pkg/util/feature"
 | 
			
		||||
	"k8s.io/klog/v2"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/controller"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/features"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
@@ -294,11 +296,17 @@ func addCompletionIndexEnvVariable(container *v1.Container) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	var fieldPath string
 | 
			
		||||
	if feature.DefaultFeatureGate.Enabled(features.PodIndexLabel) {
 | 
			
		||||
		fieldPath = fmt.Sprintf("metadata.labels['%s']", batch.JobCompletionIndexAnnotation)
 | 
			
		||||
	} else {
 | 
			
		||||
		fieldPath = fmt.Sprintf("metadata.annotations['%s']", batch.JobCompletionIndexAnnotation)
 | 
			
		||||
	}
 | 
			
		||||
	container.Env = append(container.Env, v1.EnvVar{
 | 
			
		||||
		Name: completionIndexEnvName,
 | 
			
		||||
		ValueFrom: &v1.EnvVarSource{
 | 
			
		||||
			FieldRef: &v1.ObjectFieldSelector{
 | 
			
		||||
				FieldPath: fmt.Sprintf("metadata.labels['%s']", batch.JobCompletionIndexAnnotation),
 | 
			
		||||
				FieldPath: fieldPath,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 
 | 
			
		||||
@@ -973,7 +973,7 @@ func checkIndexedJobPods(t *testing.T, control *controller.FakePodControl, wantI
 | 
			
		||||
	t.Helper()
 | 
			
		||||
	gotIndexes := sets.New[int]()
 | 
			
		||||
	for _, p := range control.Templates {
 | 
			
		||||
		checkJobCompletionEnvVariable(t, &p.Spec)
 | 
			
		||||
		checkJobCompletionEnvVariable(t, &p.Spec, podIndexLabelDisabled)
 | 
			
		||||
		if !podIndexLabelDisabled {
 | 
			
		||||
			checkJobCompletionLabel(t, &p)
 | 
			
		||||
		}
 | 
			
		||||
@@ -4418,14 +4418,20 @@ func checkJobCompletionLabel(t *testing.T, p *v1.PodTemplateSpec) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func checkJobCompletionEnvVariable(t *testing.T, spec *v1.PodSpec) {
 | 
			
		||||
func checkJobCompletionEnvVariable(t *testing.T, spec *v1.PodSpec, podIndexLabelDisabled bool) {
 | 
			
		||||
	t.Helper()
 | 
			
		||||
	var fieldPath string
 | 
			
		||||
	if podIndexLabelDisabled {
 | 
			
		||||
		fieldPath = fmt.Sprintf("metadata.annotations['%s']", batch.JobCompletionIndexAnnotation)
 | 
			
		||||
	} else {
 | 
			
		||||
		fieldPath = fmt.Sprintf("metadata.labels['%s']", batch.JobCompletionIndexAnnotation)
 | 
			
		||||
	}
 | 
			
		||||
	want := []v1.EnvVar{
 | 
			
		||||
		{
 | 
			
		||||
			Name: "JOB_COMPLETION_INDEX",
 | 
			
		||||
			ValueFrom: &v1.EnvVarSource{
 | 
			
		||||
				FieldRef: &v1.ObjectFieldSelector{
 | 
			
		||||
					FieldPath: fmt.Sprintf("metadata.annotations['%s']", batch.JobCompletionIndexAnnotation),
 | 
			
		||||
					FieldPath: fieldPath,
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user