Skip to content

Commit

Permalink
Add wait to existing resource
Browse files Browse the repository at this point in the history
Ensure that adding wait to an existing resource works (previously
this failed because it didn't notice that the resource had changed)
  • Loading branch information
willthames committed Feb 13, 2023
1 parent 1957b1e commit 78e7e50
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kustomize/resource_kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func kustomizationResourceUpdate(d *schema.ResourceData, m interface{}) error {
return logError(err)
}

if !d.HasChange("manifest") {
if !d.HasChange("manifest") && !d.HasChange("wait") {
return logError(kmm.fmtErr(
errors.New("update called without diff"),
))
Expand Down
58 changes: 58 additions & 0 deletions kustomize/resource_kustomization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,64 @@ resource "kustomization_resource" "dep1" {
`
}

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"),
),
},
},
})
}

func testAccResourceKustomizationConfig_wait_off(path string) string {
return testAccDataSourceKustomizationConfig_basic(path) + `
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"]
}
`
}

func testAccResourceKustomizationConfig_wait_on(path string) string {
return testAccDataSourceKustomizationConfig_basic(path) + `
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"
}
}
`
}

func TestAccResourceKustomization_wait_failure(t *testing.T) {
now := time.Now()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: test-wait-change

resources:
- namespace.yaml
- ../../_example_app
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: test-wait-change

0 comments on commit 78e7e50

Please sign in to comment.