-
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
Open
pedro-cs-ribeiro
wants to merge
20
commits into
argoproj:master
Choose a base branch
from
pedro-cs-ribeiro:pre-delete-hooks
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.
+492
−42
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e76e6d4
docs: Fix typos and grammar in tls.md (#22229)
todaywasawesome f6733d8
chore(deps): bump golang.org/x/oauth2 from 0.27.0 to 0.28.0 (#22211)
dependabot[bot] 60dbdc2
chore: Update some dependencies and add some comments about old libs …
andrii-korotkov-verkada af83b6a
chore(deps): bump selenium-webdriver from 4.27.0 to 4.29.0 in /ui-tes…
dependabot[bot] 230b328
feat: PreDelete hooks support
pedro-ribeiro-rci d17e0f6
feat: Add PreDelete hook tests
pedro-ribeiro-rci b676d24
feat: Update docs with PreDelete hook references
pedro-ribeiro-rci 72aaa09
Merge remote-tracking branch 'refs/remotes/upstream/master' into pre-…
pedro-ribeiro-rci 501806d
fix: fix e2e test import
pedro-ribeiro-rci 2455a76
fix: fix lint
pedro-ribeiro-rci d7be2a9
fix: fix lint
pedro-ribeiro-rci 42219fd
chore(lint): fix deep copy informers lint (#22290)
crenshaw-dev 0ed7c56
fix: Unable to edit http repo credentials from ArgoCD UI (#22065)
aali309 1a5abe1
feat: PreDelete hooks support
pedro-ribeiro-rci 79dc586
feat: Add PreDelete hook tests
pedro-ribeiro-rci 42effb4
feat: Update docs with PreDelete hook references
pedro-ribeiro-rci 9399fdf
fix: fix e2e test import
pedro-ribeiro-rci ef48c4f
fix: fix lint
pedro-ribeiro-rci 4e60963
fix: fix pr comments
pedro-ribeiro-rci 0071ca3
merge
pedro-ribeiro-rci 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 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 |
---|---|---|
|
@@ -1193,26 +1193,53 @@ func (ctrl *ApplicationController) finalizeApplicationDeletion(app *appv1.Applic | |
if err != nil { | ||
return err | ||
} | ||
|
||
// Get destination cluster | ||
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) | ||
app.UnSetCascadedDeletion() | ||
app.UnSetPostDeleteFinalizer() | ||
if app.HasPreDeleteFinalizer() { | ||
app.UnSetPreDeleteFinalizer() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why doesn't |
||
if err := ctrl.updateFinalizers(app); err != nil { | ||
return err | ||
} | ||
logCtx.Infof("Resource entries removed from undefined cluster") | ||
return nil | ||
} | ||
|
||
clusterRESTConfig, err := destCluster.RESTConfig() | ||
if err != nil { | ||
return err | ||
} | ||
config := metrics.AddMetricsTransportWrapper(ctrl.metricsServer, app, clusterRESTConfig) | ||
|
||
// Handle PreDelete hooks - run them before any deletion occurs | ||
if app.HasPreDeleteFinalizer() { | ||
objsMap, err := ctrl.getPermittedAppLiveObjects(destCluster, app, proj, projectClusters) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
done, err := ctrl.executePreDeleteHooks(app, proj, objsMap, config, logCtx) | ||
if err != nil { | ||
return err | ||
} | ||
if !done { | ||
// PreDelete hooks are still running - wait for them to complete | ||
return nil | ||
} | ||
// PreDelete hooks are done - remove the finalizer so we can continue with deletion | ||
app.UnSetPreDeleteFinalizer() | ||
if err := ctrl.updateFinalizers(app); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if app.CascadedDeletion() { | ||
deletionApproved := app.IsDeletionConfirmed(app.DeletionTimestamp.Time) | ||
|
||
logCtx.Infof("Deleting resources") | ||
// ApplicationDestination points to a valid cluster, so we may clean up the live objects | ||
objs := make([]*unstructured.Unstructured, 0) | ||
|
@@ -1289,6 +1316,23 @@ func (ctrl *ApplicationController) finalizeApplicationDeletion(app *appv1.Applic | |
return ctrl.updateFinalizers(app) | ||
} | ||
|
||
if app.HasPreDeleteFinalizer("cleanup") { | ||
objsMap, err := ctrl.getPermittedAppLiveObjects(destCluster, app, proj, projectClusters) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
done, err := ctrl.cleanupPreDeleteHooks(objsMap, config, logCtx) | ||
if err != nil { | ||
return err | ||
} | ||
if !done { | ||
return nil | ||
} | ||
app.UnSetPreDeleteFinalizer("cleanup") | ||
return ctrl.updateFinalizers(app) | ||
} | ||
|
||
if app.HasPostDeleteFinalizer("cleanup") { | ||
objsMap, err := ctrl.getPermittedAppLiveObjects(destCluster, app, proj, projectClusters) | ||
if err != nil { | ||
|
@@ -1306,7 +1350,7 @@ func (ctrl *ApplicationController) finalizeApplicationDeletion(app *appv1.Applic | |
return ctrl.updateFinalizers(app) | ||
} | ||
|
||
if !app.CascadedDeletion() && !app.HasPostDeleteFinalizer() { | ||
if !app.CascadedDeletion() && !app.HasPostDeleteFinalizer() && !app.HasPreDeleteFinalizer() { | ||
if err := ctrl.cache.SetAppManagedResources(app.Name, nil); err != nil { | ||
return err | ||
} | ||
|
@@ -1797,7 +1841,23 @@ func (ctrl *ApplicationController) processAppRefreshQueueItem() (processNext boo | |
patchMs = ctrl.persistAppStatus(origApp, &app.Status) | ||
// This is a partly a duplicate of patch_ms, but more descriptive and allows to have measurement for the next step. | ||
ts.AddCheckpoint("persist_app_status_ms") | ||
if (compareResult.hasPostDeleteHooks != app.HasPostDeleteFinalizer() || compareResult.hasPostDeleteHooks != app.HasPostDeleteFinalizer("cleanup")) && | ||
if (compareResult.hasPreDeleteHooks != app.HasPreDeleteFinalizer() || | ||
compareResult.hasPreDeleteHooks != app.HasPreDeleteFinalizer("cleanup")) && | ||
app.GetDeletionTimestamp() == nil { | ||
if compareResult.hasPreDeleteHooks { | ||
app.SetPreDeleteFinalizer() | ||
app.SetPreDeleteFinalizer("cleanup") | ||
} else { | ||
app.UnSetPreDeleteFinalizer() | ||
app.UnSetPreDeleteFinalizer("cleanup") | ||
} | ||
|
||
if err := ctrl.updateFinalizers(app); err != nil { | ||
logCtx.Errorf("Failed to update finalizers: %v", err) | ||
} | ||
} | ||
if (compareResult.hasPostDeleteHooks != app.HasPostDeleteFinalizer() || | ||
compareResult.hasPostDeleteHooks != app.HasPostDeleteFinalizer("cleanup")) && | ||
app.GetDeletionTimestamp() == nil { | ||
if compareResult.hasPostDeleteHooks { | ||
app.SetPostDeleteFinalizer() | ||
|
This file contains 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
Oops, something went wrong.
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.
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?