Summary
When comparing Kubernetes Volume and VolumeMount structs in reconciliation loops, the codebase currently uses reflect.DeepEqual. However, the Kubernetes API server injects defaults into stored objects (e.g., SecretVolumeSource.defaultMode = 0644). This means that a desired struct built without explicit defaults will never be reflect.DeepEqual to the fetched object that has been defaulted by the API server, potentially causing perpetual reconciliation updates and preventing convergence.
The recommended approach is to use k8s.io/apimachinery/pkg/api/equality.Semantic.DeepEqual, which is designed to handle Kubernetes-specific semantics including nil vs. default value differences.
Affected Areas
This issue is not limited to a single file — it applies across the entire codebase wherever reflect.DeepEqual is used to compare Kubernetes API objects that may have server-side defaults applied (Volumes, VolumeMounts, and other types with defaultable fields).
Action Items
- Audit usages of
reflect.DeepEqual in reconciliation/controller logic for Kubernetes API object comparisons.
- Replace with
k8s.io/apimachinery/pkg/api/equality.Semantic.DeepEqual where appropriate.
References
Summary
When comparing Kubernetes
VolumeandVolumeMountstructs in reconciliation loops, the codebase currently usesreflect.DeepEqual. However, the Kubernetes API server injects defaults into stored objects (e.g.,SecretVolumeSource.defaultMode = 0644). This means that a desired struct built without explicit defaults will never bereflect.DeepEqualto the fetched object that has been defaulted by the API server, potentially causing perpetual reconciliation updates and preventing convergence.The recommended approach is to use
k8s.io/apimachinery/pkg/api/equality.Semantic.DeepEqual, which is designed to handle Kubernetes-specific semantics including nil vs. default value differences.Affected Areas
This issue is not limited to a single file — it applies across the entire codebase wherever
reflect.DeepEqualis used to compare Kubernetes API objects that may have server-side defaults applied (Volumes, VolumeMounts, and other types with defaultable fields).Action Items
reflect.DeepEqualin reconciliation/controller logic for Kubernetes API object comparisons.k8s.io/apimachinery/pkg/api/equality.Semantic.DeepEqualwhere appropriate.References