-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add status for removing / removalfailed (#1334)
## Description This PR utilizes the "new" ability in a Pepr finalizer to not remove the `finalizer`. This enables us to update the status while finalizing, and catch errors if cleanup does not work as expected. Changes: - Skip finalizer if it's already running (based on status) - Skip finalizer if Package isn't ready/failed yet (for #963) - Patch `Removing` status on the CR - Catch errors on finalization and patch `RemovalFailed` status and create a failure event - Retry each cleanup/purge function using `retryWithDelay` I also updated the diagram to support these changes, as well as adding test cases for the finalizer function. Diagram update can be previewed on the docs by using [this link](https://raw.githubusercontent.com/defenseunicorns/uds-core/c41964d426b8bb9780c26d41c631dbe6f50e854a/docs/.images/diagrams/uds-core-operator-uds-package.svg) on `docs/reference/configuration/UDS operator/package.md`, specific changes: - Moved finalizer section to the right of reconciler - Simplified flow of validator (to make more space in the diagram) - Added new pieces of finalizer flow (failure, status patching, etc) ## Related Issue Fixes #963 Fixes #1159 ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Steps to Validate <details><summary>Testing Steps</summary> Test setup: ```console # Install slim-dev (unicorn flavor to avoid pull rate limiting) uds run slim-dev --set flavor=unicorn # Create the test packages zarf p create src/test --skip-sbom # Deploy the test packages zarf p deploy build/zarf-package-uds-core-test-apps-*.tar.zst --confirm # Validate all package CRs go to Ready status kubectl get pkg -A # should all show ready ``` Test that normal deletion works and makes events: ```console # Delete a package CR kubectl delete pkg -n test-tenant-app test-tenant-app # Validate success and events kubectl get pkg -n test-tenant-app # should show no resources kubectl get events -n test-tenant-app | grep package # should show 3 removal events ``` Test that finalizer doesn't run until CR is ready: ```console # This forces a re-reconcile of the package and then deletes immediately # If you watch while this happens (k9s, etc) you should see it go to Pending before Removing kubectl patch pkg httpbin-other -n authservice-test-app --subresource=status --type=json -p='[{"op": "remove", "path": "/status"}]' && kubectl delete pkg httpbin-other -n authservice-test-app # Validate that the watcher waited to finalize kubectl logs -n pepr-system -l app=pepr-uds-core-watcher --tail=-1 | grep "Waiting" kubectl get events -n authservice-test-app | grep package # should show 3 removal events ``` Test that finalizer places CR in RemovalFailed state on failed cleanup: ```console # Deploy the test apps again (we need the sso client) zarf p deploy build/zarf-package-uds-core-test-apps-*.tar.zst --confirm # Edit the peprstore kubectl edit peprstore -n pepr-system pepr-uds-core-store # Delete the line with `uds-core-operator-v2-sso-client-uds-core-httpbin`, this is the client token and will make Pepr unable to cleanup the client # Save the peprstore # Delete the package CR kubectl delete pkg httpbin-other -n authservice-test-app # Make sure that status is marked as RemovalFailed (after ~15 seconds) kubectl get pkg httpbin-other -n authservice-test-app # Make sure events show up that client failed to be removed kubectl describe pkg httpbin-other -n authservice-test-app # Make sure that the SSO client removal was retried 4 times before final failure kubectl logs -n pepr-system -l app=pepr-uds-core-watcher --tail=-1 | grep "cleanupSSOClients" ``` </details> Also note the automated jest unit tests and validate those. ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md) followed
- Loading branch information
Showing
9 changed files
with
577 additions
and
336 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
621 changes: 308 additions & 313 deletions
621
docs/.images/diagrams/uds-core-pepr-operator-flow.drawio
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -1140,7 +1140,8 @@ | |
"Ready", | ||
"Failed", | ||
"Retrying", | ||
"Removing" | ||
"Removing", | ||
"RemovalFailed" | ||
], | ||
"title": "Phase" | ||
} | ||
|
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
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
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
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
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
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