Skip to content

Commit

Permalink
feat: add test for hook finalizer which prevents external resource de…
Browse files Browse the repository at this point in the history
…letion

Signed-off-by: Dejan Zele Pejchev <[email protected]>
  • Loading branch information
dejanzele committed Dec 9, 2024
1 parent dfbfdba commit 2c2a2d2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,5 @@ replace (
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.31.0
k8s.io/sample-controller => k8s.io/sample-controller v0.31.0
)

replace github.com/argoproj/gitops-engine => github.com/dejanzele/gitops-engine v0.0.0-20241209160843-57d66fd87fa7
28 changes: 28 additions & 0 deletions test/e2e/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,31 @@ func TestAutomaticallyNamingUnnamedHook(t *testing.T) {
assert.Contains(t, resources[2].Name, "postsync")
})
}

func TestHookFinalizerPreSync(t *testing.T) {
testHookFinalizer(t, HookTypePreSync)
}

func TestHookFinalizerSync(t *testing.T) {
testHookFinalizer(t, HookTypeSync)
}

func TestHookFinalizerPostSync(t *testing.T) {
testHookFinalizer(t, HookTypePostSync)
}

func testHookFinalizer(t *testing.T, hookType HookType) {
Given(t).
Path("hook-resource-deleted-externally").
When().
PatchFile("hook.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/annotations", "value": {"argocd.argoproj.io/hook": "%s"}}]`, hookType)).
CreateApp().
Sync().
Then().
Expect(OperationPhaseIs(OperationSucceeded)).
Expect(SyncStatusIs(SyncStatusCodeSynced)).
Expect(ResourceSyncStatusIs("Pod", "pod", SyncStatusCodeSynced)).
Expect(ResourceHealthIs("Pod", "pod", health.HealthStatusHealthy)).
Expect(ResourceResultNumbering(2)).
Expect(ResourceResultIs(ResourceResult{Group: "batch", Version: "v1", Kind: "Job", Namespace: DeploymentNamespace(), Name: "hook", Message: "Reached expected number of succeeded pods", HookType: hookType, HookPhase: OperationSucceeded, SyncPhase: SyncPhase(hookType)}))
}
18 changes: 18 additions & 0 deletions test/e2e/testdata/hook-resource-deleted-externally/hook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: batch/v1
kind: Job
metadata:
annotations:
argocd.argoproj.io/hook: Sync
name: hook
spec:
ttlSecondsAfterFinished: 0
backoffLimit: 0
template:
spec:
containers:
- command:
- "true"
image: quay.io/argoprojlabs/argocd-e2e-container:0.1
imagePullPolicy: IfNotPresent
name: main
restartPolicy: Never
12 changes: 12 additions & 0 deletions test/e2e/testdata/hook-resource-deleted-externally/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: pod
spec:
containers:
- name: main
image: quay.io/argoprojlabs/argocd-e2e-container:0.1
imagePullPolicy: IfNotPresent
command:
- "true"
restartPolicy: Never

0 comments on commit 2c2a2d2

Please sign in to comment.