diff --git a/go.mod b/go.mod index b756f2fe16b11..660bc9351437b 100644 --- a/go.mod +++ b/go.mod @@ -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-20241211153501-dd67dd23d8b9 diff --git a/go.sum b/go.sum index 5cfe6edec501b..1805e1f9b1046 100644 --- a/go.sum +++ b/go.sum @@ -88,8 +88,6 @@ github.com/antonmedv/expr v1.15.1/go.mod h1:0E/6TxnOlRNp81GMzX9QfDPAmHo2Phg00y4J github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE= -github.com/argoproj/gitops-engine v0.7.1-0.20241126194557-037140180399 h1:oTAr8D0pwnu3rw01nvokr6S7iXniq7so72lSvJzlrQs= -github.com/argoproj/gitops-engine v0.7.1-0.20241126194557-037140180399/go.mod h1:H3JR5JJWtiCC8gxU2iaffw4ER4vhNBxwgwyxtMOR/2Y= github.com/argoproj/notifications-engine v0.4.1-0.20241007194503-2fef5c9049fd h1:lOVVoK89j9Nd4+JYJiKAaMNYC1402C0jICROOfUPWn0= github.com/argoproj/notifications-engine v0.4.1-0.20241007194503-2fef5c9049fd/go.mod h1:N0A4sEws2soZjEpY4hgZpQS8mRIEw6otzwfkgc3g9uQ= github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1 h1:qsHwwOJ21K2Ao0xPju1sNuqphyMnMYkyB3ZLoLtxWpo= @@ -219,6 +217,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= +github.com/dejanzele/gitops-engine v0.0.0-20241211153501-dd67dd23d8b9 h1:6N/+J6eGsB/slKd0ln+CAqBp4vZung2rx3s2nyNRUcU= +github.com/dejanzele/gitops-engine v0.0.0-20241211153501-dd67dd23d8b9/go.mod h1:H3JR5JJWtiCC8gxU2iaffw4ER4vhNBxwgwyxtMOR/2Y= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/test/e2e/hook_test.go b/test/e2e/hook_test.go index a538566986213..2bf00d2a7d18d 100644 --- a/test/e2e/hook_test.go +++ b/test/e2e/hook_test.go @@ -427,3 +427,32 @@ 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) { + t.Helper() + 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)})) +} diff --git a/test/e2e/testdata/hook-resource-deleted-externally/hook.yaml b/test/e2e/testdata/hook-resource-deleted-externally/hook.yaml new file mode 100644 index 0000000000000..1bb04369c9516 --- /dev/null +++ b/test/e2e/testdata/hook-resource-deleted-externally/hook.yaml @@ -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 \ No newline at end of file diff --git a/test/e2e/testdata/hook-resource-deleted-externally/pod.yaml b/test/e2e/testdata/hook-resource-deleted-externally/pod.yaml new file mode 100644 index 0000000000000..001aa52b04cec --- /dev/null +++ b/test/e2e/testdata/hook-resource-deleted-externally/pod.yaml @@ -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