Skip to content

Commit 46218e0

Browse files
yevgeny-shnaidmank8s-ci-robot
authored andcommitted
Updating imagepuller pod to use ImagePullPolicy
Since imagepuller pod must use the same pull policy as worker pod, this commit updates the imagepuller interface to use the pull policy from the MIC object. This commit also updates the unit tests and the mic controller to pass the pull policy from MIC object to the imagepuller interface
1 parent 4ac2be3 commit 46218e0

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

internal/controllers/mic_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ func (mrhi *micReconcilerHelperImpl) processImagesSpecs(ctx context.Context, mic
244244
imageSpec.Image,
245245
oneTimePod,
246246
micObj.Spec.ImageRepoSecret,
247+
micObj.Spec.ImagePullPolicy,
247248
micObj)
248249
errs = append(errs, err)
249250
}

internal/controllers/mic_reconciler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ var _ = Describe("processImagesSpecs", func() {
359359
gomock.InOrder(
360360
micHelper.EXPECT().GetImageState(&testMic, "image 1").Return(kmmv1beta1.ImageState("")),
361361
mockImagePuller.EXPECT().GetPullPodForImage(pullPods, "image 1").Return(nil),
362-
mockImagePuller.EXPECT().CreatePullPod(ctx, "some name", "some namespace", "image 1", expectedOneTimePodFlag, nil, &testMic).Return(nil),
362+
mockImagePuller.EXPECT().CreatePullPod(ctx, "some name", "some namespace", "image 1", expectedOneTimePodFlag,
363+
nil, v1.PullPolicy(""), &testMic).Return(nil),
363364
)
364365
err := mrh.processImagesSpecs(ctx, &testMic, pullPods)
365366
Expect(err).To(BeNil())

internal/pod/imagepuller.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535

3636
type ImagePuller interface {
3737
CreatePullPod(ctx context.Context, name, namespace, imageToPull string, oneTimePod bool,
38-
imageRepoSecret *v1.LocalObjectReference, owner metav1.Object) error
38+
imageRepoSecret *v1.LocalObjectReference, pullPolicy v1.PullPolicy, owner metav1.Object) error
3939
DeletePod(ctx context.Context, pod *v1.Pod) error
4040
ListPullPods(ctx context.Context, name, namespace string) ([]v1.Pod, error)
4141
GetPullPodForImage(pods []v1.Pod, image string) *v1.Pod
@@ -56,7 +56,7 @@ func NewImagePuller(client client.Client, scheme *runtime.Scheme) ImagePuller {
5656
}
5757

5858
func (ipi *imagePullerImpl) CreatePullPod(ctx context.Context, name, namespace, imageToPull string, oneTimePod bool,
59-
imageRepoSecret *v1.LocalObjectReference, owner metav1.Object) error {
59+
imageRepoSecret *v1.LocalObjectReference, pullPolicy v1.PullPolicy, owner metav1.Object) error {
6060

6161
pullPodTypeLabelValue := pullPodUntilSuccess
6262
if oneTimePod {
@@ -80,9 +80,10 @@ func (ipi *imagePullerImpl) CreatePullPod(ctx context.Context, name, namespace,
8080
Spec: v1.PodSpec{
8181
Containers: []v1.Container{
8282
{
83-
Name: pullerContainerName,
84-
Image: imageToPull,
85-
Command: []string{"/bin/sh", "-c", "exit 0"},
83+
Name: pullerContainerName,
84+
Image: imageToPull,
85+
Command: []string{"/bin/sh", "-c", "exit 0"},
86+
ImagePullPolicy: pullPolicy,
8687
},
8788
},
8889
RestartPolicy: v1.RestartPolicyNever,

internal/pod/imagepuller_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ var _ = Describe("CreatePullPod", func() {
162162
testImage := "some image"
163163
testMic := kmmv1beta1.ModuleImagesConfig{}
164164
testRepoSecret := v1.LocalObjectReference{}
165+
imagePullPolicy := v1.PullAlways
165166

166167
It("check the pod fields", func() {
167168
expectedPod := v1.Pod{
@@ -176,9 +177,10 @@ var _ = Describe("CreatePullPod", func() {
176177
Spec: v1.PodSpec{
177178
Containers: []v1.Container{
178179
{
179-
Name: pullerContainerName,
180-
Image: testImage,
181-
Command: []string{"/bin/sh", "-c", "exit 0"},
180+
Name: pullerContainerName,
181+
Image: testImage,
182+
Command: []string{"/bin/sh", "-c", "exit 0"},
183+
ImagePullPolicy: imagePullPolicy,
182184
},
183185
},
184186
RestartPolicy: v1.RestartPolicyNever,
@@ -198,7 +200,7 @@ var _ = Describe("CreatePullPod", func() {
198200
}
199201
return nil
200202
})
201-
err := ip.CreatePullPod(ctx, testName, testNamespace, testImage, false, &testRepoSecret, &testMic)
203+
err := ip.CreatePullPod(ctx, testName, testNamespace, testImage, false, &testRepoSecret, imagePullPolicy, &testMic)
202204
Expect(err).To(BeNil())
203205
})
204206
})

internal/pod/mock_imagepuller.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)