tarantool/tarantool-operator

Panic when `ctx.GetLeader()` is nil?

ramil-bitrise opened this issue · 2 comments

Expected behavior

No panics

Actual behavior

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=0x20 pc=0x1462ed0]

goroutine 292 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.1/pkg/internal/controller/controller.go:119 +0x1fa
panic({0x15edae0, 0x2588de0})
	/usr/local/go/src/runtime/panic.go:884 +0x212
github.com/tarantool/tarantool-operator/pkg/topology/transport/podexec.(*PodExec).Exec(0xc00038ff00, {0x1a32060, 0xc001231330}, 0x0, {0x151a900, 0xc00001b250}, {0x185aa49, 0xd5}, {0x0, 0x0, ...})
	/workspace/pkg/topology/transport/podexec/transport.go:37 +0xd0
github.com/tarantool/tarantool-operator/pkg/topology.(*CommonCartridgeTopology).Exec(...)
	/workspace/pkg/topology/common.go:20
github.com/tarantool/tarantool-operator/pkg/topology.(*CommonCartridgeTopology).GetRolesHierarchy(0xc0002cf620, {0x1a32060, 0xc001231330}, 0xc00004e730?)
	/workspace/pkg/topology/common.go:236 +0xcb
github.com/tarantool/tarantool-operator/pkg/reconciliation/steps/role.(*ConfigureVShardRolesStep[...]).Reconcile(0x1, 0x1a34640?, 0xc0007d0c30?)
	/workspace/pkg/reconciliation/steps/role/configure_vshard_roles.go:40 +0x34a
github.com/tarantool/tarantool-operator/pkg/reconciliation.(*SteppedReconciler[...]).Run(0xc0003ea948, 0xc000562730, {0xc000573b50?, 0x16?, 0xc001097af0})
	/workspace/pkg/reconciliation/reconciler.go:33 +0x4fa
github.com/tarantool/tarantool-operator/controllers.(*RoleReconciler).Reconcile(0xc0001160b8, {0x1a31df8?, 0xc0007d0cc0}, {{{0xc00004e730?, 0x10?}, {0xc00082c4e0?, 0x40da67?}}})
	/workspace/controllers/role_controller.go:102 +0x668
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x1a31df8?, {0x1a31df8?, 0xc0007d0cc0?}, {{{0xc00004e730?, 0x1573260?}, {0xc00082c4e0?, 0x0?}}})
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.1/pkg/internal/controller/controller.go:122 +0xc8
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc000001360, {0x1a31d50, 0xc00038f800}, {0x1644760?, 0xc000507980?})
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.1/pkg/internal/controller/controller.go:323 +0x38f
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc000001360, {0x1a31d50, 0xc00038f800})
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.1/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.1/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.1/pkg/internal/controller/controller.go:231 +0x333

Steps to reproduce the behavior

I don't have steps to reproduce, hope that stacktrace is enough to add nil dereference sanity check.

Environment

Also, don't have it but we are trying to use latest versions for tarantool and tarantool-operator. Let me know if this is needed.

Tarantool-operator version is v1.0.0-rc2

Possible fix:

diff --git a/pkg/reconciliation/steps/role/configure_vshard_roles.go b/pkg/reconciliation/steps/role/configure_vshard_roles.go
index 6cf9742..6a48fa3 100644
--- a/pkg/reconciliation/steps/role/configure_vshard_roles.go
+++ b/pkg/reconciliation/steps/role/configure_vshard_roles.go
@@ -37,6 +37,11 @@ func (r *ConfigureVShardRolesStep[RoleType, CtxType, CtrlType]) Reconcile(ctx Ct
                                continue
                        }

+                       if ctx.GetLeader() == nil {
+                               allRolesConfigured = false
+                               continue
+                       }
+
                        hierarchy, err := topologyClient.GetRolesHierarchy(ctx, ctx.GetLeader())
                        if err != nil {
                                allRolesConfigured = false

Closing for now, looks like it's not reproduced in the latest version.