From 8ba8201b537510e7486cca5d382697ef2896b13e Mon Sep 17 00:00:00 2001 From: Sebastian Diez Date: Wed, 26 Jun 2024 09:06:06 +0200 Subject: [PATCH 1/3] feat: Support wait for StatefulSet --- docs/resources/resource.md | 4 +- kustomize/manifest.go | 37 +++++- kustomize/resource_kustomization_test.go | 118 +++++++++++++++++- .../nowait/initial/kustomization.yaml | 1 + .../nowait/initial/statefulset.yaml | 19 +++ .../nowait/modified/kustomization.yaml | 8 ++ .../wait-change/initial/kustomization.yaml | 1 + .../wait-change/initial/statefulset.yaml | 19 +++ .../initial/kustomization.yaml | 8 ++ .../initial/namespace.yaml | 4 + .../initial/statefulset.yaml | 19 +++ .../wait/initial/kustomization.yaml | 1 + .../wait/initial/statefulset.yaml | 19 +++ .../wait/modified/kustomization.yaml | 8 ++ 14 files changed, 257 insertions(+), 9 deletions(-) create mode 100644 kustomize/test_kustomizations/nowait/initial/statefulset.yaml create mode 100644 kustomize/test_kustomizations/wait-change/initial/statefulset.yaml create mode 100644 kustomize/test_kustomizations/wait-fail-statefulset/initial/kustomization.yaml create mode 100644 kustomize/test_kustomizations/wait-fail-statefulset/initial/namespace.yaml create mode 100644 kustomize/test_kustomizations/wait-fail-statefulset/initial/statefulset.yaml create mode 100644 kustomize/test_kustomizations/wait/initial/statefulset.yaml diff --git a/docs/resources/resource.md b/docs/resources/resource.md index f3c7165..6a4fcb5 100644 --- a/docs/resources/resource.md +++ b/docs/resources/resource.md @@ -68,7 +68,7 @@ resource "kustomization_resource" "p0" { # then loop through resources in ids_prio[1] # and set an explicit depends_on on kustomization_resource.p0 -# wait 2 minutes for any deployment or daemonset to become ready +# wait 2 minutes for any deployment, statefulset or daemonset to become ready resource "kustomization_resource" "p1" { for_each = data.kustomization_build.test.ids_prio[1] @@ -105,5 +105,5 @@ resource "kustomization_resource" "p2" { ## Argument Reference - `manifest` - (Required) JSON encoded Kubernetes resource manifest. -- `wait` - Whether to wait for pods to become ready (default false). Currently only has an effect for Deployments and DaemonSets. +- `wait` - Whether to wait for pods to become ready (default false). Currently only has an effect for Deployments, StatefulSets and DaemonSets. - 'timeouts' - (Optional) Overwrite `create`, `update` or `delete` timeout defaults. Defaults are 5 minutes for `create` and `update` and 10 minutes for `delete`. diff --git a/kustomize/manifest.go b/kustomize/manifest.go index 31765da..043713a 100644 --- a/kustomize/manifest.go +++ b/kustomize/manifest.go @@ -23,8 +23,9 @@ import ( ) var waitRefreshFunctions = map[string]waitRefreshFunction{ - "apps/Deployment": waitDeploymentRefresh, - "apps/Daemonset": waitDaemonsetRefresh, + "apps/Deployment": waitDeploymentRefresh, + "apps/Daemonset": waitDaemonsetRefresh, + "apps/StatefulSet": waitStatefulSetRefresh, } type kManifestId struct { @@ -429,6 +430,38 @@ func waitDeploymentRefresh(km *kManifest) (interface{}, string, error) { return nil, "in progress", nil } +func statefulSetReady(u *k8sunstructured.Unstructured) (bool, error) { + var statefulSet k8sappsv1.StatefulSet + if err := k8sruntime.DefaultUnstructuredConverter.FromUnstructured(u.UnstructuredContent(), &statefulSet); err != nil { + return false, err + } + if statefulSet.Generation == statefulSet.Status.ObservedGeneration && + statefulSet.Status.AvailableReplicas == *statefulSet.Spec.Replicas && + statefulSet.Status.AvailableReplicas == statefulSet.Status.Replicas { + return true, nil + } else { + return false, nil + } +} + +func waitStatefulSetRefresh(km *kManifest) (interface{}, string, error) { + resp, err := km.apiGet(k8smetav1.GetOptions{}) + if err != nil { + if k8serrors.IsNotFound(err) { + return nil, "missing", nil + } + return nil, "error", err + } + ready, err := statefulSetReady(resp) + if err != nil { + return nil, "error", err + } + if ready { + return resp, "done", nil + } + return nil, "in progress", nil +} + func (km *kManifest) waitCreatedOrUpdated(t time.Duration) error { gvk := km.gvk() if refresh, ok := waitRefreshFunctions[fmt.Sprintf("%s/%s", gvk.Group, gvk.Kind)]; ok { diff --git a/kustomize/resource_kustomization_test.go b/kustomize/resource_kustomization_test.go index f851856..71c0e41 100644 --- a/kustomize/resource_kustomization_test.go +++ b/kustomize/resource_kustomization_test.go @@ -483,24 +483,26 @@ func TestAccResourceKustomization_wait(t *testing.T) { Steps: []resource.TestStep{ // // - // Applying initial config with a svc and deployment in a namespace with wait + // Applying initial config with a deployment and statefulset in a namespace with wait { Config: testAccResourceKustomizationConfig_wait("test_kustomizations/wait/initial"), Check: resource.ComposeAggregateTestCheckFunc( assertDurationIsShorterThan(now, 5*time.Minute), testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), testAccCheckDeploymentReady("kustomization_resource.dep1", "test-wait", "test"), + testAccCheckStatefulSetReady("kustomization_resource.state1", "test-wait", "test-statefulset"), ), }, // // - // Applying modified config updating the deployment annotation with wait + // Applying modified config updating the deployment and statefulset annotation with wait { Config: testAccResourceKustomizationConfig_wait("test_kustomizations/wait/modified"), Check: resource.ComposeAggregateTestCheckFunc( assertDurationIsShorterThan(now, 1*time.Minute), testAccCheckManifestNestedString("kustomization_resource.dep1", "this will cause a redeploy", "spec", "template", "metadata", "annotations", "new"), testAccCheckDeploymentReady("kustomization_resource.dep1", "test-wait", "test"), + testAccCheckStatefulSetReady("kustomization_resource.state1", "test-wait", "test-statefulset"), ), }, }, @@ -520,6 +522,14 @@ resource "kustomization_resource" "dep1" { update = "1m" } } +resource "kustomization_resource" "state1" { + manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-wait/test-statefulset"] + wait = true + timeouts { + create = "1m" + update = "1m" + } +} ` } @@ -548,6 +558,7 @@ func TestAccResourceKustomization_add_wait(t *testing.T) { assertDurationIsShorterThan(now, 1*time.Minute), testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), testAccCheckDeploymentReady("kustomization_resource.dep1", "test-wait-change", "test"), + testAccCheckStatefulSetReady("kustomization_resource.state1", "test-wait-change", "test-statefulset"), ), }, }, @@ -562,6 +573,9 @@ resource "kustomization_resource" "ns" { resource "kustomization_resource" "dep1" { manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait-change/test"] } +resource "kustomization_resource" "state1" { + manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-wait-change/test-statefulset"] +} ` } @@ -578,6 +592,14 @@ resource "kustomization_resource" "dep1" { update = "1m" } } +resource "kustomization_resource" "state1" { + manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-wait-change/test-statefulset"] + wait = true + timeouts { + create = "1m" + update = "1m" + } +} ` } @@ -618,7 +640,8 @@ resource "kustomization_resource" "dep1" { ` } -func TestAccResourceKustomization_nowait(t *testing.T) { +func TestAccResourceKustomization_wait_failure_statefulset(t *testing.T) { + now := time.Now() resource.Test(t, resource.TestCase{ //PreCheck: func() { testAccPreCheck(t) }, @@ -626,24 +649,62 @@ func TestAccResourceKustomization_nowait(t *testing.T) { Steps: []resource.TestStep{ // // - // Applying initial config with a svc and deployment in a namespace without wait + // Applying initial config with a failing statefulset in a namespace with wait + { + Config: testAccResourceKustomizationConfig_wait_failure_statefulset("test_kustomizations/wait-fail-statefulset/initial"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckStatefulSetNotReady("kustomization_resource.state1", "test-wait-fail-statefulset", "test-statefulset"), + assertDurationIsLongerThan(now, 1*time.Minute), + ), + ExpectError: regexp.MustCompile("timed out creating/updating StatefulSet test-wait-fail-statefulset/test-statefulset:"), + }, + }, + }) +} + +func testAccResourceKustomizationConfig_wait_failure_statefulset(path string) string { + return testAccDataSourceKustomizationConfig_basic(path) + ` +resource "kustomization_resource" "ns" { + manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-fail-statefulset"] +} +resource "kustomization_resource" "state1" { + manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-wait-fail-statefulset/test-statefulset"] + wait = true + timeouts { + create = "1m" + } +} +` +} + +func TestAccResourceKustomization_nowait(t *testing.T) { + resource.Test(t, resource.TestCase{ + //PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + // + // + // Applying initial config with a svc and deployment and statefulset in a namespace without wait // so shouldn't exist immediately after creation { Config: testAccResourceKustomizationConfig_nowait("test_kustomizations/nowait/initial"), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), testAccCheckDeploymentNotReady("kustomization_resource.dep1", "test-nowait", "test"), + testAccCheckStatefulSetNotReady("kustomization_resource.state1", "test-nowait", "test-statefulset"), ), }, // // - // Applying modified config updating the deployment annotation without wait, + // Applying modified config updating the deployment and statefulset annotation without wait, // so we don't immediately expect the annotation to be present { Config: testAccResourceKustomizationConfig_nowait("test_kustomizations/nowait/modified"), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckManifestNestedString("kustomization_resource.dep1", "this will cause a redeploy", "spec", "template", "metadata", "annotations", "new"), testAccCheckDeploymentNotReady("kustomization_resource.dep1", "test-nowait", "test"), + testAccCheckManifestNestedString("kustomization_resource.state1", "this will cause statefulset to redeploy", "spec", "template", "metadata", "annotations", "new"), + testAccCheckStatefulSetNotReady("kustomization_resource.state1", "test-nowait", "test-statefulset"), ), }, }, @@ -659,6 +720,9 @@ resource "kustomization_resource" "ns" { resource "kustomization_resource" "dep1" { manifest = data.kustomization_build.test.manifests["apps/Deployment/test-nowait/test"] } +resource "kustomization_resource" "state1" { + manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-nowait/test-statefulset"] +} ` } @@ -1122,6 +1186,50 @@ func testAccCheckDeploymentNotReady(n string, namespace string, name string) res } } +func testAccCheckStatefulSetReady(n string, namespace string, name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + u, err := getResourceFromTestState(s, n) + if err != nil { + return err + } + + resp, err := getResourceFromK8sAPI(u) + if err != nil { + return err + } + ready, err := statefulSetReady(resp) + if err != nil { + return err + } + if !ready { + return fmt.Errorf("statefulset %s in %s not ready", name, namespace) + } + return nil + } +} + +func testAccCheckStatefulSetNotReady(n string, namespace string, name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + u, err := getResourceFromTestState(s, n) + if err != nil { + return err + } + + resp, err := getResourceFromK8sAPI(u) + if err != nil { + return err + } + ready, err := statefulSetReady(resp) + if err != nil { + return err + } + if ready { + return fmt.Errorf("statefulset %s in %s unexpectedly ready", name, namespace) + } + return nil + } +} + func getResourceFromTestState(s *terraform.State, n string) (ur *k8sunstructured.Unstructured, err error) { rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/kustomize/test_kustomizations/nowait/initial/kustomization.yaml b/kustomize/test_kustomizations/nowait/initial/kustomization.yaml index 70bbbaa..3c73f81 100644 --- a/kustomize/test_kustomizations/nowait/initial/kustomization.yaml +++ b/kustomize/test_kustomizations/nowait/initial/kustomization.yaml @@ -5,4 +5,5 @@ namespace: test-nowait resources: - namespace.yaml +- statefulset.yaml - ../../_example_app diff --git a/kustomize/test_kustomizations/nowait/initial/statefulset.yaml b/kustomize/test_kustomizations/nowait/initial/statefulset.yaml new file mode 100644 index 0000000..bcd47b0 --- /dev/null +++ b/kustomize/test_kustomizations/nowait/initial/statefulset.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + labels: + app: test-statefulset + name: test-statefulset +spec: + replicas: 1 + selector: + matchLabels: + app: test-statefulset + template: + metadata: + labels: + app: test-statefulset + spec: + containers: + - image: nginx + name: nginx diff --git a/kustomize/test_kustomizations/nowait/modified/kustomization.yaml b/kustomize/test_kustomizations/nowait/modified/kustomization.yaml index e22a366..d34b12a 100644 --- a/kustomize/test_kustomizations/nowait/modified/kustomization.yaml +++ b/kustomize/test_kustomizations/nowait/modified/kustomization.yaml @@ -13,3 +13,11 @@ patches: path: /spec/template/metadata/annotations value: new: this will cause a redeploy + - target: + kind: StatefulSet + name: test-statefulset + patch: | + - op: add + path: /spec/template/metadata/annotations + value: + new: this will cause statefulset to redeploy diff --git a/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml b/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml index 004c561..5c12aca 100644 --- a/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml +++ b/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml @@ -5,4 +5,5 @@ namespace: test-wait-change resources: - namespace.yaml +- statefulset.yaml - ../../_example_app diff --git a/kustomize/test_kustomizations/wait-change/initial/statefulset.yaml b/kustomize/test_kustomizations/wait-change/initial/statefulset.yaml new file mode 100644 index 0000000..bcd47b0 --- /dev/null +++ b/kustomize/test_kustomizations/wait-change/initial/statefulset.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + labels: + app: test-statefulset + name: test-statefulset +spec: + replicas: 1 + selector: + matchLabels: + app: test-statefulset + template: + metadata: + labels: + app: test-statefulset + spec: + containers: + - image: nginx + name: nginx diff --git a/kustomize/test_kustomizations/wait-fail-statefulset/initial/kustomization.yaml b/kustomize/test_kustomizations/wait-fail-statefulset/initial/kustomization.yaml new file mode 100644 index 0000000..f3ccbbd --- /dev/null +++ b/kustomize/test_kustomizations/wait-fail-statefulset/initial/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: test-wait-fail-statefulset + +resources: +- namespace.yaml +- statefulset.yaml diff --git a/kustomize/test_kustomizations/wait-fail-statefulset/initial/namespace.yaml b/kustomize/test_kustomizations/wait-fail-statefulset/initial/namespace.yaml new file mode 100644 index 0000000..41adcb3 --- /dev/null +++ b/kustomize/test_kustomizations/wait-fail-statefulset/initial/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: test-wait-fail-statefulset diff --git a/kustomize/test_kustomizations/wait-fail-statefulset/initial/statefulset.yaml b/kustomize/test_kustomizations/wait-fail-statefulset/initial/statefulset.yaml new file mode 100644 index 0000000..2792fb2 --- /dev/null +++ b/kustomize/test_kustomizations/wait-fail-statefulset/initial/statefulset.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + labels: + app: test-statefulset + name: test-statefulset +spec: + replicas: 1 + selector: + matchLabels: + app: test-statefulset + template: + metadata: + labels: + app: test-statefulset + spec: + containers: + - image: doesnotexist/definitelydoesntexist + name: willfail diff --git a/kustomize/test_kustomizations/wait/initial/kustomization.yaml b/kustomize/test_kustomizations/wait/initial/kustomization.yaml index 7428808..e0e85c3 100644 --- a/kustomize/test_kustomizations/wait/initial/kustomization.yaml +++ b/kustomize/test_kustomizations/wait/initial/kustomization.yaml @@ -5,4 +5,5 @@ namespace: test-wait resources: - namespace.yaml +- statefulset.yaml - ../../_example_app diff --git a/kustomize/test_kustomizations/wait/initial/statefulset.yaml b/kustomize/test_kustomizations/wait/initial/statefulset.yaml new file mode 100644 index 0000000..bcd47b0 --- /dev/null +++ b/kustomize/test_kustomizations/wait/initial/statefulset.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + labels: + app: test-statefulset + name: test-statefulset +spec: + replicas: 1 + selector: + matchLabels: + app: test-statefulset + template: + metadata: + labels: + app: test-statefulset + spec: + containers: + - image: nginx + name: nginx diff --git a/kustomize/test_kustomizations/wait/modified/kustomization.yaml b/kustomize/test_kustomizations/wait/modified/kustomization.yaml index e22a366..b82f37a 100644 --- a/kustomize/test_kustomizations/wait/modified/kustomization.yaml +++ b/kustomize/test_kustomizations/wait/modified/kustomization.yaml @@ -13,3 +13,11 @@ patches: path: /spec/template/metadata/annotations value: new: this will cause a redeploy + - target: + kind: StatefulSet + name: test-statefulset + patch: | + - op: add + path: /spec/template/metadata/annotations + value: + new: this will cause a redeploy From ea02f51f3c5083d8b39e2c4b71b715e94a305e48 Mon Sep 17 00:00:00 2001 From: Sebastian Diez Date: Wed, 26 Jun 2024 09:57:30 +0200 Subject: [PATCH 2/3] fix: Typo in DaemonSet wait function mapping If wait is configured, terraform should now wait for a DaemonSet to become ready --- kustomize/manifest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kustomize/manifest.go b/kustomize/manifest.go index 043713a..37e9939 100644 --- a/kustomize/manifest.go +++ b/kustomize/manifest.go @@ -24,7 +24,7 @@ import ( var waitRefreshFunctions = map[string]waitRefreshFunction{ "apps/Deployment": waitDeploymentRefresh, - "apps/Daemonset": waitDaemonsetRefresh, + "apps/DaemonSet": waitDaemonsetRefresh, "apps/StatefulSet": waitStatefulSetRefresh, } From 2b9c32b5027a88a6db8e9908c3aaf5f5d6fd8c80 Mon Sep 17 00:00:00 2001 From: Sebastian Diez Date: Wed, 26 Jun 2024 11:00:34 +0200 Subject: [PATCH 3/3] chore: Refactor test for wait functionality - Test all supported resources separatly - Test DaemonSet resource --- kustomize/resource_kustomization_test.go | 374 +++++++----------- .../nowait/initial/daemonset.yaml | 18 + .../nowait/initial/kustomization.yaml | 1 + .../nowait/initial/statefulset.yaml | 8 +- .../nowait/modified/kustomization.yaml | 12 +- .../wait-change/initial/daemonset.yaml | 18 + .../wait-change/initial/kustomization.yaml | 1 + .../wait-change/initial/statefulset.yaml | 8 +- .../initial/kustomization.yaml | 8 - .../initial/namespace.yaml | 4 - .../initial/statefulset.yaml | 19 - .../wait-fail/initial/daemonset.yaml | 18 + .../wait-fail/initial/kustomization.yaml | 2 + .../wait-fail/initial/statefulset.yaml | 19 + .../wait/initial/daemonset.yaml | 18 + .../wait/initial/kustomization.yaml | 1 + .../wait/initial/statefulset.yaml | 8 +- .../wait/modified/kustomization.yaml | 10 +- 18 files changed, 261 insertions(+), 286 deletions(-) create mode 100644 kustomize/test_kustomizations/nowait/initial/daemonset.yaml create mode 100644 kustomize/test_kustomizations/wait-change/initial/daemonset.yaml delete mode 100644 kustomize/test_kustomizations/wait-fail-statefulset/initial/kustomization.yaml delete mode 100644 kustomize/test_kustomizations/wait-fail-statefulset/initial/namespace.yaml delete mode 100644 kustomize/test_kustomizations/wait-fail-statefulset/initial/statefulset.yaml create mode 100644 kustomize/test_kustomizations/wait-fail/initial/daemonset.yaml create mode 100644 kustomize/test_kustomizations/wait-fail/initial/statefulset.yaml create mode 100644 kustomize/test_kustomizations/wait/initial/daemonset.yaml diff --git a/kustomize/resource_kustomization_test.go b/kustomize/resource_kustomization_test.go index 71c0e41..0786600 100644 --- a/kustomize/resource_kustomization_test.go +++ b/kustomize/resource_kustomization_test.go @@ -475,255 +475,187 @@ resource "kustomization_resource" "scprov" { ` } +type readyCheckFunc func(u *k8sunstructured.Unstructured) (bool, error) + +var waitSupportedResources = map[string]readyCheckFunc{ + "Deployment": deploymentReady, + "DaemonSet": daemonsetReady, + "StatefulSet": statefulSetReady, +} + func TestAccResourceKustomization_wait(t *testing.T) { - now := time.Now() - resource.Test(t, resource.TestCase{ - //PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - // - // - // Applying initial config with a deployment and statefulset in a namespace with wait - { - Config: testAccResourceKustomizationConfig_wait("test_kustomizations/wait/initial"), - Check: resource.ComposeAggregateTestCheckFunc( - assertDurationIsShorterThan(now, 5*time.Minute), - testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), - testAccCheckDeploymentReady("kustomization_resource.dep1", "test-wait", "test"), - testAccCheckStatefulSetReady("kustomization_resource.state1", "test-wait", "test-statefulset"), - ), - }, - // - // - // Applying modified config updating the deployment and statefulset annotation with wait - { - Config: testAccResourceKustomizationConfig_wait("test_kustomizations/wait/modified"), - Check: resource.ComposeAggregateTestCheckFunc( - assertDurationIsShorterThan(now, 1*time.Minute), - testAccCheckManifestNestedString("kustomization_resource.dep1", "this will cause a redeploy", "spec", "template", "metadata", "annotations", "new"), - testAccCheckDeploymentReady("kustomization_resource.dep1", "test-wait", "test"), - testAccCheckStatefulSetReady("kustomization_resource.state1", "test-wait", "test-statefulset"), - ), + for kind, readyCheck := range waitSupportedResources { + now := time.Now() + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Applying initial config with wait + { + Config: testAccResourceKustomizationConfig_wait("test_kustomizations/wait/initial", kind), + Check: resource.ComposeAggregateTestCheckFunc( + assertDurationIsShorterThan(now, 5*time.Minute), + testAccCheckManifestNestedString("kustomization_resource.dep", "test", "spec", "selector", "matchLabels", "app"), + testAccCheckResourceReady("kustomization_resource.dep", "test-wait", "test", kind, readyCheck), + ), + }, + // Applying modified config updating the deployment annotation with wait + { + Config: testAccResourceKustomizationConfig_wait("test_kustomizations/wait/modified", kind), + Check: resource.ComposeAggregateTestCheckFunc( + assertDurationIsShorterThan(now, 1*time.Minute), + testAccCheckManifestNestedString("kustomization_resource.dep", "this will cause a redeploy", "spec", "template", "metadata", "annotations", "new"), + testAccCheckResourceReady("kustomization_resource.dep", "test-wait", "test", kind, readyCheck), + ), + }, }, - }, - }) + }) + } } -func testAccResourceKustomizationConfig_wait(path string) string { - return testAccDataSourceKustomizationConfig_basic(path) + ` +func testAccResourceKustomizationConfig_wait(path string, kind string) string { + return testAccDataSourceKustomizationConfig_basic(path) + fmt.Sprintf(` resource "kustomization_resource" "ns" { manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait"] } -resource "kustomization_resource" "dep1" { - manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait/test"] - wait = true - timeouts { - create = "1m" - update = "1m" - } -} -resource "kustomization_resource" "state1" { - manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-wait/test-statefulset"] +resource "kustomization_resource" "dep" { + manifest = data.kustomization_build.test.manifests["apps/%s/test-wait/test"] wait = true timeouts { create = "1m" update = "1m" } } -` +`, kind) } func TestAccResourceKustomization_add_wait(t *testing.T) { - now := time.Now() - resource.Test(t, resource.TestCase{ - //PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - // - // - // Applying initial config with a svc and deployment in a namespace with no wait - { - Config: testAccResourceKustomizationConfig_wait_off("test_kustomizations/wait-change/initial"), - Check: resource.ComposeAggregateTestCheckFunc( - assertDurationIsShorterThan(now, 5*time.Minute), - testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), - ), - }, - // - // - // Applying exactly the same configuration, but with wait turned on - { - Config: testAccResourceKustomizationConfig_wait_on("test_kustomizations/wait-change/initial"), - Check: resource.ComposeAggregateTestCheckFunc( - assertDurationIsShorterThan(now, 1*time.Minute), - testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), - testAccCheckDeploymentReady("kustomization_resource.dep1", "test-wait-change", "test"), - testAccCheckStatefulSetReady("kustomization_resource.state1", "test-wait-change", "test-statefulset"), - ), + for kind, readyCheck := range waitSupportedResources { + now := time.Now() + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Applying initial config with no wait + { + Config: testAccResourceKustomizationConfig_wait_off("test_kustomizations/wait-change/initial", kind), + Check: resource.ComposeAggregateTestCheckFunc( + assertDurationIsShorterThan(now, 5*time.Minute), + testAccCheckManifestNestedString("kustomization_resource.dep", "test", "spec", "selector", "matchLabels", "app"), + ), + }, + // Applying exactly the same configuration, but with wait turned on + { + Config: testAccResourceKustomizationConfig_wait_on("test_kustomizations/wait-change/initial", kind), + Check: resource.ComposeAggregateTestCheckFunc( + assertDurationIsShorterThan(now, 1*time.Minute), + testAccCheckManifestNestedString("kustomization_resource.dep", "test", "spec", "selector", "matchLabels", "app"), + testAccCheckResourceReady("kustomization_resource.dep", "test-wait-change", "test", kind, readyCheck), + ), + }, }, - }, - }) + }) + } } -func testAccResourceKustomizationConfig_wait_off(path string) string { - return testAccDataSourceKustomizationConfig_basic(path) + ` +func testAccResourceKustomizationConfig_wait_off(path string, kind string) string { + return testAccDataSourceKustomizationConfig_basic(path) + fmt.Sprintf(` resource "kustomization_resource" "ns" { manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-change"] } -resource "kustomization_resource" "dep1" { - manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait-change/test"] +resource "kustomization_resource" "dep" { + manifest = data.kustomization_build.test.manifests["apps/%s/test-wait-change/test"] } -resource "kustomization_resource" "state1" { - manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-wait-change/test-statefulset"] -} -` +`, kind) } -func testAccResourceKustomizationConfig_wait_on(path string) string { - return testAccDataSourceKustomizationConfig_basic(path) + ` +func testAccResourceKustomizationConfig_wait_on(path string, kind string) string { + return testAccDataSourceKustomizationConfig_basic(path) + fmt.Sprintf(` resource "kustomization_resource" "ns" { manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-change"] } -resource "kustomization_resource" "dep1" { - manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait-change/test"] - wait = true - timeouts { - create = "1m" - update = "1m" - } -} -resource "kustomization_resource" "state1" { - manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-wait-change/test-statefulset"] +resource "kustomization_resource" "dep" { + manifest = data.kustomization_build.test.manifests["apps/%s/test-wait-change/test"] wait = true timeouts { create = "1m" update = "1m" } } -` +`, kind) } func TestAccResourceKustomization_wait_failure(t *testing.T) { - now := time.Now() - - resource.Test(t, resource.TestCase{ - //PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - // - // - // Applying initial config with a svc and a failing deployment in a namespace with wait - { - Config: testAccResourceKustomizationConfig_wait_failure("test_kustomizations/wait-fail/initial"), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckDeploymentNotReady("kustomization_resource.dep1", "test-wait-fail", "test"), - assertDurationIsLongerThan(now, 1*time.Minute), - ), - ExpectError: regexp.MustCompile("timed out creating/updating Deployment test-wait-fail/test:"), + for kind, readyCheck := range waitSupportedResources { + now := time.Now() + + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Applying initial config with a failing deployment with wait + { + Config: testAccResourceKustomizationConfig_wait_failure("test_kustomizations/wait-fail/initial", kind), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckResourceNotReady("kustomization_resource.dep", "test-wait-fail", "test", kind, readyCheck), + assertDurationIsLongerThan(now, 1*time.Minute), + ), + ExpectError: regexp.MustCompile(fmt.Sprintf("timed out creating/updating %s test-wait-fail/test:", kind)), + }, }, - }, - }) -} - -func testAccResourceKustomizationConfig_wait_failure(path string) string { - return testAccDataSourceKustomizationConfig_basic(path) + ` -resource "kustomization_resource" "ns" { - manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-fail"] -} -resource "kustomization_resource" "dep1" { - manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait-fail/test"] - wait = true - timeouts { - create = "1m" + }) } } -` -} -func TestAccResourceKustomization_wait_failure_statefulset(t *testing.T) { - now := time.Now() - - resource.Test(t, resource.TestCase{ - //PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - // - // - // Applying initial config with a failing statefulset in a namespace with wait - { - Config: testAccResourceKustomizationConfig_wait_failure_statefulset("test_kustomizations/wait-fail-statefulset/initial"), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckStatefulSetNotReady("kustomization_resource.state1", "test-wait-fail-statefulset", "test-statefulset"), - assertDurationIsLongerThan(now, 1*time.Minute), - ), - ExpectError: regexp.MustCompile("timed out creating/updating StatefulSet test-wait-fail-statefulset/test-statefulset:"), - }, - }, - }) -} - -func testAccResourceKustomizationConfig_wait_failure_statefulset(path string) string { - return testAccDataSourceKustomizationConfig_basic(path) + ` +func testAccResourceKustomizationConfig_wait_failure(path string, kind string) string { + return testAccDataSourceKustomizationConfig_basic(path) + fmt.Sprintf(` resource "kustomization_resource" "ns" { - manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-fail-statefulset"] + manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-fail"] } -resource "kustomization_resource" "state1" { - manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-wait-fail-statefulset/test-statefulset"] +resource "kustomization_resource" "dep" { + manifest = data.kustomization_build.test.manifests["apps/%s/test-wait-fail/test"] wait = true timeouts { create = "1m" } } -` +`, kind) } func TestAccResourceKustomization_nowait(t *testing.T) { - resource.Test(t, resource.TestCase{ - //PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - // - // - // Applying initial config with a svc and deployment and statefulset in a namespace without wait - // so shouldn't exist immediately after creation - { - Config: testAccResourceKustomizationConfig_nowait("test_kustomizations/nowait/initial"), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), - testAccCheckDeploymentNotReady("kustomization_resource.dep1", "test-nowait", "test"), - testAccCheckStatefulSetNotReady("kustomization_resource.state1", "test-nowait", "test-statefulset"), - ), - }, - // - // - // Applying modified config updating the deployment and statefulset annotation without wait, - // so we don't immediately expect the annotation to be present - { - Config: testAccResourceKustomizationConfig_nowait("test_kustomizations/nowait/modified"), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckManifestNestedString("kustomization_resource.dep1", "this will cause a redeploy", "spec", "template", "metadata", "annotations", "new"), - testAccCheckDeploymentNotReady("kustomization_resource.dep1", "test-nowait", "test"), - testAccCheckManifestNestedString("kustomization_resource.state1", "this will cause statefulset to redeploy", "spec", "template", "metadata", "annotations", "new"), - testAccCheckStatefulSetNotReady("kustomization_resource.state1", "test-nowait", "test-statefulset"), - ), + for kind, readyCheck := range waitSupportedResources { + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + // Applying initial config without wait so shouldn't be ready immediately after creation + { + Config: testAccResourceKustomizationConfig_nowait("test_kustomizations/nowait/initial", kind), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckManifestNestedString("kustomization_resource.dep", "test", "spec", "selector", "matchLabels", "app"), + testAccCheckResourceNotReady("kustomization_resource.dep", "test-nowait", "test", kind, readyCheck), + ), + }, + // Applying modified config updating the deployment and statefulset annotation without wait, + // so we don't immediately expect the annotation to be present + { + Config: testAccResourceKustomizationConfig_nowait("test_kustomizations/nowait/modified", kind), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckManifestNestedString("kustomization_resource.dep", "this will cause a redeploy", "spec", "template", "metadata", "annotations", "new"), + testAccCheckResourceNotReady("kustomization_resource.dep", "test-nowait", "test", kind, readyCheck), + ), + }, }, - }, - }) + }) + } } -func testAccResourceKustomizationConfig_nowait(path string) string { - return testAccDataSourceKustomizationConfig_basic(path) + ` +func testAccResourceKustomizationConfig_nowait(path string, kind string) string { + return testAccDataSourceKustomizationConfig_basic(path) + fmt.Sprintf(` resource "kustomization_resource" "ns" { manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-nowait"] } -resource "kustomization_resource" "dep1" { - manifest = data.kustomization_build.test.manifests["apps/Deployment/test-nowait/test"] +resource "kustomization_resource" "dep" { + manifest = data.kustomization_build.test.manifests["apps/%s/test-nowait/test"] } -resource "kustomization_resource" "state1" { - manifest = data.kustomization_build.test.manifests["apps/StatefulSet/test-nowait/test-statefulset"] -} -` +`, kind) } // Upgrade_API_Version Test @@ -1142,51 +1074,10 @@ func testAccCheckDeploymentPurged(n string) resource.TestCheckFunc { } } -func testAccCheckDeploymentReady(n string, namespace string, name string) resource.TestCheckFunc { - return func(s *terraform.State) error { - u, err := getResourceFromTestState(s, n) - if err != nil { - return err - } - - resp, err := getResourceFromK8sAPI(u) - if err != nil { - return err - } - ready, err := deploymentReady(resp) - if err != nil { - return err - } - if !ready { - return fmt.Errorf("deployment %s in %s not ready", name, namespace) - } - return nil - } -} - -func testAccCheckDeploymentNotReady(n string, namespace string, name string) resource.TestCheckFunc { - return func(s *terraform.State) error { - u, err := getResourceFromTestState(s, n) - if err != nil { - return err - } - - resp, err := getResourceFromK8sAPI(u) - if err != nil { - return err - } - ready, err := deploymentReady(resp) - if err != nil { - return err - } - if ready { - return fmt.Errorf("deployment %s in %s unexpectedly ready", name, namespace) - } - return nil - } -} - -func testAccCheckStatefulSetReady(n string, namespace string, name string) resource.TestCheckFunc { +func testAccCheckResourceReady( + n string, namespace string, name string, resourceName string, + readyCheck readyCheckFunc, +) resource.TestCheckFunc { return func(s *terraform.State) error { u, err := getResourceFromTestState(s, n) if err != nil { @@ -1197,18 +1088,21 @@ func testAccCheckStatefulSetReady(n string, namespace string, name string) resou if err != nil { return err } - ready, err := statefulSetReady(resp) + ready, err := readyCheck(resp) if err != nil { return err } if !ready { - return fmt.Errorf("statefulset %s in %s not ready", name, namespace) + return fmt.Errorf("%s %s in %s not ready", resourceName, name, namespace) } return nil } } -func testAccCheckStatefulSetNotReady(n string, namespace string, name string) resource.TestCheckFunc { +func testAccCheckResourceNotReady( + n string, namespace string, name string, resourceName string, + readyCheck readyCheckFunc, +) resource.TestCheckFunc { return func(s *terraform.State) error { u, err := getResourceFromTestState(s, n) if err != nil { @@ -1219,12 +1113,12 @@ func testAccCheckStatefulSetNotReady(n string, namespace string, name string) re if err != nil { return err } - ready, err := statefulSetReady(resp) + ready, err := readyCheck(resp) if err != nil { return err } if ready { - return fmt.Errorf("statefulset %s in %s unexpectedly ready", name, namespace) + return fmt.Errorf("%s %s in %s unexpectedly ready", resourceName, name, namespace) } return nil } diff --git a/kustomize/test_kustomizations/nowait/initial/daemonset.yaml b/kustomize/test_kustomizations/nowait/initial/daemonset.yaml new file mode 100644 index 0000000..dbd3e2c --- /dev/null +++ b/kustomize/test_kustomizations/nowait/initial/daemonset.yaml @@ -0,0 +1,18 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + labels: + app: test + name: test +spec: + selector: + matchLabels: + app: test + template: + metadata: + labels: + app: test + spec: + containers: + - image: nginx + name: nginx diff --git a/kustomize/test_kustomizations/nowait/initial/kustomization.yaml b/kustomize/test_kustomizations/nowait/initial/kustomization.yaml index 3c73f81..0928370 100644 --- a/kustomize/test_kustomizations/nowait/initial/kustomization.yaml +++ b/kustomize/test_kustomizations/nowait/initial/kustomization.yaml @@ -5,5 +5,6 @@ namespace: test-nowait resources: - namespace.yaml +- daemonset.yaml - statefulset.yaml - ../../_example_app diff --git a/kustomize/test_kustomizations/nowait/initial/statefulset.yaml b/kustomize/test_kustomizations/nowait/initial/statefulset.yaml index bcd47b0..898631c 100644 --- a/kustomize/test_kustomizations/nowait/initial/statefulset.yaml +++ b/kustomize/test_kustomizations/nowait/initial/statefulset.yaml @@ -2,17 +2,17 @@ apiVersion: apps/v1 kind: StatefulSet metadata: labels: - app: test-statefulset - name: test-statefulset + app: test + name: test spec: replicas: 1 selector: matchLabels: - app: test-statefulset + app: test template: metadata: labels: - app: test-statefulset + app: test spec: containers: - image: nginx diff --git a/kustomize/test_kustomizations/nowait/modified/kustomization.yaml b/kustomize/test_kustomizations/nowait/modified/kustomization.yaml index d34b12a..63c378d 100644 --- a/kustomize/test_kustomizations/nowait/modified/kustomization.yaml +++ b/kustomize/test_kustomizations/nowait/modified/kustomization.yaml @@ -13,11 +13,19 @@ patches: path: /spec/template/metadata/annotations value: new: this will cause a redeploy + - target: + kind: DaemonSet + name: test + patch: | + - op: add + path: /spec/template/metadata/annotations + value: + new: this will cause a redeploy - target: kind: StatefulSet - name: test-statefulset + name: test patch: | - op: add path: /spec/template/metadata/annotations value: - new: this will cause statefulset to redeploy + new: this will cause a redeploy diff --git a/kustomize/test_kustomizations/wait-change/initial/daemonset.yaml b/kustomize/test_kustomizations/wait-change/initial/daemonset.yaml new file mode 100644 index 0000000..dbd3e2c --- /dev/null +++ b/kustomize/test_kustomizations/wait-change/initial/daemonset.yaml @@ -0,0 +1,18 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + labels: + app: test + name: test +spec: + selector: + matchLabels: + app: test + template: + metadata: + labels: + app: test + spec: + containers: + - image: nginx + name: nginx diff --git a/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml b/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml index 5c12aca..b5d68f7 100644 --- a/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml +++ b/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml @@ -5,5 +5,6 @@ namespace: test-wait-change resources: - namespace.yaml +- daemonset.yaml - statefulset.yaml - ../../_example_app diff --git a/kustomize/test_kustomizations/wait-change/initial/statefulset.yaml b/kustomize/test_kustomizations/wait-change/initial/statefulset.yaml index bcd47b0..898631c 100644 --- a/kustomize/test_kustomizations/wait-change/initial/statefulset.yaml +++ b/kustomize/test_kustomizations/wait-change/initial/statefulset.yaml @@ -2,17 +2,17 @@ apiVersion: apps/v1 kind: StatefulSet metadata: labels: - app: test-statefulset - name: test-statefulset + app: test + name: test spec: replicas: 1 selector: matchLabels: - app: test-statefulset + app: test template: metadata: labels: - app: test-statefulset + app: test spec: containers: - image: nginx diff --git a/kustomize/test_kustomizations/wait-fail-statefulset/initial/kustomization.yaml b/kustomize/test_kustomizations/wait-fail-statefulset/initial/kustomization.yaml deleted file mode 100644 index f3ccbbd..0000000 --- a/kustomize/test_kustomizations/wait-fail-statefulset/initial/kustomization.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization - -namespace: test-wait-fail-statefulset - -resources: -- namespace.yaml -- statefulset.yaml diff --git a/kustomize/test_kustomizations/wait-fail-statefulset/initial/namespace.yaml b/kustomize/test_kustomizations/wait-fail-statefulset/initial/namespace.yaml deleted file mode 100644 index 41adcb3..0000000 --- a/kustomize/test_kustomizations/wait-fail-statefulset/initial/namespace.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: test-wait-fail-statefulset diff --git a/kustomize/test_kustomizations/wait-fail-statefulset/initial/statefulset.yaml b/kustomize/test_kustomizations/wait-fail-statefulset/initial/statefulset.yaml deleted file mode 100644 index 2792fb2..0000000 --- a/kustomize/test_kustomizations/wait-fail-statefulset/initial/statefulset.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - labels: - app: test-statefulset - name: test-statefulset -spec: - replicas: 1 - selector: - matchLabels: - app: test-statefulset - template: - metadata: - labels: - app: test-statefulset - spec: - containers: - - image: doesnotexist/definitelydoesntexist - name: willfail diff --git a/kustomize/test_kustomizations/wait-fail/initial/daemonset.yaml b/kustomize/test_kustomizations/wait-fail/initial/daemonset.yaml new file mode 100644 index 0000000..dbd3e2c --- /dev/null +++ b/kustomize/test_kustomizations/wait-fail/initial/daemonset.yaml @@ -0,0 +1,18 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + labels: + app: test + name: test +spec: + selector: + matchLabels: + app: test + template: + metadata: + labels: + app: test + spec: + containers: + - image: nginx + name: nginx diff --git a/kustomize/test_kustomizations/wait-fail/initial/kustomization.yaml b/kustomize/test_kustomizations/wait-fail/initial/kustomization.yaml index ecd0b25..7e0f692 100644 --- a/kustomize/test_kustomizations/wait-fail/initial/kustomization.yaml +++ b/kustomize/test_kustomizations/wait-fail/initial/kustomization.yaml @@ -5,6 +5,8 @@ namespace: test-wait-fail resources: - namespace.yaml +- daemonset.yaml +- statefulset.yaml - ../../_example_app images: diff --git a/kustomize/test_kustomizations/wait-fail/initial/statefulset.yaml b/kustomize/test_kustomizations/wait-fail/initial/statefulset.yaml new file mode 100644 index 0000000..898631c --- /dev/null +++ b/kustomize/test_kustomizations/wait-fail/initial/statefulset.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + labels: + app: test + name: test +spec: + replicas: 1 + selector: + matchLabels: + app: test + template: + metadata: + labels: + app: test + spec: + containers: + - image: nginx + name: nginx diff --git a/kustomize/test_kustomizations/wait/initial/daemonset.yaml b/kustomize/test_kustomizations/wait/initial/daemonset.yaml new file mode 100644 index 0000000..dbd3e2c --- /dev/null +++ b/kustomize/test_kustomizations/wait/initial/daemonset.yaml @@ -0,0 +1,18 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + labels: + app: test + name: test +spec: + selector: + matchLabels: + app: test + template: + metadata: + labels: + app: test + spec: + containers: + - image: nginx + name: nginx diff --git a/kustomize/test_kustomizations/wait/initial/kustomization.yaml b/kustomize/test_kustomizations/wait/initial/kustomization.yaml index e0e85c3..99bebe3 100644 --- a/kustomize/test_kustomizations/wait/initial/kustomization.yaml +++ b/kustomize/test_kustomizations/wait/initial/kustomization.yaml @@ -5,5 +5,6 @@ namespace: test-wait resources: - namespace.yaml +- daemonset.yaml - statefulset.yaml - ../../_example_app diff --git a/kustomize/test_kustomizations/wait/initial/statefulset.yaml b/kustomize/test_kustomizations/wait/initial/statefulset.yaml index bcd47b0..898631c 100644 --- a/kustomize/test_kustomizations/wait/initial/statefulset.yaml +++ b/kustomize/test_kustomizations/wait/initial/statefulset.yaml @@ -2,17 +2,17 @@ apiVersion: apps/v1 kind: StatefulSet metadata: labels: - app: test-statefulset - name: test-statefulset + app: test + name: test spec: replicas: 1 selector: matchLabels: - app: test-statefulset + app: test template: metadata: labels: - app: test-statefulset + app: test spec: containers: - image: nginx diff --git a/kustomize/test_kustomizations/wait/modified/kustomization.yaml b/kustomize/test_kustomizations/wait/modified/kustomization.yaml index b82f37a..7a4ff24 100644 --- a/kustomize/test_kustomizations/wait/modified/kustomization.yaml +++ b/kustomize/test_kustomizations/wait/modified/kustomization.yaml @@ -15,7 +15,15 @@ patches: new: this will cause a redeploy - target: kind: StatefulSet - name: test-statefulset + name: test + patch: | + - op: add + path: /spec/template/metadata/annotations + value: + new: this will cause a redeploy + - target: + kind: DaemonSet + name: test patch: | - op: add path: /spec/template/metadata/annotations