kubeslice / worker-operator

Kubeslice Worker Operator Opensource Repository: The KubeSlice Worker Operator is a Kubernetes operator that manages the lifecycle of KubeSlice worker clusters.
Apache License 2.0
58 stars 19 forks source link

Bug: Operator panicking out as `Client` not set #335

Closed Bhargav-InfraCloud closed 4 months ago

Bhargav-InfraCloud commented 4 months ago

πŸ“œ Description

The operator is panicking out due to nil pointer dereference on master.

Earlier, the field client.Client in SliceGwReconciler (pkg/hub/controllers/slicegateway_controller.go) was being set by sigs.k8s.io/controller-runtime/pkg/controller by calling the InjectClient method that the reconciler(s) implement in worker-operator.

But in the commit 8077621e3faaf798e0fa1ac4218e99765a89198b, the sigs.k8s.io/controller-runtime was bumped up from v0.11.1 to v0.16.3. And in v0.15.0, the controller-runtime had some breaking changes, and removing InjectClient is one of them.

So, after that, the client.Client is no longer set by controller-runtime and so, the operator panics of nil pointer dereference.

πŸ‘Ÿ Reproduction steps

Run the controller and worker setup and check for the kubeslice-operator deployment's logs.

πŸ‘ Expected behavior

It shouldn't panic. And the worker operator should function as usual.

πŸ‘Ž Actual Behavior

It panics due to nil pointer dereference.

🐚 Relevant log output

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=0x30 pc=0x1845091]
goroutine 219 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
    /workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:116 +0x1fa
panic({0x1a0f880, 0x2cb13a0})
    /usr/local/go/src/runtime/panic.go:884 +0x213
github.com/kubeslice/worker-operator/pkg/hub/controllers.(*SliceGwReconciler).Reconcile(0xc0008dc2c0, {0x1f25ae8, 0xc000b083c0}, {{{0xc0006afa80?, 0x5?}, {0xc0005c5100?, 0xc000b26d48?}}})
    /workspace/pkg/hub/controllers/slicegateway_controller.go:59 +0xb1
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x1f28380?, {0x1f25ae8?, 0xc000b083c0?}, {{{0xc0006afa80?, 0xb?}, {0xc0005c5100?, 0x0?}}})
    /workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:119 +0xc8
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc0004600a0, {0x1f25a40, 0xc00098d0e0}, {0x1aa66a0?, 0xc000372080?})
    /workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:316 +0x3ca
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc0004600a0, {0x1f25a40, 0xc00098d0e0})
    /workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:266 +0x1d9
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
    /workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:227 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
    /workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:223 +0x587

Version

Latest master. Commit: 8077621e3faaf798e0fa1ac4218e99765a89198b

πŸ–₯️ What operating system are you seeing the problem on?

Linux

βœ… Proposed Solution

Set the client in SliceGwReconciler at the hub/manager level itself.

Probably need to clean up all the code around InjectClient in multiple places as it is obsolete now. And in tests (many).

πŸ‘€ Have you spent some time to check if this issue has been raised before?

Code of Conduct