-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
feat: PreDelete hooks support (Issue #13975) #22288
base: master
Are you sure you want to change the base?
feat: PreDelete hooks support (Issue #13975) #22288
Conversation
Signed-off-by: Dan Garfield <dan@codefresh.io> Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
…#22211) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
…rgoproj#22104) (argoproj#22208) Signed-off-by: Andrii Korotkov <andrii.korotkov@verkada.com> Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
argoproj#22117) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com> Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
…delete-hooks # Conflicts: # go.mod # go.sum # ui-test/package.json
✅ Preview Environment deployed on Bunnyshell
See: Environment Details | Pipeline Logs Available commands (reply to this comment):
|
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #22288 +/- ##
==========================================
- Coverage 55.91% 55.87% -0.04%
==========================================
Files 343 343
Lines 57305 57487 +182
==========================================
+ Hits 32042 32121 +79
- Misses 22623 22705 +82
- Partials 2640 2661 +21 ☔ View full report in Codecov by Sentry. |
hookHealth = &health.HealthStatus{ | ||
Status: health.HealthStatusHealthy, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? I don't know if assuming healthy for when there's no health would not have any undesired side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For pre-delete hooks, defaulting to "Healthy" when no health check is defined prevents the process from getting stuck waiting for an undefined condition.
This approach is consistent with how we handle other hook types on the code.
@@ -86,7 +85,7 @@ func Test_deepCopyAppProjectClient_List(t *testing.T) { | |||
{name: "Error listing app project", fields: fields{ | |||
AppProjectInterface: func() clientset.AppProjectInterface { | |||
appProject := mocks.AppProjectInterface{} | |||
appProject.On("List", context.Background(), metav1.ListOptions{}).Return(nil, errors.New("error")) | |||
appProject.On("List", t.Context(), metav1.ListOptions{}).Return(nil, errors.New("error")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to rebase, this was fixed in another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased to latest upstream master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like rebase wasn't fully done or wasn't to the latest master, since these changes are still here.
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
Signed-off-by: Pedro Ribeiro <pedro.ribeiro@cross-join.com>
destCluster, err := argo.GetDestinationCluster(context.Background(), app.Spec.Destination, ctrl.db) | ||
if err != nil { | ||
logCtx.Warnf("Unable to get destination cluster: %v", err) | ||
logCtx.Warnf("Unable to locate cluster URL for Application being deleted: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this accurate? What if we can locate a URL, but there's some other error getting the cluster?
app.UnSetCascadedDeletion() | ||
app.UnSetPostDeleteFinalizer() | ||
if app.HasPreDeleteFinalizer() { | ||
app.UnSetPreDeleteFinalizer() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't app.UnSetPostDeleteFinalizer()
require such a check?
postDeleteHooks = map[string]string{ | ||
"argocd.argoproj.io/hook": postDeleteHook, | ||
"helm.sh/hook": "post-delete", | ||
} | ||
) | ||
|
||
func isHook(obj *unstructured.Unstructured) bool { | ||
return hook.IsHook(obj) || isPostDeleteHook(obj) | ||
return hook.IsHook(obj) || isPostDeleteHook(obj) || isPreDeleteHook(obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are pre- and post- delete hooks are handled separately?
return true, nil | ||
} | ||
|
||
func (ctrl *ApplicationController) executePostDeleteHooks(app *appv1.Application, proj *appv1.AppProject, liveObjs map[kube.ResourceKey]*unstructured.Unstructured, config *rest.Config, logCtx *log.Entry) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we unify some code with post-detele hooks?
@@ -86,7 +85,7 @@ func Test_deepCopyAppProjectClient_List(t *testing.T) { | |||
{name: "Error listing app project", fields: fields{ | |||
AppProjectInterface: func() clientset.AppProjectInterface { | |||
appProject := mocks.AppProjectInterface{} | |||
appProject.On("List", context.Background(), metav1.ListOptions{}).Return(nil, errors.New("error")) | |||
appProject.On("List", t.Context(), metav1.ListOptions{}).Return(nil, errors.New("error")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like rebase wasn't fully done or wasn't to the latest master, since these changes are still here.
(httpsValues.type != 'git' && 'Bearer token is only supported for Git BitBucket Data Center repositories'), | ||
tlsClientCertKey: !httpsValues.tlsClientCertKey && httpsValues.tlsClientCertData && 'TLS client cert key is required if TLS client cert is given.' | ||
(validURLValues.password && validURLValues.bearerToken && 'Either the password or the bearer token must be set, but not both.') || | ||
(validURLValues.type != 'git' && 'Bearer token is only supported for Git BitBucket Data Center repositories.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these changes needed?
private isHTTPSUrl(url: string) { | ||
if (url.match(/^https:\/\/.*$/gi)) { | ||
// Whether url is a http or https url | ||
private isHTTPOrHTTPSUrl(url: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we separate these changes into a different PR, please?
Closes #13975
This PR introduces PreDelete hooks for Argo CD. PreDelete hooks allow users to execute tasks before an application's resources are deleted, providing a way to perform graceful shutdowns, backup operations, or other cleanup tasks that should happen before resource deletion.
Implementation details:
The implementation follows the same pattern established for PostDelete hooks:
Checklist:
ArgoCD_PreDelete_Hook.mov