Skip to content

Implementation proposal: TemporalNamespace deletion stuck on finalizer patch #8

Description

@Azerothian

Source

Upstream issue: alexandrevilain#943 — "Cannot delete namespaces"

When trying to delete a TemporalNamespace I often encounter issues where the operator gets stuck and fails to reconcile Temporal namespaces … ERROR Reconciler error … unable to patch object: TemporalNamespace.temporal.io "debugging" is invalid: metadata.finalizers: Forbidden: no new finalizers can be added if the object is being deleted, found new finalizers []string{"foregroundDeletion"} … I usually have to manually remove the finalizer from the TemporalNamespace object and also restart the operator itself as it gets stuck.

Why it fits this operator

Deleting a TemporalNamespace is a first-class operator lifecycle operation. A namespace that cannot be deleted (operator stuck in a loop, forced to hand-remove Kubernetes finalizers and restart the controller) leaves garbage workflows behind and blocks cluster teardown. This is core reconciler/finalizer logic — the operator's responsibility.

Proposed implementation

  1. Finalizer guard — in the TemporalNamespace finalizer/deletion path, never re-add a finalizer once Kubernetes has marked the object as being deleted (foregroundDeletion present → abort cleanly instead of re-patching).
  2. Idempotent deletion — when the namespace is already absent on the Temporal server (try to delete but not found), treat "not found" as success and finish removing CRD-side resources instead of erroring/looping.
  3. Reconcile self-heal — on a failed delete reconcile, surface a clear reconcile-blocked state instead of repeatedly re-patching the same invalid object (the cause of the stuck loop).

Affected areas

  • TemporalNamespace controller / reconciler deletion path
  • Finalizer logic (controllers/finalizer)
  • Error handling for the namespace-delete RPC (not found)

Risks / migration concerns

  • Deletion is destructive — keep the delete-vs-patch distinction; never silently skip when the namespace exists on the server.
  • Needs e2e coverage (create → delete → re-create) so the fix doesn't reintroduce stuck/finalizer states.
  • Tracks the still-open upstream defect.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions