Skip to content

fix: route CmdDelete through the engine and unstick finalizer teardown - #103

Open
ntlaletsi70 wants to merge 1 commit into
release/v0.4.1from
bugfix/githubevent-teardown-routing
Open

fix: route CmdDelete through the engine and unstick finalizer teardown#103
ntlaletsi70 wants to merge 1 commit into
release/v0.4.1from
bugfix/githubevent-teardown-routing

Conversation

@ntlaletsi70

Copy link
Copy Markdown
Collaborator

Summary

  • GitHubEvent and Deployment reconcilers computed cmdType (Update vs Delete) correctly but then hardcoded Type: command.CmdUpdate when building the engine command — CmdDelete (and therefore CleanupPrerequisites) was never reached on deletion, so the finalizer either leaked resources (if create-ish logic happened to succeed against a dying object) or got stuck forever (if it didn't). Fixed both to use the computed cmdType.
  • Build, Deployment, and GitRepository's teardown required an Environment lookup that fails permanently once the Environment CR is deleted, wedging the finalizer if the Environment goes before its children. Added EnvironmentGone as a pre-check so teardown skips store-bound cleanup once the Environment is confirmed gone, instead of erroring forever.
  • GitHubEvent's teardown drops the Environment dependency entirely: GitHubEvent CRs are written by the Argo Events Sensor into the fixed argo-events namespace, never the Environment's own namespace, so the lookup was structurally unsatisfiable in production. GitHubWebhookSecretReconciler.Delete only needs the secret's name/namespace, not a store binding.
  • Fixed a nil-pointer panic in the build observer (applyTriggers dereferenced resolved.Spec.Policy.Triggers without a nil check on Policy), crashing on every Build CR with no policy block.

All four fixes were reproduced and verified live against a kind cluster before and after the change, in addition to unit test coverage.

Test plan

  • go build ./..., go vet ./..., go test ./... all pass
  • Live-reproduced the stuck-finalizer scenario (delete Environment before its Build/GitHubEvent children) against a kind cluster; confirmed teardown now completes cleanly with no manual finalizer patch
  • Live-confirmed CmdDelete now reaches the engine for both GitHubEvent and Deployment (previously always routed as CmdUpdate)
  • Live-confirmed the build-observer panic is gone for a Build CR with no policy block
  • New unit tests: EnvironmentGone (mediators), CleanupPrerequisites_NoEnvironment (githubevent mediator), updated TestBuildDomain_Handle_Delete_MissingEnvironment to assert the corrected behavior

🤖 Generated with Claude Code

GitHubEvent and Deployment reconcilers computed the correct cmdType
(Update vs Delete based on finalizer/deletionTimestamp) but then hardcoded
Type: command.CmdUpdate when building the engine command. CmdDelete was
never reached, so CleanupPrerequisites never ran on deletion — the
finalizer only cleared if create-ish logic happened to succeed against a
dying object, and stuck forever otherwise.

Also fixes a related class of stuck finalizer: Build, Deployment, and
GitRepository's CleanupPrerequisites required an Environment lookup that
fails permanently once the Environment is deleted, wedging the finalizer
if the Environment goes before its children. Added EnvironmentGone as a
pre-check mediators can use to skip store-bound cleanup once the
Environment is confirmed gone.

GitHubEvent's teardown drops the Environment dependency entirely instead:
GitHubEvent CRs are written by the Argo Events Sensor into the fixed
argo-events namespace, never the Environment's own namespace, so the
lookup was structurally unsatisfiable in production regardless of
deletion order. GitHubWebhookSecretReconciler.Delete only needs the
secret's name/namespace, not a store binding.

Also fixes a nil-pointer panic in the build observer: applyTriggers
dereferenced resolved.Spec.Policy.Triggers without checking Policy for
nil, crashing on every Build CR with no policy block.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant