-
Notifications
You must be signed in to change notification settings - Fork 297
fix(hooks): always remove finalizers #754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
agaudreault
wants to merge
29
commits into
argoproj:master
Choose a base branch
from
agaudreault:fix-hook-finalizer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
12baa16
clarify doc
agaudreault 03d77eb
do not preemptively fail sync if failure hooks fail to apply
agaudreault 60c298f
make sure finalizer is removed before deleting BeforeHookCreation hooks
agaudreault 6654e51
terminate hooks on error/failures
agaudreault 9f490be
always remove finalizers on existing task before creation
agaudreault 412d96b
cleanup status update on terminate
agaudreault 230a1c0
handle sync failure on manifest apply
agaudreault cccd178
fix test
agaudreault 8c43f14
clarify doc
agaudreault 5399bd1
typo
agaudreault eda44c9
Merge remote-tracking branch 'upstream/master' into fix-hook-finalizer
agaudreault dc9311d
race condition on BeforeHookCreation and replace
agaudreault 4416a7e
log
agaudreault fa0bdc3
review
agaudreault b652e65
unit tests
agaudreault a0bf17e
clean tests
agaudreault 3286e06
check deleted
agaudreault f633932
some tests
agaudreault 0201c5a
move tests
agaudreault 3d2aa95
cleanup tests
agaudreault b39a9c8
docs
agaudreault 9da34cc
import cycle
agaudreault 13fa1f3
fix cycle in import
agaudreault 9c694ed
fix unit test
agaudreault 1cec50b
revert hook finalizer const move
agaudreault bc80f53
fix pending msg
agaudreault 9bd0a63
more comments
agaudreault 8af49be
Update pkg/sync/doc.go
agaudreault ef00d91
remove finalizer from completed hooks on terminate
agaudreault File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.