Skip to content

Commit caaf745

Browse files
authored
Merge pull request #222 from willthames/add_wait_to_existing_resource
Add wait to existing resource
2 parents 1957b1e + 78e7e50 commit caaf745

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

kustomize/resource_kustomization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func kustomizationResourceUpdate(d *schema.ResourceData, m interface{}) error {
320320
return logError(err)
321321
}
322322

323-
if !d.HasChange("manifest") {
323+
if !d.HasChange("manifest") && !d.HasChange("wait") {
324324
return logError(kmm.fmtErr(
325325
errors.New("update called without diff"),
326326
))

kustomize/resource_kustomization_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,64 @@ resource "kustomization_resource" "dep1" {
523523
`
524524
}
525525

526+
func TestAccResourceKustomization_add_wait(t *testing.T) {
527+
now := time.Now()
528+
resource.Test(t, resource.TestCase{
529+
//PreCheck: func() { testAccPreCheck(t) },
530+
Providers: testAccProviders,
531+
Steps: []resource.TestStep{
532+
//
533+
//
534+
// Applying initial config with a svc and deployment in a namespace with no wait
535+
{
536+
Config: testAccResourceKustomizationConfig_wait_off("test_kustomizations/wait-change/initial"),
537+
Check: resource.ComposeAggregateTestCheckFunc(
538+
assertDurationIsShorterThan(now, 5*time.Minute),
539+
testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"),
540+
),
541+
},
542+
//
543+
//
544+
// Applying exactly the same configuration, but with wait turned on
545+
{
546+
Config: testAccResourceKustomizationConfig_wait_on("test_kustomizations/wait-change/initial"),
547+
Check: resource.ComposeAggregateTestCheckFunc(
548+
assertDurationIsShorterThan(now, 1*time.Minute),
549+
testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"),
550+
testAccCheckDeploymentReady("kustomization_resource.dep1", "test-wait-change", "test"),
551+
),
552+
},
553+
},
554+
})
555+
}
556+
557+
func testAccResourceKustomizationConfig_wait_off(path string) string {
558+
return testAccDataSourceKustomizationConfig_basic(path) + `
559+
resource "kustomization_resource" "ns" {
560+
manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-change"]
561+
}
562+
resource "kustomization_resource" "dep1" {
563+
manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait-change/test"]
564+
}
565+
`
566+
}
567+
568+
func testAccResourceKustomizationConfig_wait_on(path string) string {
569+
return testAccDataSourceKustomizationConfig_basic(path) + `
570+
resource "kustomization_resource" "ns" {
571+
manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-change"]
572+
}
573+
resource "kustomization_resource" "dep1" {
574+
manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait-change/test"]
575+
wait = true
576+
timeouts {
577+
create = "1m"
578+
update = "1m"
579+
}
580+
}
581+
`
582+
}
583+
526584
func TestAccResourceKustomization_wait_failure(t *testing.T) {
527585
now := time.Now()
528586

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
namespace: test-wait-change
5+
6+
resources:
7+
- namespace.yaml
8+
- ../../_example_app
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: test-wait-change

0 commit comments

Comments
 (0)