Skip to content

Commit 545388d

Browse files
committed
Fix nodePlugin affinity not propagating from OperatorConfig to DaemonSet
Rook creates Driver CRs with a non-nil but empty Affinity struct. The merge logic only checked if Affinity == nil, so the affinity from OperatorConfig.driverSpecDefaults was never applied. Add isAffinityEmpty() helper to check for nil or effectively empty affinity structs, allowing the merge to properly fill in defaults. Signed-off-by: ksc98 <kylechang96@gmail.com>
1 parent 7c71102 commit 545388d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

internal/controller/driver_controller.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ func mergeDriverSpecs(dest, src *csiv1.DriverSpec) {
17311731
if dest.Annotations == nil {
17321732
dest.Annotations = src.Annotations
17331733
}
1734-
if dest.Affinity == nil {
1734+
if isAffinityEmpty(dest.Affinity) {
17351735
dest.Affinity = src.Affinity
17361736
}
17371737
if dest.Tolerations == nil {
@@ -1786,7 +1786,7 @@ func mergeDriverSpecs(dest, src *csiv1.DriverSpec) {
17861786
if dest.Annotations == nil {
17871787
dest.Annotations = src.Annotations
17881788
}
1789-
if dest.Affinity == nil {
1789+
if isAffinityEmpty(dest.Affinity) {
17901790
dest.Affinity = src.Affinity
17911791
}
17921792
if dest.Tolerations == nil {
@@ -1855,3 +1855,14 @@ func mergeDriverSpecs(dest, src *csiv1.DriverSpec) {
18551855
dest.CephFsClientType = src.CephFsClientType
18561856
}
18571857
}
1858+
1859+
// isAffinityEmpty checks if an Affinity is nil or has no meaningful content.
1860+
// This handles the case where an Affinity struct is non-nil but contains only
1861+
// empty nested structs (e.g., &Affinity{NodeAffinity: &NodeAffinity{}}).
1862+
func isAffinityEmpty(affinity *corev1.Affinity) bool {
1863+
if affinity == nil {
1864+
return true
1865+
}
1866+
return reflect.DeepEqual(affinity, &corev1.Affinity{}) ||
1867+
reflect.DeepEqual(affinity, &corev1.Affinity{NodeAffinity: &corev1.NodeAffinity{}})
1868+
}

0 commit comments

Comments
 (0)