Skip to content

Commit

Permalink
resources: fix case of nil PodAntiAffinity
Browse files Browse the repository at this point in the history
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 <ssharon@redhat.com>
  • Loading branch information
synarete committed Feb 29, 2024
1 parent 3af87a2 commit 541193c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/resources/statefulsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ func buildOneSmbdPerNodeAffinity(

affinity := affinityForSmbPod(planner)
if affinity == nil {
affinity = &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{},
}
affinity = &corev1.Affinity{}
}
if affinity.PodAntiAffinity == nil {
affinity.PodAntiAffinity = &corev1.PodAntiAffinity{}
}
affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution = append(
affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution,
Expand Down

0 comments on commit 541193c

Please sign in to comment.