Skip to content

Commit

Permalink
Make TestYttWaitRulesWithUnblockChanges more certain (carvel-dev#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenrewar authored Jul 5, 2022
1 parent cc64572 commit b98f36e
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions test/e2e/custom_wait_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -223,39 +225,36 @@ 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)})

out = strings.TrimSpace(replaceSpaces(replaceTarget(replaceTs(out))))

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
<replaced>: ---- applying 1 changes [0/3 done] ----
<replaced>: create customresourcedefinition/crontabs.stable.example.com (apiextensions.k8s.io/v1) cluster
<replaced>: ---- waiting on 1 changes [0/3 done] ----
<replaced>: ok: reconcile customresourcedefinition/crontabs.stable.example.com (apiextensions.k8s.io/v1) cluster
<replaced>: ---- applying 1 changes [1/3 done] ----
<replaced>: ---- applying 1 changes [0/2 done] ----
<replaced>: create crontab/my-new-cron-object-1 (stable.example.com/v1) namespace: kapp-test
<replaced>: ---- waiting on 1 changes [1/3 done] ----
<replaced>: ---- waiting on 1 changes [0/2 done] ----
<replaced>: ongoing: reconcile crontab/my-new-cron-object-1 (stable.example.com/v1) namespace: kapp-test
<replaced>: ^ Allowing blocked changes to proceed: Unblock blocked changes
<replaced>: ---- applying 1 changes [2/3 done] ----
<replaced>: ---- applying 1 changes [1/2 done] ----
<replaced>: create configmap/test-cm (v1) namespace: kapp-test
<replaced>: ---- waiting on 2 changes [1/3 done] ----
<replaced>: ---- waiting on 2 changes [0/2 done] ----
<replaced>: ok: reconcile configmap/test-cm (v1) namespace: kapp-test
<replaced>: ---- waiting on 1 changes [2/3 done] ----
<replaced>: ---- waiting on 1 changes [1/2 done] ----
<replaced>: ok: reconcile crontab/my-new-cron-object-1 (stable.example.com/v1) namespace: kapp-test
<replaced>: ^ Current state as Running
<replaced>: ---- applying complete [3/3 done] ----
<replaced>: ---- waiting complete [3/3 done] ----
<replaced>: ---- applying complete [2/2 done] ----
<replaced>: ---- waiting complete [2/2 done] ----
Succeeded`))
require.Equal(t, expectedOutput, out)
Expand Down

0 comments on commit b98f36e

Please sign in to comment.