Fix KubeBlocks Module Destruction Issues #80
Draft
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.
Env Destroy Link -> ✅
https://1155708878.control-plane-saas-cp-saas-dev.console.facets.cloud/capc/stack/azure-project-type-1155708878/releases/cluster/68c7e87ab24e7c36bf2c1e99/dialog/release-details/6949898bf2a09b6a794578c1
Problem Statement
The KubeBlocks operator and CRD modules were experiencing critical failures during environment destruction, causing:
Error Logs
Issue 1: Finalizer and Custom Resource Deletion Errors
Issue 2: Resource Retention After Helm Uninstall
CRD stuck
Add-on CRs
Manual Patch - for testing ...
DESTROY Release error -
https://1155708878.control-plane-saas-cp-saas-dev.console.facets.cloud/capc/stack/azure-project-type-1155708878/releases/cluster/68c7e87ab24e7c36bf2c1e99/dialog/release-details/694951680c18a362176b27cf/terminal-dialog/terraform-logs?backUrl=%2Fstack%2Fazure-project-type-1155708878%2Freleases%2Fcluster%2F68c7e87ab24e7c36bf2c1e99
Root Cause Analysis
1. Resource Retention Policy
Database addon Helm charts had
helm.sh/resource-policy: keepannotations on resources, preventing deletion during Helm uninstall. This blocked CRD deletion as custom resources still existed.Reference: KubeBlocks Addon Documentation
2. Deletion Order Race Condition
During destruction, the operator (which handles webhooks and finalizers) was destroyed before custom resources finished cleaning up:
Reference: GitHub Issue #1528
Solution Overview
Three-Pronged Approach
extra.keepResource = falseon database addonstime_sleepwithdestroy_durationto ensure proper cleanup timingignore_changeson manifest attributesDetailed Changes
Change 1: Disable Resource Retention in Database Addons
File:
modules/common/kubeblocks-operator/standard/1.0/main.tfBefore:
After:
Impact: ✅ ComponentDefinitions, ConfigMaps, and other addon resources are now deleted during Helm uninstall
Change 2: Add Destruction Delay in Operator Module
File:
modules/common/kubeblocks-operator/standard/1.0/main.tfAdded:
Impact: ✅ Creates a 120-second buffer during destruction for custom resources to clean up while operator is still running
Change 3: Add Destruction Delay in CRD Module
File:
modules/common/kubeblocks-crd/standard/1.0/main.tfAdded:
Impact: ✅ Creates an additional 120-second buffer before CRD deletion
Key Changes:
metadata.finalizerstocomputed_fields(don't try to manage finalizers)metadata.uidtocomputed_fields(Kubernetes-managed field)ignore_changes = [manifest, object]to prevent massive diffs in plan outputfor_eachto use CRD name as key (stable identifier)Change 4: Improve CRD Keying Strategy
File:
modules/common/kubeblocks-crd/standard/1.0/main.tfBefore:
After:
Impact:
How The Solution Works
Corrected Destruction Flow
Key Mechanisms
1.
destroy_durationTimingThe
time_sleepresource withdestroy_durationcreates a delay before the resource itself is destroyed:During destruction:
time_sleeptime_sleepsleeps for 120 secondstime_sleepis removedtime_sleepcan now be destroyed2. Resource Retention Control
The
extra.keepResource = falseparameter tells KubeBlocks addon charts to remove thehelm.sh/resource-policy: keepannotation:Without this: Helm uninstall keeps resources → CRDs can't delete → errors
With this: Helm uninstall removes resources → CRDs can delete cleanly → success
3. Plan Output Suppression
The
ignore_changeslifecycle rule prevents Terraform from showing massive diffs:Impact:
Testing Results
Before Fix
After Fix
Sample Successful Destruction Log
Breaking Changes
References
Files Changed
modules/common/kubeblocks-operator/standard/1.0/main.tfmodules/common/kubeblocks-crd/standard/1.0/main.tfChecklist