From b98f36e7fec58714cdea8a915f27c8f34be747e8 Mon Sep 17 00:00:00 2001 From: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com> Date: Wed, 6 Jul 2022 00:33:52 +0530 Subject: [PATCH] Make TestYttWaitRulesWithUnblockChanges more certain (#548) --- test/e2e/custom_wait_rules_test.go | 79 +++++++++++++++--------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/test/e2e/custom_wait_rules_test.go b/test/e2e/custom_wait_rules_test.go index af0f7be53..eabef1dae 100644 --- a/test/e2e/custom_wait_rules_test.go +++ b/test/e2e/custom_wait_rules_test.go @@ -127,28 +127,7 @@ func TestYttWaitRules_WithUnblockChanges(t *testing.T) { kapp := Kapp{t, env.Namespace, env.KappBinaryPath, logger} kubectl := Kubectl{t, env.Namespace, logger} - yaml := ` -apiVersion: kapp.k14s.io/v1alpha1 -kind: Config - -waitRules: - - ytt: - funcContractV1: - resource.star: | - def is_done(resource): - state = resource.status.currentState - if state == "Progressing": - return {"done": False, "unblockChanges": True, "message": "Unblock blocked changes"} - elif state == "Running": - return {"done": True, "successful": True, "message": "Current state as Running"} - else: - return {"done": True, "successful": False, "message": "Not in Failed or Running state"} - end - end - resourceMatchers: - - apiVersionKindMatcher: {apiVersion: stable.example.com/v1, kind: CronTab} ---- -apiVersion: apiextensions.k8s.io/v1 + crd := `apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: crontabs.stable.example.com @@ -180,7 +159,28 @@ spec: names: plural: crontabs singular: crontab - kind: CronTab + kind: CronTab` + + yaml := ` +apiVersion: kapp.k14s.io/v1alpha1 +kind: Config + +waitRules: + - ytt: + funcContractV1: + resource.star: | + def is_done(resource): + state = resource.status.currentState + if state == "Progressing": + return {"done": False, "unblockChanges": True, "message": "Unblock blocked changes"} + elif state == "Running": + return {"done": True, "successful": True, "message": "Current state as Running"} + else: + return {"done": True, "successful": False, "message": "Not in Failed or Running state"} + end + end + resourceMatchers: + - apiVersionKindMatcher: {apiVersion: stable.example.com/v1, kind: CronTab} --- apiVersion: "stable.example.com/v1" kind: CronTab @@ -202,8 +202,10 @@ metadata: kapp.k14s.io/change-rule: "upsert after upserting cr"` name := "test-custom-wait-rule-contract-v1" + crdApp := "test-custom-wait-rule-contract-v1-crd" cleanUp := func() { kapp.Run([]string{"delete", "-a", name}) + kapp.Run([]string{"delete", "-a", crdApp}) } cleanUp() @@ -223,6 +225,8 @@ metadata: }() logger.Section("deploy resource with current state as progressing", func() { + kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", crdApp}, RunOpts{StdinReader: strings.NewReader(crd)}) + out, _ := kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name}, RunOpts{ StdinReader: strings.NewReader(yaml)}) @@ -230,32 +234,27 @@ metadata: expectedOutput := strings.TrimSpace(replaceSpaces(`Changes -Namespace Name Kind Age Op Op st. Wait to Rs Ri $ -(cluster) crontabs.stable.example.com CustomResourceDefinition - create - reconcile - - $ -kapp-test my-new-cron-object-1 CronTab - create - reconcile - - $ -^ test-cm ConfigMap - create - reconcile - - $ +Namespace Name Kind Age Op Op st. Wait to Rs Ri $ +kapp-test my-new-cron-object-1 CronTab - create - reconcile - - $ +^ test-cm ConfigMap - create - reconcile - - $ -Op: 3 create, 0 delete, 0 update, 0 noop, 0 exists -Wait to: 3 reconcile, 0 delete, 0 noop +Op: 2 create, 0 delete, 0 update, 0 noop, 0 exists +Wait to: 2 reconcile, 0 delete, 0 noop -: ---- applying 1 changes [0/3 done] ---- -: create customresourcedefinition/crontabs.stable.example.com (apiextensions.k8s.io/v1) cluster -: ---- waiting on 1 changes [0/3 done] ---- -: ok: reconcile customresourcedefinition/crontabs.stable.example.com (apiextensions.k8s.io/v1) cluster -: ---- applying 1 changes [1/3 done] ---- +: ---- applying 1 changes [0/2 done] ---- : create crontab/my-new-cron-object-1 (stable.example.com/v1) namespace: kapp-test -: ---- waiting on 1 changes [1/3 done] ---- +: ---- waiting on 1 changes [0/2 done] ---- : ongoing: reconcile crontab/my-new-cron-object-1 (stable.example.com/v1) namespace: kapp-test : ^ Allowing blocked changes to proceed: Unblock blocked changes -: ---- applying 1 changes [2/3 done] ---- +: ---- applying 1 changes [1/2 done] ---- : create configmap/test-cm (v1) namespace: kapp-test -: ---- waiting on 2 changes [1/3 done] ---- +: ---- waiting on 2 changes [0/2 done] ---- : ok: reconcile configmap/test-cm (v1) namespace: kapp-test -: ---- waiting on 1 changes [2/3 done] ---- +: ---- waiting on 1 changes [1/2 done] ---- : ok: reconcile crontab/my-new-cron-object-1 (stable.example.com/v1) namespace: kapp-test : ^ Current state as Running -: ---- applying complete [3/3 done] ---- -: ---- waiting complete [3/3 done] ---- +: ---- applying complete [2/2 done] ---- +: ---- waiting complete [2/2 done] ---- Succeeded`)) require.Equal(t, expectedOutput, out)