diff --git a/api/v1alpha2/reference_types.go b/api/v1alpha2/reference_types.go index 5622efc9..ddccdd12 100644 --- a/api/v1alpha2/reference_types.go +++ b/api/v1alpha2/reference_types.go @@ -7,7 +7,6 @@ import ( "github.com/fluxcd/pkg/apis/meta" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -166,7 +165,7 @@ type RunnerPodSpec struct { // Runner pod ImagePullPolicy to use other than default // +optional - ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"` + ImagePullPolicy string `json:"imagePullPolicy,omitempty"` // List of sources to populate environment variables in the container. // The keys defined within a source must be a C_IDENTIFIER. All invalid keys diff --git a/controllers/tc000260_runner_pod_test.go b/controllers/tc000260_runner_pod_test.go index 8830b68d..e2536619 100644 --- a/controllers/tc000260_runner_pod_test.go +++ b/controllers/tc000260_runner_pod_test.go @@ -73,6 +73,7 @@ func Test_000260_runner_pod_test(t *testing.T) { spec := reconciler.runnerPodSpec(helloWorldTF, "runner.tls-123") g.Expect(spec.ServiceAccountName).To(Equal(serviceAccountName)) g.Expect(spec.Containers[0].Image).To(Equal(runnerPodImage)) + g.Expect(spec.Containers[0].ImagePullPolicy).To(Equal(corev1.PullIfNotPresent)) g.Expect(spec.HostAliases[0].Hostnames).To(Equal([]string{"foo", "bar"})) podTemplate, err := runnerPodTemplate(helloWorldTF, "runner.tls-123", revision) @@ -178,6 +179,76 @@ func Test_000260_runner_pod_test_env_vars(t *testing.T) { }()).To(BeTrue()) } +func Test_000260_runner_pod_a_test_image_pull_policy(t *testing.T) { + Spec("This spec describes a runner pod creation process") + + const ( + terraformName = "runner-pod-test" + sourceName = "runner-pod-test" + serviceAccountName = "helloworld-tf-runner" + runnerPodImage = "ghcr.io/weaveworks/tf-runner:test" + revision = "v2.6@sha256:c7fd0cc69b924aa5f9a6928477311737e439ca1b9e444855b0377e8a8ec65bb5" + ) + + var stringMap = map[string]string{ + "company.com/abc": "xyz", + "company.com/xyz": "abc", + "tf.weave.works/tls-secret-name": "runner.tls-123", + } + + g := NewWithT(t) + + It("generate a runner pod template") + By("passing a terraform object, the runner pod template should be accurate") + helloWorldTF := infrav1.Terraform{ + ObjectMeta: metav1.ObjectMeta{ + Name: terraformName, + Namespace: "flux-system", + }, + Spec: infrav1.TerraformSpec{ + ApprovePlan: "auto", + Path: "./terraform-hello-world-example", + SourceRef: infrav1.CrossNamespaceSourceReference{ + Kind: "GitRepository", + Name: sourceName, + Namespace: "flux-system", + }, + ServiceAccountName: serviceAccountName, + RunnerPodTemplate: infrav1.RunnerPodTemplate{ + Metadata: infrav1.RunnerPodMetadata{ + Labels: stringMap, + Annotations: stringMap, + }, + Spec: infrav1.RunnerPodSpec{ + Image: runnerPodImage, + ImagePullPolicy: "Always", + }, + }, + }, + } + + spec := reconciler.runnerPodSpec(helloWorldTF, "runner.tls-123") + g.Expect(spec.ServiceAccountName).To(Equal(serviceAccountName)) + g.Expect(spec.Containers[0].Image).To(Equal(runnerPodImage)) + g.Expect(spec.Containers[0].ImagePullPolicy).To(Equal(corev1.PullAlways)) + + podTemplate, err := runnerPodTemplate(helloWorldTF, "runner.tls-123", revision) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(func() bool { + for k, v := range stringMap { + if v != podTemplate.ObjectMeta.Labels[k] { + return false + } + } + for k, v := range stringMap { + if v != podTemplate.ObjectMeta.Annotations[k] { + return false + } + } + return true + }()).To(BeTrue()) +} + func Test_000260_runner_pod_test_env_vars_proxy(t *testing.T) { Spec("This spec describes a runner pod creation process") diff --git a/controllers/tf_controller_runner.go b/controllers/tf_controller_runner.go index 9e30e815..743d499e 100644 --- a/controllers/tf_controller_runner.go +++ b/controllers/tf_controller_runner.go @@ -39,8 +39,8 @@ func getRunnerPodImage(image string) string { return runnerPodImage } -func getRunnerImagePullPolicy(imagePullPolicy v1.PullPolicy) v1.PullPolicy { - runnerImagePullPolicy := imagePullPolicy +func getRunnerImagePullPolicy(imagePullPolicy string) v1.PullPolicy { + runnerImagePullPolicy := v1.PullPolicy(imagePullPolicy) if runnerImagePullPolicy == "" { runnerImagePullPolicy = v1.PullIfNotPresent } diff --git a/docs/References/terraform.md b/docs/References/terraform.md index 3f92743f..1d8f43e9 100644 --- a/docs/References/terraform.md +++ b/docs/References/terraform.md @@ -870,9 +870,7 @@ string imagePullPolicy
- -Kubernetes core/v1.PullPolicy - +string @@ -1113,9 +1111,7 @@ string imagePullPolicy
- -Kubernetes core/v1.PullPolicy - +string