karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.46k stars 883 forks source link

Panic risk found in karmada-controller-manager #1117

Closed RainbowMango closed 2 years ago

RainbowMango commented 2 years ago

What happened: Found a panic from E2E testing:

2021-12-16T09:52:24.317479266Z stderr F I1216 09:52:24.317403       1 detector.go:450] ResourceBinding(karmadatest-rw5/job-n79-job) is up to date.
2021-12-16T09:52:24.317495167Z stderr F I1216 09:52:24.316216       1 binding_controller.go:49] Reconciling ResourceBinding karmadatest-rw5/job-n79-job.
2021-12-16T09:52:24.323018902Z stderr F panic: runtime error: index out of range [0] with length 0
2021-12-16T09:52:24.323113408Z stderr F 
2021-12-16T09:52:24.324093667Z stderr F goroutine 1372 [running]:
2021-12-16T09:52:24.325930379Z stderr F github.com/karmada-io/karmada/pkg/util.DivideReplicasByTargetCluster(0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x0)
2021-12-16T09:52:24.327448371Z stderr F     /home/runner/work/karmada/karmada/pkg/util/binding.go:81 +0x146
2021-12-16T09:52:24.333939064Z stderr F github.com/karmada-io/karmada/pkg/controllers/binding.ensureWork(0x2396568, 0xc0003a8730, 0xc00000f778, 0x233cc00, 0xc000700170, 0x23a6a88, 0xc0004ffc00, 0x20ba970, 0xa, 0x3, ...)
2021-12-16T09:52:24.33469841Z stderr F  /home/runner/work/karmada/karmada/pkg/controllers/binding/common.go:85 +0x1fdc
2021-12-16T09:52:24.335739974Z stderr F github.com/karmada-io/karmada/pkg/controllers/binding.(*ResourceBindingController).syncBinding(0xc000477b00, 0xc0004ffc00, 0xc000058038, 0xc001d1d240, 0xf, 0xc001d1d210)
2021-12-16T09:52:24.33634731Z stderr F  /home/runner/work/karmada/karmada/pkg/controllers/binding/binding_controller.go:113 +0xa0f
2021-12-16T09:52:24.338041713Z stderr F github.com/karmada-io/karmada/pkg/controllers/binding.(*ResourceBindingController).Reconcile(0xc000477b00, 0x237db18, 0xc0018bf770, 0xc001d1d240, 0xf, 0xc001d1d210, 0xb, 0xc0018bf770, 0xc0018bf740, 0xc0021d9db0, ...)
2021-12-16T09:52:24.33865305Z stderr F  /home/runner/work/karmada/karmada/pkg/controllers/binding/binding_controller.go:70 +0x26d
2021-12-16T09:52:24.340047435Z stderr F sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0xc00045abe0, 0x237db18, 0xc0018bf740, 0xc001d1d240, 0xf, 0xc001d1d210, 0xb, 0xc0018bf700, 0x0, 0x0, ...)
2021-12-16T09:52:24.340489662Z stderr F     /home/runner/work/karmada/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:114 +0x247
2021-12-16T09:52:24.341248408Z stderr F sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc00045abe0, 0x237da70, 0xc0007fc240, 0x1e89400, 0xc001c08080)
2021-12-16T09:52:24.341656332Z stderr F     /home/runner/work/karmada/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:311 +0x305
2021-12-16T09:52:24.34904428Z stderr F sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc00045abe0, 0x237da70, 0xc0007fc240, 0x21a2600)
2021-12-16T09:52:24.349456305Z stderr F     /home/runner/work/karmada/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:266 +0x205
2021-12-16T09:52:24.350065442Z stderr F sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2(0xc00081d4f0, 0xc00045abe0, 0x237da70, 0xc0007fc240)
2021-12-16T09:52:24.350427864Z stderr F     /home/runner/work/karmada/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:227 +0x6b
2021-12-16T09:52:24.350886592Z stderr F created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
2021-12-16T09:52:24.351433625Z stderr F     /home/runner/work/karmada/karmada/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:223 +0x4d2

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

RainbowMango commented 2 years ago

cc @Garrybest

Garrybest commented 2 years ago

I see. I will fix it soon.