From 8c246a5450ffb82b94e03e19caeb05458b9a6cb8 Mon Sep 17 00:00:00 2001 From: Somtochi Onyekwere Date: Thu, 19 May 2022 13:15:11 +0100 Subject: [PATCH] Set digests in image override Signed-off-by: Somtochi Onyekwere --- controllers/kustomization_generator.go | 1 + controllers/kustomization_generator_test.go | 4 ++++ controllers/kustomization_transformer_test.go | 6 ++++++ controllers/testdata/patch/deployment.yaml | 2 ++ 4 files changed, 13 insertions(+) diff --git a/controllers/kustomization_generator.go b/controllers/kustomization_generator.go index daa43e0..9657cd0 100644 --- a/controllers/kustomization_generator.go +++ b/controllers/kustomization_generator.go @@ -104,6 +104,7 @@ func (kg *KustomizeGenerator) WriteFile(dirPath string) error { Name: image.Name, NewName: image.NewName, NewTag: image.NewTag, + Digest: image.Digest, } if exists, index := checkKustomizeImageExists(kus.Images, image.Name); exists { kus.Images[index] = newImage diff --git a/controllers/kustomization_generator_test.go b/controllers/kustomization_generator_test.go index da73ffb..3186d1a 100644 --- a/controllers/kustomization_generator_test.go +++ b/controllers/kustomization_generator_test.go @@ -50,3 +50,7 @@ func Test_secureBuildKustomization_panic(t *testing.T) { g.Expect(err).To(HaveOccurred()) }) } + +func Test_WriteFile(t *testing.T) { + +} diff --git a/controllers/kustomization_transformer_test.go b/controllers/kustomization_transformer_test.go index 672ccbf..d241a68 100644 --- a/controllers/kustomization_transformer_test.go +++ b/controllers/kustomization_transformer_test.go @@ -332,6 +332,10 @@ func TestKustomizationReconciler_FluxTransformers(t *testing.T) { NewName: "ghcr.io/stefanprodan/podinfo", NewTag: "5.2.0", }, + { + Name: "ghcr.io/fluxcd/flagger", + Digest: "sha256:2832f53c577d44753e97b0ed5f00e7e3a06979c9fab77d0e78bdac4b612b14fb", + }, }, Patches: []kustomize.Patch{ { @@ -394,6 +398,8 @@ metadata: g.Expect(deployment.ObjectMeta.Labels["patch3"]).To(Equal("json6902")) g.Expect(deployment.ObjectMeta.Labels["patch4"]).To(Equal("strategic-merge")) g.Expect(*deployment.Spec.Replicas).To(Equal(int32(2))) + g.Expect(deployment.Spec.Template.Spec.Containers[0].Image).To(ContainSubstring("5.2.0")) + g.Expect(deployment.Spec.Template.Spec.Containers[1].Image).To(ContainSubstring("sha256:2832f53c577d44753e97b0ed5f00e7e3a06979c9fab77d0e78bdac4b612b14fb")) }) } diff --git a/controllers/testdata/patch/deployment.yaml b/controllers/testdata/patch/deployment.yaml index d38011b..178cd06 100644 --- a/controllers/testdata/patch/deployment.yaml +++ b/controllers/testdata/patch/deployment.yaml @@ -17,3 +17,5 @@ spec: containers: - name: podinfo image: podinfo + - name: flagger + image: ghcr.io/fluxcd/flagger