Skip to content

Add wait to existing resource #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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