mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 20:42:26 +00:00
fix unit test bug
This commit is contained in:
parent
a1a5f49bb9
commit
037091284e
@ -26,8 +26,10 @@ import (
|
|||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apiserver/pkg/storage/names"
|
"k8s.io/apiserver/pkg/storage/names"
|
||||||
|
"k8s.io/apiserver/pkg/util/feature"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
|
"k8s.io/kubernetes/pkg/features"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -294,11 +296,17 @@ func addCompletionIndexEnvVariable(container *v1.Container) {
|
|||||||
return
|
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{
|
container.Env = append(container.Env, v1.EnvVar{
|
||||||
Name: completionIndexEnvName,
|
Name: completionIndexEnvName,
|
||||||
ValueFrom: &v1.EnvVarSource{
|
ValueFrom: &v1.EnvVarSource{
|
||||||
FieldRef: &v1.ObjectFieldSelector{
|
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()
|
t.Helper()
|
||||||
gotIndexes := sets.New[int]()
|
gotIndexes := sets.New[int]()
|
||||||
for _, p := range control.Templates {
|
for _, p := range control.Templates {
|
||||||
checkJobCompletionEnvVariable(t, &p.Spec)
|
checkJobCompletionEnvVariable(t, &p.Spec, podIndexLabelDisabled)
|
||||||
if !podIndexLabelDisabled {
|
if !podIndexLabelDisabled {
|
||||||
checkJobCompletionLabel(t, &p)
|
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()
|
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{
|
want := []v1.EnvVar{
|
||||||
{
|
{
|
||||||
Name: "JOB_COMPLETION_INDEX",
|
Name: "JOB_COMPLETION_INDEX",
|
||||||
ValueFrom: &v1.EnvVarSource{
|
ValueFrom: &v1.EnvVarSource{
|
||||||
FieldRef: &v1.ObjectFieldSelector{
|
FieldRef: &v1.ObjectFieldSelector{
|
||||||
FieldPath: fmt.Sprintf("metadata.annotations['%s']", batch.JobCompletionIndexAnnotation),
|
FieldPath: fieldPath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user