-
Notifications
You must be signed in to change notification settings - Fork 6
Add deployment finalizer #97
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
base: main
Are you sure you want to change the base?
Conversation
e121567
to
fbc3949
Compare
9617e3f
to
4e13b89
Compare
a484510
to
b6d8d81
Compare
Previously the test was manually adding finalizers using controllerutil.AddFinalizer instead of testing the actual controller logic. Now the test calls the controller's Reconcile method to properly exercise the finalizer addition logic as intended. Addresses: #97 (comment)
Changed the exported constant TemporalWorkerDeploymentFinalizer to temporalWorkerDeploymentFinalizer (lowercase) to make it package-private since it's only used within the controller package. Addresses: #97 (comment)
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.
Pull Request Overview
This PR adds a deployment finalizer to the TemporalWorkerDeployment controller to prevent accidental deletion of deployment resources that would be unrecoverable. The finalizer ensures controlled deletion following the Kubernetes finalizer pattern, preventing unrecoverable state loss when deployments are accidentally deleted.
Key changes:
- Added finalizer management in the controller reconciliation loop
- Implemented proper cleanup logic for managed deployment resources
- Added comprehensive unit tests covering finalizer behavior and edge cases
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
internal/controller/worker_controller.go | Core finalizer implementation with deletion handling and resource cleanup logic |
internal/controller/finalizer_test.go | Comprehensive unit tests for finalizer behavior, cleanup, and edge cases |
internal/tests/internal/integration_test.go | Integration test validating deployment deletion protection behavior |
internal/testhelpers/make.go | Added test utilities for scheme setup and fake client creation |
internal/planner/planner.go | Minor code cleanup removing unnecessary else clause |
internal/k8s/deployments.go | Updated comment explaining finalizer management approach |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Add detailed documentation comments for hardcoded timeout values explaining the rationale behind the chosen durations (2 minutes cleanup timeout and 5 second poll interval) - Change field selector fallback logging from Info to debug level (V(1)) to reduce noise during normal operation, especially in test environments Addresses: - #97 (comment) - #97 (comment)
- Added testDeploymentDeletionProtection test to verify deployment resources can only be deleted by the controller - Test validates proper owner references with BlockOwnerDeletion=true - Verifies controller recreates deployments if directly deleted - Confirms controller properly cleans up deployments when TWD is deleted - Replaced logging statements with proper testify assertions for better test validation and debugging
- Update GitHub Actions workflow to use go-version-file instead of hardcoded Go 1.21 - Fix revive linting error in planner.go by removing unnecessary else clause - Fix deprecated result.Requeue usage in finalizer_test.go to use RequeueAfter
- Replace stale list iteration with proper polling using fresh queries - Add timeout and context cancellation handling with configurable constants - Implement field selector optimization with backward compatibility fallback - Replace brittle time.Sleep with condition-based polling in integration tests - Add comprehensive edge case tests for context cancellation and partial cleanup failures
Previously the test was manually adding finalizers using controllerutil.AddFinalizer instead of testing the actual controller logic. Now the test calls the controller's Reconcile method to properly exercise the finalizer addition logic as intended. Addresses: #97 (comment)
Changed the exported constant TemporalWorkerDeploymentFinalizer to temporalWorkerDeploymentFinalizer (lowercase) to make it package-private since it's only used within the controller package. Addresses: #97 (comment)
Removed duplicate testEnv struct declaration from integration_test.go as it was already defined in env_helpers.go. This resolves the build error that was preventing integration tests from running.
- Add detailed documentation comments for hardcoded timeout values explaining the rationale behind the chosen durations (2 minutes cleanup timeout and 5 second poll interval) - Change field selector fallback logging from Info to debug level (V(1)) to reduce noise during normal operation, especially in test environments Addresses: - #97 (comment) - #97 (comment)
83f07d5
to
0e1a946
Compare
What was changed
Added a deployment finalizer to prevent accidental deletion of deployment resources that would be unrecoverable for the controller.
Why?
The Temporal worker controller doesn't persist the original pod template anywhere other than in the live Kubernetes deployment resource. When a deployment is accidentally deleted (e.g., via
kubectl delete deployment
), the controller cannot recreate it since it doesn't have the old version of the pod template saved anywhere else.This finalizer follows the Kubernetes finalizers pattern to ensure controlled deletion and prevent unrecoverable state loss.
Checklist
Closes Add Finalizer for Deployment Resources #55
How was this tested: New integration test validates finalizer behavior during deployment deletion
Any docs updates needed: No documentation updates required - this is an internal implementation detail