mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Merge pull request #71479 from soggiest/podpreset-initcontainers
PodPreset: Add same functionality for init containers as standard containers
This commit is contained in:
commit
55a65763c0
@ -184,6 +184,12 @@ func safeToApplyPodPresetsOnPod(pod *api.Pod, podPresets []*settingsv1alpha1.Pod
|
|||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, iCtr := range pod.Spec.InitContainers {
|
||||||
|
if err := safeToApplyPodPresetsOnContainer(&iCtr, podPresets); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return utilerrors.NewAggregate(errs)
|
return utilerrors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,6 +387,10 @@ func applyPodPresetsOnPod(pod *api.Pod, podPresets []*settingsv1alpha1.PodPreset
|
|||||||
applyPodPresetsOnContainer(&ctr, podPresets)
|
applyPodPresetsOnContainer(&ctr, podPresets)
|
||||||
pod.Spec.Containers[i] = ctr
|
pod.Spec.Containers[i] = ctr
|
||||||
}
|
}
|
||||||
|
for i, iCtr := range pod.Spec.InitContainers {
|
||||||
|
applyPodPresetsOnContainer(&iCtr, podPresets)
|
||||||
|
pod.Spec.InitContainers[i] = iCtr
|
||||||
|
}
|
||||||
|
|
||||||
// add annotation
|
// add annotation
|
||||||
if pod.ObjectMeta.Annotations == nil {
|
if pod.ObjectMeta.Annotations == nil {
|
||||||
|
@ -99,6 +99,13 @@ var _ = SIGDescribe("[Feature:PodPreset] PodPreset", func() {
|
|||||||
Image: imageutils.GetE2EImage(imageutils.Nginx),
|
Image: imageutils.GetE2EImage(imageutils.Nginx),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
InitContainers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "init1",
|
||||||
|
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
||||||
|
Command: []string{"/bin/true"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +160,9 @@ var _ = SIGDescribe("[Feature:PodPreset] PodPreset", func() {
|
|||||||
if !reflect.DeepEqual(pip.Spec.Env, pod.Spec.Containers[0].Env) {
|
if !reflect.DeepEqual(pip.Spec.Env, pod.Spec.Containers[0].Env) {
|
||||||
framework.Failf("env of pod container does not match the env of the pip: expected %#v, got: %#v", pip.Spec.Env, pod.Spec.Containers[0].Env)
|
framework.Failf("env of pod container does not match the env of the pip: expected %#v, got: %#v", pip.Spec.Env, pod.Spec.Containers[0].Env)
|
||||||
}
|
}
|
||||||
|
if !reflect.DeepEqual(pip.Spec.Env, pod.Spec.InitContainers[0].Env) {
|
||||||
|
framework.Failf("env of pod init container does not match the env of the pip: expected %#v, got: %#v", pip.Spec.Env, pod.Spec.InitContainers[0].Env)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("should not modify the pod on conflict", func() {
|
ginkgo.It("should not modify the pod on conflict", func() {
|
||||||
@ -208,6 +218,14 @@ var _ = SIGDescribe("[Feature:PodPreset] PodPreset", func() {
|
|||||||
Env: []v1.EnvVar{{Name: "abc", Value: "value2"}, {Name: "ABC", Value: "value"}},
|
Env: []v1.EnvVar{{Name: "abc", Value: "value2"}, {Name: "ABC", Value: "value"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
InitContainers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "init1",
|
||||||
|
Image: imageutils.GetE2EImage(imageutils.BusyBox),
|
||||||
|
Env: []v1.EnvVar{{Name: "abc", Value: "value2"}, {Name: "ABC", Value: "value"}},
|
||||||
|
Command: []string{"/bin/true"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,6 +280,10 @@ var _ = SIGDescribe("[Feature:PodPreset] PodPreset", func() {
|
|||||||
if !reflect.DeepEqual(originalPod.Spec.Containers[0].Env, pod.Spec.Containers[0].Env) {
|
if !reflect.DeepEqual(originalPod.Spec.Containers[0].Env, pod.Spec.Containers[0].Env) {
|
||||||
framework.Failf("env of pod container does not match the env of the original pod: expected %#v, got: %#v", originalPod.Spec.Containers[0].Env, pod.Spec.Containers[0].Env)
|
framework.Failf("env of pod container does not match the env of the original pod: expected %#v, got: %#v", originalPod.Spec.Containers[0].Env, pod.Spec.Containers[0].Env)
|
||||||
}
|
}
|
||||||
|
if !reflect.DeepEqual(originalPod.Spec.InitContainers[0].Env, pod.Spec.InitContainers[0].Env) {
|
||||||
|
framework.Failf("env of pod init container does not match the env of the original pod: expected %#v, got: %#v", originalPod.Spec.InitContainers[0].Env, pod.Spec.InitContainers[0].Env)
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user