samba-in-kubernetes / samba-operator

An operator for a Samba as a service on PVCs in kubernetes
Apache License 2.0
120 stars 24 forks source link

Samba-operator crashes when setting affinity in clustered samba server #330

Closed FTS152 closed 8 months ago

FTS152 commented 9 months ago

Reproduce:

  1. Open ctdb experimental feature
  2. Set affinity options in smbcommonconfig
    podSettings:
    affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
    ...
  3. Deploy smbshare and samba-operator crashes with the following logs:
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
 panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1593f0a]

goroutine 314 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
 /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.4/pkg/internal/controller/controller.go:119 +0x1fa
panic({0x16f5040, 0x26e0e20})
 /usr/local/go/src/runtime/panic.go:884 +0x213
github.com/samba-in-kubernetes/samba-operator/internal/resources.buildOneSmbdPerNodeAffinity(0xc0000caf00, 0xc000409bc0?, {0x18fc6c8, 0x20})
 /workspace/internal/resources/statefulsets.go:89 +0x22a
github.com/samba-in-kubernetes/samba-operator/internal/resources.buildStatefulSet(0xc0000caf00, {0xc0001470e0, 0x11}, {0xc0009f20e0, 0x1d}, {0xc000147098, 0x15})
 /workspace/internal/resources/statefulsets.go:34 +0x30d
github.com/samba-in-kubernetes/samba-operator/internal/resources.(*SmbShareManager).getOrCreateStatefulSet(0xc00081fc90, {0x1b47760, 0xc000409ad0}, 0xc0000caf00, {0xc000147098, 0x15})
 /workspace/internal/resources/getters.go:406 +0xc6
github.com/samba-in-kubernetes/samba-operator/internal/resources.(*SmbShareManager).updateClusteredState(0xc00081fc90, {0x1b47760, 0xc000409ad0}, 0xc0000caf00)
 /workspace/internal/resources/smbshare.go:351 +0xee
github.com/samba-in-kubernetes/samba-operator/internal/resources.(*SmbShareManager).Update(0xc00081fc90, {0x1b47760, 0xc000409ad0}, 0xc0006a18c0)
 /workspace/internal/resources/smbshare.go:170 +0x366
github.com/samba-in-kubernetes/samba-operator/internal/resources.(*SmbShareManager).Process(0xc0003f7c90, {0x1b47760, 0xc000409ad0}, {{0xc000147098?, 0x14?}, {0xc000147080?, 0x0?}})
 /workspace/internal/resources/smbshare.go:102 +0x125
github.com/samba-in-kubernetes/samba-operator/controllers.(*SmbShareReconciler).Reconcile(0xc000406f00, {0x1b47760, 0xc000409ad0}, {{{0xc000147098, 0x15}, {0xc000147080, 0x17}}})
 /workspace/controllers/smbshare_controller.go:71 +0x253
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x1b47760?, {0x1b47760?, 0xc000409ad0?}, {{{0xc000147098?, 0x16776a0?}, {0xc000147080?, 0x0?}}})
 /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.4/pkg/internal/controller/controller.go:122 +0xc8
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc00039f360, {0x1b476b8, 0xc0004db130}, {0x174c960?, 0xc0004ba480?})
 /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.4/pkg/internal/controller/controller.go:323 +0x35f
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc00039f360, {0x1b476b8, 0xc0004db130})
 /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.4/pkg/internal/controller/controller.go:274 +0x1d9
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
 /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.4/pkg/internal/controller/controller.go:235 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
 /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.4/pkg/internal/controller/controller.go:231 +0x587

Causes:

According to the logs, samba-operator reports error at func buildOneSmbdPerNodeAffinity(). When affinity is set, affinity.PodAntiAffinity may still be null if this attribute is not set in smbcommonconfig. Currently a workaround is adding affinity.PodAntiAffinity with empty list in the yaml file.

podSettings:
  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution: []
synarete commented 9 months ago

Try with this fix: https://github.com/samba-in-kubernetes/samba-operator/pull/331