diff --git a/go.mod b/go.mod index 446d1de179c1e..11e74fe2d58ca 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/TomOnTime/utfutil v0.0.0-20180511104225-09c41003ee1d github.com/alicebob/miniredis/v2 v2.34.0 github.com/antonmedv/expr v1.15.1 - github.com/argoproj/gitops-engine v0.7.1-0.20250207161338-3ef5ab187edd + github.com/argoproj/gitops-engine v0.7.1-0.20250207220447-65db274b8d73 github.com/argoproj/notifications-engine v0.4.1-0.20241007194503-2fef5c9049fd github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1 github.com/aws/aws-sdk-go v1.55.6 @@ -194,7 +194,7 @@ require ( github.com/dlclark/regexp2 v1.11.4 github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/emirpasic/gods v1.18.1 // indirect - github.com/evanphx/json-patch/v5 v5.9.0 // indirect + github.com/evanphx/json-patch/v5 v5.9.11 // indirect github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect github.com/fatih/camelcase v1.0.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect diff --git a/go.sum b/go.sum index 67995b0ca6fcb..23f5ebeb4d0cc 100644 --- a/go.sum +++ b/go.sum @@ -90,8 +90,8 @@ 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.20250207161338-3ef5ab187edd h1:aCjdkkizo+PWig7csetbazm3VSBUZYbRj37YVqpqMOE= -github.com/argoproj/gitops-engine v0.7.1-0.20250207161338-3ef5ab187edd/go.mod h1:bXZN8czlc8J79DDqt8+mqhTrtO4YZIh57s9xseacy8I= +github.com/argoproj/gitops-engine v0.7.1-0.20250207220447-65db274b8d73 h1:OdAuLtAjJQNnZI3lbskJ9xvASvpHbTgQ5ONEbwm6jD0= +github.com/argoproj/gitops-engine v0.7.1-0.20250207220447-65db274b8d73/go.mod h1:h4Klm/rHWHcRJZJjsSkAxq61/SqdbPG0ef/SO2QYTks= 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= @@ -249,8 +249,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v5.9.11+incompatible h1:ixHHqfcGvxhWkniF1tWxBHA0yb4Z+d1UQi45df52xW8= github.com/evanphx/json-patch v5.9.11+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= -github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU= +github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM= github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwCFad8crR9dcMQWvV9Hvulu6hwUh4tWPJnM= github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4= github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI= diff --git a/test/e2e/hook_test.go b/test/e2e/hook_test.go index 18268623ab0ec..a1e3da0e37b53 100644 --- a/test/e2e/hook_test.go +++ b/test/e2e/hook_test.go @@ -10,14 +10,17 @@ import ( "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "github.com/argoproj/gitops-engine/pkg/health" . "github.com/argoproj/gitops-engine/pkg/sync/common" + "github.com/argoproj/pkg/errors" . "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" . "github.com/argoproj/argo-cd/v3/test/e2e/fixture" . "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app" . "github.com/argoproj/argo-cd/v3/util/errors" + "github.com/argoproj/argo-cd/v3/util/lua" ) func TestPreSyncHookSuccessful(t *testing.T) { @@ -427,3 +430,56 @@ 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). + And(func() { + errors.CheckError(SetResourceOverrides(map[string]ResourceOverride{ + lua.GetConfigMapKey(schema.FromAPIVersionAndKind("batch/v1", "Job")): { + HealthLua: ` + local hs = {} + hs.status = "Healthy" + if obj.metadata.deletionTimestamp == nil then + hs.status = "Progressing" + hs.message = "Waiting to be externally deleted" + return hs + end + if obj.metadata.finalizers ~= nil then + for i, finalizer in ipairs(obj.metadata.finalizers) do + if finalizer == "argocd.argoproj.io/hook-finalizer" then + hs.message = "Resource has finalizer" + return hs + end + end + end + hs.message = "no finalizer for a hook is wrong" + return hs`, + }, + })) + }). + 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: "Resource has finalizer", 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