Summary
Finalization logic for Kruize resources currently treats invalid cluster_type values as OpenShift by default, even though creation now rejects invalid cluster_type values. This asymmetry can hide misconfigurations and cause unexpected behavior during cleanup.
Problem Details
- At creation time, invalid
cluster_type values in Kruize.spec.cluster_type are rejected via validation.
- At finalization time, the controller currently:
- Reads
kruize.Spec.Cluster_type.
- If the value is not recognized, it defaults to OpenShift-specific cleanup instead of failing.
This leads to:
- A resource with a misconfigured
cluster_type potentially being rejected when created, but
- The same misconfigured
cluster_type being treated as OpenShift during deletion/finalization if it somehow exists in the cluster (e.g., via older versions, manual edits, or spec drift).
This behavior:
- Masks configuration errors.
- Can cause OpenShift-specific cleanup logic to run on non-OpenShift clusters.
- Makes create and delete behavior inconsistent for the same invalid spec.
Expected Behavior
Finalization should:
- Use the same validation rules for
cluster_type as creation, and
- Fail finalization (and log an error) if the stored
cluster_type is invalid, or
- Use a canonical, validated cluster type value that was persisted at creation time, and reuse that value during finalization instead of defaulting to OpenShift.
Proposed Solutions
Option A – Validate during finalization (simpler):
- In
internal/controller/kruize_controller.go, when determining the cluster type during finalization, validate kruize.Spec.Cluster_type using the same validation helper as creation (e.g. constants.IsValidClusterType).
- If invalid, log an error and return without performing cleanup.
Suggested code snippet:
// Get the cluster type to determine which resources to clean up
clusterType := kruize.Spec.Cluster_type
if !constants.IsValidClusterType(clusterType) {
err := fmt.Errorf("invalid cluster type %q in Kruize spec during finalization", clusterType)
logger.Error(err, "Invalid cluster type during finalization; refusing to proceed")
return err
}
// existing cleanup logic based on clusterType ...
To compile, ensure fmt is imported in internal/controller/kruize_controller.go:
import (
"fmt"
// other imports...
)
(If fmt is already imported, no changes are needed there.)
Option B – Persist canonical cluster type at creation (more robust, but larger change):
- During creation/reconciliation, after validating
cluster_type, store a canonical/normalized cluster type in the Kruize status or another durable field.
- During finalization, only use this canonical field to determine which cleanup logic to run.
- If the canonical field is missing or invalid (e.g. from legacy objects), log an error and fail finalization instead of defaulting to OpenShift.
Action Items
Impact
Fixing this will:
- Keep creation and finalization behavior consistent.
- Prevent invalid specs from being silently treated as OpenShift.
- Reduce risk of running OpenShift-specific cleanup on non-OpenShift clusters.
I created this issue for @shreyabiradar07 from #108 (comment).
Tips and commands
Getting Help
Summary
Finalization logic for
Kruizeresources currently treats invalidcluster_typevalues as OpenShift by default, even though creation now rejects invalidcluster_typevalues. This asymmetry can hide misconfigurations and cause unexpected behavior during cleanup.Problem Details
cluster_typevalues inKruize.spec.cluster_typeare rejected via validation.kruize.Spec.Cluster_type.This leads to:
cluster_typepotentially being rejected when created, butcluster_typebeing treated as OpenShift during deletion/finalization if it somehow exists in the cluster (e.g., via older versions, manual edits, or spec drift).This behavior:
Expected Behavior
Finalization should:
cluster_typeas creation, andcluster_typeis invalid, orProposed Solutions
Option A – Validate during finalization (simpler):
internal/controller/kruize_controller.go, when determining the cluster type during finalization, validatekruize.Spec.Cluster_typeusing the same validation helper as creation (e.g.constants.IsValidClusterType).Suggested code snippet:
To compile, ensure
fmtis imported ininternal/controller/kruize_controller.go:(If
fmtis already imported, no changes are needed there.)Option B – Persist canonical cluster type at creation (more robust, but larger change):
cluster_type, store a canonical/normalized cluster type in theKruizestatus or another durable field.Action Items
cluster_type.cluster_typein spec during finalization (should log and fail, not default to OpenShift).cluster_typeis invalid.Impact
Fixing this will:
I created this issue for @shreyabiradar07 from #108 (comment).
Tips and commands
Getting Help