Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
12baa16
clarify doc
agaudreault Aug 11, 2025
03d77eb
do not preemptively fail sync if failure hooks fail to apply
agaudreault Aug 11, 2025
60c298f
make sure finalizer is removed before deleting BeforeHookCreation hooks
agaudreault Aug 11, 2025
6654e51
terminate hooks on error/failures
agaudreault Aug 12, 2025
9f490be
always remove finalizers on existing task before creation
agaudreault Aug 12, 2025
412d96b
cleanup status update on terminate
agaudreault Aug 13, 2025
230a1c0
handle sync failure on manifest apply
agaudreault Aug 18, 2025
cccd178
fix test
agaudreault Aug 18, 2025
8c43f14
clarify doc
agaudreault Aug 18, 2025
5399bd1
typo
agaudreault Aug 18, 2025
eda44c9
Merge remote-tracking branch 'upstream/master' into fix-hook-finalizer
agaudreault Aug 18, 2025
dc9311d
race condition on BeforeHookCreation and replace
agaudreault Aug 19, 2025
4416a7e
log
agaudreault Aug 19, 2025
fa0bdc3
review
agaudreault Aug 19, 2025
b652e65
unit tests
agaudreault Aug 19, 2025
a0bf17e
clean tests
agaudreault Aug 20, 2025
3286e06
check deleted
agaudreault Aug 20, 2025
f633932
some tests
agaudreault Aug 20, 2025
0201c5a
move tests
agaudreault Aug 20, 2025
3d2aa95
cleanup tests
agaudreault Aug 20, 2025
b39a9c8
docs
agaudreault Aug 20, 2025
9da34cc
import cycle
agaudreault Aug 20, 2025
13fa1f3
fix cycle in import
agaudreault Aug 20, 2025
9c694ed
fix unit test
agaudreault Aug 20, 2025
1cec50b
revert hook finalizer const move
agaudreault Aug 20, 2025
bc80f53
fix pending msg
agaudreault Aug 20, 2025
9bd0a63
more comments
agaudreault Aug 20, 2025
8af49be
Update pkg/sync/doc.go
agaudreault Aug 22, 2025
ef00d91
remove finalizer from completed hooks on terminate
agaudreault Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/sync/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ Hooks can be deleted in an automatic fashion using the annotation: argocd.argopr
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded

Hook deletion policies are governed by sync success and failure. A successful sync operation requires all hooks to complete successfully. A sync will fail if _any_ hooks fail.
The following policies define when the hook will be deleted.

- HookSucceeded - the hook resource is deleted after the hook succeeded (e.g. Job/Workflow completed successfully).
- HookFailed - the hook resource is deleted after the hook failed.
- HookSucceeded - the hook resource is deleted if the sync succeeds
- HookFailed - the hook resource is deleted if the sync fails.
- BeforeHookCreation - any existing hook resource is deleted before the new one is created

# Sync Waves
Expand Down
84 changes: 84 additions & 0 deletions pkg/sync/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package sync

import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/argoproj/gitops-engine/pkg/health"
synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
"github.com/argoproj/gitops-engine/pkg/sync/hook"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
testingutils "github.com/argoproj/gitops-engine/pkg/utils/testing"
)

type resourceNameHealthOverride map[string]health.HealthStatusCode

func (r resourceNameHealthOverride) GetResourceHealth(obj *unstructured.Unstructured) (*health.HealthStatus, error) {
if status, ok := r[obj.GetName()]; ok {
return &health.HealthStatus{Status: status, Message: "test"}, nil
}
return nil, nil
}

func getResourceResult(resources []synccommon.ResourceSyncResult, resourceKey kube.ResourceKey) *synccommon.ResourceSyncResult {
for _, res := range resources {
if res.ResourceKey == resourceKey {
return &res
}
}
return nil
}

func newHook(name string, hookType synccommon.HookType, deletePolicy synccommon.HookDeletePolicy) *unstructured.Unstructured {
obj := testingutils.NewPod()
obj.SetName(name)
obj.SetNamespace(testingutils.FakeArgoCDNamespace)
testingutils.Annotate(obj, synccommon.AnnotationKeyHook, string(hookType))
testingutils.Annotate(obj, synccommon.AnnotationKeyHookDeletePolicy, string(deletePolicy))
obj.SetFinalizers([]string{hook.HookFinalizer})
return obj
}

func withReplaceAnnotation(un *unstructured.Unstructured) *unstructured.Unstructured {
un.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: synccommon.SyncOptionReplace})
return un
}

func withServerSideApplyAnnotation(un *unstructured.Unstructured) *unstructured.Unstructured {
un.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: synccommon.SyncOptionServerSideApply})
return un
}

func withDisableServerSideApplyAnnotation(un *unstructured.Unstructured) *unstructured.Unstructured {
un.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: synccommon.SyncOptionDisableServerSideApply})
return un
}

func withReplaceAndServerSideApplyAnnotations(un *unstructured.Unstructured) *unstructured.Unstructured {
un.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: "Replace=true,ServerSideApply=true"})
return un
}

func withForceAnnotation(un *unstructured.Unstructured) *unstructured.Unstructured {
un.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: synccommon.SyncOptionForce})
return un
}

func withForceAndReplaceAnnotations(un *unstructured.Unstructured) *unstructured.Unstructured {
un.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: "Force=true,Replace=true"})
return un
}

func createNamespaceTask(namespace string) (*syncTask, error) {
nsSpec := &corev1.Namespace{TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: kube.NamespaceKind}, ObjectMeta: metav1.ObjectMeta{Name: namespace}}
unstructuredObj, err := kube.ToUnstructured(nsSpec)

task := &syncTask{phase: synccommon.SyncPhasePreSync, targetObj: unstructuredObj}
if err != nil {
return task, fmt.Errorf("failed to convert namespace spec to unstructured: %w", err)
}
return task, nil
}
Loading