diff --git a/controllers/kustomization_controller_patch_test.go b/controllers/kustomization_controller_patch_test.go index 18ed621e..b90ec202 100644 --- a/controllers/kustomization_controller_patch_test.go +++ b/controllers/kustomization_controller_patch_test.go @@ -244,88 +244,4 @@ metadata: Expect(*deployment.Spec.Replicas).To(Equal(int32(2))) }) }) - - Context("Kustomize functions", func() { - var ( - namespace *corev1.Namespace - kubeconfig *kustomizev1.KubeConfig - artifactFile string - artifactChecksum string - artifactURL string - kustomization *kustomizev1.Kustomization - ) - - BeforeEach(func() { - namespace = &corev1.Namespace{} - namespace.Name = "patch-" + randStringRunes(5) - Expect(k8sClient.Create(context.Background(), namespace)).To(Succeed()) - - kubecfgSecret, err := kubeConfigSecret() - Expect(err).ToNot(HaveOccurred()) - kubecfgSecret.Namespace = namespace.Name - Expect(k8sClient.Create(context.Background(), kubecfgSecret)).To(Succeed()) - kubeconfig = &kustomizev1.KubeConfig{ - SecretRef: meta.LocalObjectReference{ - Name: kubecfgSecret.Name, - }, - } - - artifactFile = "patch-" + randStringRunes(5) - artifactChecksum, err = initArtifact(artifactServer, "testdata/replacement", artifactFile) - Expect(err).ToNot(HaveOccurred()) - artifactURL, err = artifactServer.URLForFile(artifactFile) - Expect(err).ToNot(HaveOccurred()) - - gitRepoKey := client.ObjectKey{ - Name: fmt.Sprintf("patch-%s", randStringRunes(5)), - Namespace: namespace.Name, - } - gitRepo := readyGitRepository(gitRepoKey, artifactURL, "main/"+artifactChecksum, artifactChecksum) - Expect(k8sClient.Create(context.Background(), gitRepo)).To(Succeed()) - Expect(k8sClient.Status().Update(context.Background(), gitRepo)).To(Succeed()) - - kustomizationKey := types.NamespacedName{ - Name: "patch-" + randStringRunes(5), - Namespace: namespace.Name, - } - kustomization = &kustomizev1.Kustomization{ - ObjectMeta: metav1.ObjectMeta{ - Name: kustomizationKey.Name, - Namespace: kustomizationKey.Namespace, - }, - Spec: kustomizev1.KustomizationSpec{ - Path: "./", - KubeConfig: kubeconfig, - SourceRef: kustomizev1.CrossNamespaceSourceReference{ - Name: gitRepoKey.Name, - Namespace: gitRepoKey.Namespace, - Kind: sourcev1.GitRepositoryKind, - }, - TargetNamespace: namespace.Name, - }, - } - }) - - AfterEach(func() { - Expect(k8sClient.Delete(context.Background(), namespace)).To(Succeed()) - }) - - It("kustomize replacement transformer", func() { - Expect(k8sClient.Create(context.TODO(), kustomization)).To(Succeed()) - - Eventually(func() bool { - var obj kustomizev1.Kustomization - _ = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(kustomization), &obj) - return obj.Status.LastAppliedRevision == "main/"+artifactChecksum - }, timeout, time.Second).Should(BeTrue()) - - var quota corev1.ResourceQuota - Expect(k8sClient.Get(context.TODO(), client.ObjectKey{ - Name: "common", - Namespace: namespace.Name, - }, "a)).To(Succeed()) - val := quota.Spec.Hard[corev1.ResourceLimitsMemory] - Expect(val.String()).To(Equal("24Gi")) - }) - }) }) diff --git a/controllers/kustomization_controller_transformers_test.go b/controllers/kustomization_controller_transformers_test.go new file mode 100644 index 00000000..292aac96 --- /dev/null +++ b/controllers/kustomization_controller_transformers_test.go @@ -0,0 +1,376 @@ +/* +Copyright 2021 The Flux authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controllers + +import ( + "context" + "fmt" + "os" + "strings" + "time" + + sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/fluxcd/pkg/apis/meta" + "github.com/fluxcd/pkg/testserver" + + kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta1" +) + +var _ = Describe("KustomizationReconciler", func() { + var ( + artifactServer *testserver.ArtifactServer + ) + + BeforeEach(func() { + var err error + artifactServer, err = testserver.NewTempArtifactServer() + Expect(err).ToNot(HaveOccurred()) + artifactServer.Start() + }) + + AfterEach(func() { + artifactServer.Stop() + os.RemoveAll(artifactServer.Root()) + }) + + Context("Kustomize transformers", func() { + var ( + namespace *corev1.Namespace + kubeconfig *kustomizev1.KubeConfig + artifactFile string + artifactChecksum string + artifactURL string + kustomization *kustomizev1.Kustomization + deployNamespace *corev1.Namespace + ) + + BeforeEach(func() { + namespace = &corev1.Namespace{} + namespace.Name = "patch-" + randStringRunes(5) + Expect(k8sClient.Create(context.Background(), namespace)).To(Succeed()) + + deployNamespace = &corev1.Namespace{} + deployNamespace.Name = "deploy-system" + Expect(k8sClient.Create(context.Background(), deployNamespace)).To(Succeed()) + + kubecfgSecret, err := kubeConfigSecret() + Expect(err).ToNot(HaveOccurred()) + kubecfgSecret.Namespace = namespace.Name + Expect(k8sClient.Create(context.Background(), kubecfgSecret)).To(Succeed()) + kubeconfig = &kustomizev1.KubeConfig{ + SecretRef: meta.LocalObjectReference{ + Name: kubecfgSecret.Name, + }, + } + + artifactFile = "patch-" + randStringRunes(5) + artifactChecksum, err = initArtifact(artifactServer, "testdata/transformers", artifactFile) + Expect(err).ToNot(HaveOccurred()) + artifactURL, err = artifactServer.URLForFile(artifactFile) + Expect(err).ToNot(HaveOccurred()) + + gitRepoKey := client.ObjectKey{ + Name: fmt.Sprintf("patch-%s", randStringRunes(5)), + Namespace: namespace.Name, + } + gitRepo := readyGitRepository(gitRepoKey, artifactURL, "main/"+artifactChecksum, artifactChecksum) + Expect(k8sClient.Create(context.Background(), gitRepo)).To(Succeed()) + Expect(k8sClient.Status().Update(context.Background(), gitRepo)).To(Succeed()) + + kustomizationKey := types.NamespacedName{ + Name: "patch-" + randStringRunes(5), + Namespace: namespace.Name, + } + kustomization = &kustomizev1.Kustomization{ + ObjectMeta: metav1.ObjectMeta{ + Name: kustomizationKey.Name, + Namespace: kustomizationKey.Namespace, + }, + Spec: kustomizev1.KustomizationSpec{ + Path: "./", + KubeConfig: kubeconfig, + SourceRef: kustomizev1.CrossNamespaceSourceReference{ + Name: gitRepoKey.Name, + Namespace: gitRepoKey.Namespace, + Kind: sourcev1.GitRepositoryKind, + }, + }, + } + + Expect(k8sClient.Create(context.TODO(), kustomization)).To(Succeed()) + + Eventually(func() bool { + var obj kustomizev1.Kustomization + _ = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(kustomization), &obj) + return obj.Status.LastAppliedRevision == "main/"+artifactChecksum + }, timeout, time.Second).Should(BeTrue()) + + }) + + AfterEach(func() { + Expect(k8sClient.Delete(context.Background(), kustomization)).To(Succeed()) + Expect(k8sClient.Delete(context.Background(), deployNamespace)).To(Succeed()) + Expect(k8sClient.Delete(context.Background(), namespace)).To(Succeed()) + }) + + It("kustomize transformers", func() { + quota := &corev1.ResourceQuota{} + + By("namespace and prefix transformers", func() { + Expect(k8sClient.Get(context.TODO(), client.ObjectKey{ + Name: "test-common-transform", + Namespace: deployNamespace.Name, + }, quota)).To(Succeed()) + }) + + By("replacement transformer", func() { + val := quota.Spec.Hard[corev1.ResourceLimitsMemory] + Expect(val.String()).To(Equal("24Gi")) + }) + + By("annotations transformer", func() { + Expect(quota.Annotations["test"]).To(Equal("annotations")) + }) + + By("label transformer", func() { + Expect(quota.Labels["test"]).To(Equal("labels")) + }) + + By("configmap generator", func() { + var configMapList corev1.ConfigMapList + Expect(k8sClient.List(context.TODO(), &configMapList)).To(Succeed()) + Expect(checkConfigMap(&configMapList, "test-metas-transform")).To(Equal(true)) + }) + + By("secret generator", func() { + var secretList corev1.SecretList + Expect(k8sClient.List(context.TODO(), &secretList)).To(Succeed()) + Expect(checkSecret(&secretList, "test-secret-transform")).To(Equal(true)) + }) + + deployment := &appsv1.Deployment{} + Expect(k8sClient.Get(context.TODO(), types.NamespacedName{ + Name: "test-podinfo-transform", + Namespace: deployNamespace.Name, + }, deployment)).To(Succeed()) + + By("patch6902 transformer", func() { + Expect(deployment.Labels["patch"]).To(Equal("json6902")) + }) + + By("patches transformer", func() { + Expect(deployment.Labels["app.kubernetes.io/version"]).To(Equal("1.21.0")) + }) + + By("patchStrategicMerge transformer", func() { + Expect(deployment.Spec.Template.Spec.ServiceAccountName). + To(Equal("test")) + }) + + By("image transformer", func() { + Expect(deployment.Spec.Template.Spec.Containers[0].Image). + To(Equal("podinfo:6.0.0")) + }) + + By("replica transformer", func() { + Expect(int(*deployment.Spec.Replicas)). + To(Equal(2)) + }) + }) + }) + + Context("Kustomize file transformers", func() { + var ( + namespace *corev1.Namespace + kubeconfig *kustomizev1.KubeConfig + artifactFile string + artifactChecksum string + artifactURL string + kustomization *kustomizev1.Kustomization + deployNamespace *corev1.Namespace + ) + + BeforeEach(func() { + namespace = &corev1.Namespace{} + namespace.Name = "patch-" + randStringRunes(5) + Expect(k8sClient.Create(context.Background(), namespace)).To(Succeed()) + + deployNamespace = &corev1.Namespace{} + deployNamespace.Name = "second-system" + Expect(k8sClient.Create(context.Background(), deployNamespace)).To(Succeed()) + + kubecfgSecret, err := kubeConfigSecret() + Expect(err).ToNot(HaveOccurred()) + kubecfgSecret.Namespace = namespace.Name + Expect(k8sClient.Create(context.Background(), kubecfgSecret)).To(Succeed()) + kubeconfig = &kustomizev1.KubeConfig{ + SecretRef: meta.LocalObjectReference{ + Name: kubecfgSecret.Name, + }, + } + + artifactFile = "patch-" + randStringRunes(5) + artifactChecksum, err = initArtifact(artifactServer, "testdata/file-transformer", artifactFile) + Expect(err).ToNot(HaveOccurred()) + artifactURL, err = artifactServer.URLForFile(artifactFile) + Expect(err).ToNot(HaveOccurred()) + + gitRepoKey := client.ObjectKey{ + Name: fmt.Sprintf("patch-%s", randStringRunes(5)), + Namespace: namespace.Name, + } + gitRepo := readyGitRepository(gitRepoKey, artifactURL, "main/"+artifactChecksum, artifactChecksum) + Expect(k8sClient.Create(context.Background(), gitRepo)).To(Succeed()) + Expect(k8sClient.Status().Update(context.Background(), gitRepo)).To(Succeed()) + + kustomizationKey := types.NamespacedName{ + Name: "patch-" + randStringRunes(5), + Namespace: namespace.Name, + } + kustomization = &kustomizev1.Kustomization{ + ObjectMeta: metav1.ObjectMeta{ + Name: kustomizationKey.Name, + Namespace: kustomizationKey.Namespace, + }, + Spec: kustomizev1.KustomizationSpec{ + Path: "./", + KubeConfig: kubeconfig, + SourceRef: kustomizev1.CrossNamespaceSourceReference{ + Name: gitRepoKey.Name, + Namespace: gitRepoKey.Namespace, + Kind: sourcev1.GitRepositoryKind, + }, + }, + } + + Expect(k8sClient.Create(context.TODO(), kustomization)).To(Succeed()) + + Eventually(func() bool { + var obj kustomizev1.Kustomization + _ = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(kustomization), &obj) + return obj.Status.LastAppliedRevision == "main/"+artifactChecksum + }, timeout, time.Second).Should(BeTrue()) + + }) + + AfterEach(func() { + Expect(k8sClient.Delete(context.Background(), deployNamespace)).To(Succeed()) + Expect(k8sClient.Delete(context.Background(), namespace)).To(Succeed()) + }) + + It("kustomize file transformers", func() { + quota := &corev1.ResourceQuota{} + + By("namespace and prefix transformers", func() { + Expect(k8sClient.Get(context.TODO(), client.ObjectKey{ + Name: "test-common-transform", + Namespace: deployNamespace.Name, + }, quota)).To(Succeed()) + }) + + By("replacement transformer", func() { + val := quota.Spec.Hard[corev1.ResourceLimitsMemory] + Expect(val.String()).To(Equal("24Gi")) + }) + + By("annotations transformer", func() { + Expect(quota.Annotations["test"]).To(Equal("annotations")) + }) + + By("label transformer", func() { + Expect(quota.Labels["test"]).To(Equal("labels")) + }) + + By("configmap generator", func() { + var configMapList corev1.ConfigMapList + Expect(k8sClient.List(context.TODO(), &configMapList)).To(Succeed()) + Expect(checkConfigMap(&configMapList, "test-metas-transform")).To(Equal(true)) + }) + + By("secret generator", func() { + var secretList corev1.SecretList + Expect(k8sClient.List(context.TODO(), &secretList)).To(Succeed()) + Expect(checkSecret(&secretList, "test-secret-transform")).To(Equal(true)) + }) + + deployment := &appsv1.Deployment{} + Expect(k8sClient.Get(context.TODO(), types.NamespacedName{ + Name: "test-podinfo-transform", + Namespace: deployNamespace.Name, + }, deployment)).To(Succeed()) + + By("patch6902 transformer", func() { + Expect(deployment.Labels["patch"]).To(Equal("json6902")) + }) + + By("patches transformer", func() { + Expect(deployment.Labels["app.kubernetes.io/version"]).To(Equal("1.21.0")) + }) + + By("patchStrategicMerge transformer", func() { + Expect(deployment.Spec.Template.Spec.ServiceAccountName). + To(Equal("test")) + }) + + By("image transformer", func() { + Expect(deployment.Spec.Template.Spec.Containers[0].Image). + To(Equal("podinfo:6.0.0")) + }) + + By("replica transformer", func() { + Expect(int(*deployment.Spec.Replicas)). + To(Equal(2)) + }) + }) + }) +}) + +func checkConfigMap(list *corev1.ConfigMapList, name string) bool { + if list == nil { + return false + } + + for _, configMap := range list.Items { + if strings.Contains(configMap.Name, name) { + return true + } + } + + return false +} + +func checkSecret(list *corev1.SecretList, name string) bool { + if list == nil { + return false + } + + for _, secret := range list.Items { + if strings.Contains(secret.Name, name) { + return true + } + } + + return false +} diff --git a/controllers/testdata/file-transformer/annotation-transformer.yaml b/controllers/testdata/file-transformer/annotation-transformer.yaml new file mode 100644 index 00000000..abac25fc --- /dev/null +++ b/controllers/testdata/file-transformer/annotation-transformer.yaml @@ -0,0 +1,9 @@ +apiVersion: builtin +kind: AnnotationsTransformer +metadata: + name: notImportantHere +annotations: + test: annotations +fieldSpecs: + - path: metadata/annotations + create: true diff --git a/controllers/testdata/file-transformer/configmap-generator.yaml b/controllers/testdata/file-transformer/configmap-generator.yaml new file mode 100644 index 00000000..f9903362 --- /dev/null +++ b/controllers/testdata/file-transformer/configmap-generator.yaml @@ -0,0 +1,7 @@ +apiVersion: builtin +kind: ConfigMapGenerator +metadata: + name: metas +literals: + - limits.cpu=16 + - limits.memory=24Gi diff --git a/controllers/testdata/file-transformer/deployment.yaml b/controllers/testdata/file-transformer/deployment.yaml new file mode 100644 index 00000000..73eabc01 --- /dev/null +++ b/controllers/testdata/file-transformer/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podinfo + labels: + app: podinfo +spec: + replicas: 1 + selector: + matchLabels: + app: podinfo + template: + metadata: + labels: + app: podinfo + spec: + containers: + - name: podinfo + image: podinfo diff --git a/controllers/testdata/file-transformer/imagetag-transformer.yaml b/controllers/testdata/file-transformer/imagetag-transformer.yaml new file mode 100644 index 00000000..36dc27ec --- /dev/null +++ b/controllers/testdata/file-transformer/imagetag-transformer.yaml @@ -0,0 +1,9 @@ +apiVersion: builtin +kind: ImageTagTransformer +metadata: + name: notImportantHere +imageTag: + name: podinfo + newTag: 6.0.0 +fieldSpecs: + - path: spec/template/spec/containers[]/image diff --git a/controllers/testdata/file-transformer/kustomization.yaml b/controllers/testdata/file-transformer/kustomization.yaml new file mode 100644 index 00000000..14a81bb8 --- /dev/null +++ b/controllers/testdata/file-transformer/kustomization.yaml @@ -0,0 +1,21 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - quota.yaml + - deployment.yaml + +generators: + - configmap-generator.yaml + - secret-generator.yaml + +transformers: + - annotation-transformer.yaml + - label-transformer.yaml + - imagetag-transformer.yaml + - namespace-transformer.yaml + - patch-transformer.yaml + - patchjson6902-transformer.yaml + - patchStrategicMerge-transformer.yaml + - prefixsuffix-transformer.yaml + - replicas-transformer.yaml + - replacement-transformer.yaml diff --git a/controllers/testdata/file-transformer/label-transformer.yaml b/controllers/testdata/file-transformer/label-transformer.yaml new file mode 100644 index 00000000..ebe23ea3 --- /dev/null +++ b/controllers/testdata/file-transformer/label-transformer.yaml @@ -0,0 +1,15 @@ +apiVersion: builtin +kind: LabelTransformer +metadata: + name: notImportantHere +labels: + test: labels +fieldSpecs: + - path: metadata/labels + create: true + - path: spec/selector/matchLabels + create: true + kind: Deployment + - path: spec/template/metadata/labels + create: true + kind: Deployment diff --git a/controllers/testdata/file-transformer/namespace-transformer.yaml b/controllers/testdata/file-transformer/namespace-transformer.yaml new file mode 100644 index 00000000..e594bd1a --- /dev/null +++ b/controllers/testdata/file-transformer/namespace-transformer.yaml @@ -0,0 +1,8 @@ +apiVersion: builtin +kind: NamespaceTransformer +metadata: + name: notImportantHere + namespace: second-system +fieldSpecs: + - path: metadata/namespace + create: true diff --git a/controllers/testdata/file-transformer/patch-transformer.yaml b/controllers/testdata/file-transformer/patch-transformer.yaml new file mode 100644 index 00000000..4e1971e9 --- /dev/null +++ b/controllers/testdata/file-transformer/patch-transformer.yaml @@ -0,0 +1,5 @@ +apiVersion: builtin +kind: PatchTransformer +metadata: + name: notImportantHere +path: patch.yaml diff --git a/controllers/testdata/file-transformer/patch.yaml b/controllers/testdata/file-transformer/patch.yaml new file mode 100644 index 00000000..c36fcfd2 --- /dev/null +++ b/controllers/testdata/file-transformer/patch.yaml @@ -0,0 +1,6 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podinfo + labels: + app.kubernetes.io/version: 1.21.0 diff --git a/controllers/testdata/file-transformer/patchStrategicMerge-transformer.yaml b/controllers/testdata/file-transformer/patchStrategicMerge-transformer.yaml new file mode 100644 index 00000000..f7ce2a78 --- /dev/null +++ b/controllers/testdata/file-transformer/patchStrategicMerge-transformer.yaml @@ -0,0 +1,13 @@ +apiVersion: builtin +kind: PatchStrategicMergeTransformer +metadata: + name: notImportantHere +patches: |- + apiVersion: apps/v1 + kind: Deployment + metadata: + name: podinfo + spec: + template: + spec: + serviceAccountName: test diff --git a/controllers/testdata/file-transformer/patchjson6902-transformer.yaml b/controllers/testdata/file-transformer/patchjson6902-transformer.yaml new file mode 100644 index 00000000..7d2bdcae --- /dev/null +++ b/controllers/testdata/file-transformer/patchjson6902-transformer.yaml @@ -0,0 +1,10 @@ +apiVersion: builtin +kind: PatchJson6902Transformer +metadata: + name: notImportantHere +target: + group: apps + version: v1 + kind: Deployment + name: podinfo +jsonOp: '[{"op": "add", "path": "/metadata/labels/patch", "value": "json6902"}]' diff --git a/controllers/testdata/file-transformer/prefixsuffix-transformer.yaml b/controllers/testdata/file-transformer/prefixsuffix-transformer.yaml new file mode 100644 index 00000000..5778dcb2 --- /dev/null +++ b/controllers/testdata/file-transformer/prefixsuffix-transformer.yaml @@ -0,0 +1,8 @@ +apiVersion: builtin +kind: PrefixSuffixTransformer +metadata: + name: notImportantHere +prefix: test- +suffix: -transform +fieldSpecs: + - path: metadata/name diff --git a/controllers/testdata/replacement/quota.yaml b/controllers/testdata/file-transformer/quota.yaml similarity index 100% rename from controllers/testdata/replacement/quota.yaml rename to controllers/testdata/file-transformer/quota.yaml diff --git a/controllers/testdata/replacement/kustomization.yaml b/controllers/testdata/file-transformer/replacement-transformer.yaml similarity index 53% rename from controllers/testdata/replacement/kustomization.yaml rename to controllers/testdata/file-transformer/replacement-transformer.yaml index faf05ebc..7188b4a6 100644 --- a/controllers/testdata/replacement/kustomization.yaml +++ b/controllers/testdata/file-transformer/replacement-transformer.yaml @@ -1,15 +1,7 @@ -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: - - quota.yaml - -namespace: integrations -configMapGenerator: - - name: metas - literals: - - limits.cpu=16 - - limits.memory=24Gi - +apiVersion: builtin +kind: ReplacementTransformer +metadata: + name: notImportantHere replacements: - source: kind: ConfigMap diff --git a/controllers/testdata/file-transformer/replicas-transformer.yaml b/controllers/testdata/file-transformer/replicas-transformer.yaml new file mode 100644 index 00000000..211b15c4 --- /dev/null +++ b/controllers/testdata/file-transformer/replicas-transformer.yaml @@ -0,0 +1,20 @@ +apiVersion: builtin +kind: ReplicaCountTransformer +metadata: + name: notImportantHere +replica: + count: 2 + name: podinfo +fieldSpecs: + - path: spec/replicas + create: true + kind: Deployment + - path: spec/replicas + create: true + kind: ReplicationController + - path: spec/replicas + create: true + kind: ReplicaSet + - path: spec/replicas + create: true + kind: StatefulSet diff --git a/controllers/testdata/file-transformer/secret-generator.yaml b/controllers/testdata/file-transformer/secret-generator.yaml new file mode 100644 index 00000000..a11e4a78 --- /dev/null +++ b/controllers/testdata/file-transformer/secret-generator.yaml @@ -0,0 +1,7 @@ +apiVersion: builtin +kind: SecretGenerator +metadata: + name: secret +literals: + - username=admin + - password=password diff --git a/controllers/testdata/transformers/deployment.yaml b/controllers/testdata/transformers/deployment.yaml new file mode 100644 index 00000000..73eabc01 --- /dev/null +++ b/controllers/testdata/transformers/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podinfo + labels: + app: podinfo +spec: + replicas: 1 + selector: + matchLabels: + app: podinfo + template: + metadata: + labels: + app: podinfo + spec: + containers: + - name: podinfo + image: podinfo diff --git a/controllers/testdata/transformers/kustomization.yaml b/controllers/testdata/transformers/kustomization.yaml new file mode 100644 index 00000000..b9f6a682 --- /dev/null +++ b/controllers/testdata/transformers/kustomization.yaml @@ -0,0 +1,77 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - quota.yaml + - deployment.yaml + +namespace: deploy-system + +namePrefix: test- + +nameSuffix: -transform + +commonAnnotations: + test: annotations + +commonLabels: + test: labels + +images: + - name: podinfo + newTag: 6.0.0 + +replicas: + - name: podinfo + count: 2 + +configMapGenerator: + - name: metas + literals: + - limits.cpu=16 + - limits.memory=24Gi + +secretGenerator: + - name: secret + literals: + - username=admin + - password=password + +patchesStrategicMerge: + - |- + apiVersion: apps/v1 + kind: Deployment + metadata: + name: podinfo + spec: + template: + spec: + serviceAccountName: test + +patchesJson6902: + - target: + version: v1 + kind: Deployment + name: podinfo + patch: |- + - op: add + path: /metadata/labels/patch + value: json6902 + +patches: + - path: patch.yaml + target: + kind: Deployment + name: podinfo + + +replacements: + - source: + kind: ConfigMap + name: metas + fieldPath: data.[limits.memory] + targets: + - select: + name: common + kind: ResourceQuota + fieldPaths: + - spec.hard.[limits.memory] diff --git a/controllers/testdata/transformers/patch.yaml b/controllers/testdata/transformers/patch.yaml new file mode 100644 index 00000000..f9f8e864 --- /dev/null +++ b/controllers/testdata/transformers/patch.yaml @@ -0,0 +1,6 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podinfo + labels: + app.kubernetes.io/version: 1.21.0 \ No newline at end of file diff --git a/controllers/testdata/transformers/quota.yaml b/controllers/testdata/transformers/quota.yaml new file mode 100644 index 00000000..9cc0c624 --- /dev/null +++ b/controllers/testdata/transformers/quota.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ResourceQuota +metadata: + name: common + namespace: $NAMESPACE +spec: + hard: + limits.cpu: "1" + limits.memory: "1Gi" + resourcequotas: "1"