Skip to content

Commit ba72432

Browse files
synaretemergify[bot]
authored andcommitted
resources: fix case of nil PodAntiAffinity
Protect from case where user provided 'affinity' entry in podSettings of smbcommonconfig but without 'podAntiAffinity' sub-entry. This in turn would cause samba-operator a nil pointer dereference. Fixes: #330 Signed-off-by: Shachar Sharon <[email protected]>
1 parent 3af87a2 commit ba72432

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

internal/resources/statefulsets.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ func buildOneSmbdPerNodeAffinity(
8181

8282
affinity := affinityForSmbPod(planner)
8383
if affinity == nil {
84-
affinity = &corev1.Affinity{
85-
PodAntiAffinity: &corev1.PodAntiAffinity{},
86-
}
84+
affinity = &corev1.Affinity{}
85+
}
86+
if affinity.PodAntiAffinity == nil {
87+
affinity.PodAntiAffinity = &corev1.PodAntiAffinity{}
8788
}
8889
affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution = append(
8990
affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution,

0 commit comments

Comments
 (0)