Repository navigation
[MeshSync] Return ErrNilClient when initializing with nil Kubernetes client - #645
chill-czar wants to merge 1 commit into
Conversation
…client When meshsync.New was invoked with a nil kubeClient, it unconditionally dereferenced kubeClient.KubeClient while resolving the cluster ID and dynamic informer, resulting in an unhandled nil pointer panic. Check kubeClient at the beginning of meshsync.New and return the allocated ErrNilClient error (code 1016), preventing panics when constructing Handler or initializing the Kubernetes Discoverer adapter without a valid client. Signed-off-by: Sarthak Chaudhari <aisarthak2@gmail.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
pontusringblom
left a comment
There was a problem hiding this comment.
Clean guard: the nil check lands before the first dereference of kubeClient, reuses the existing ErrNilClient, and the discovery wrapper test confirms the error propagates through kubernetes.New. Two small test asks below.
Please consider and reply to each comment in this review. For every suggestion, state how you've incorporated it or explain your reasoning for not doing so.
| }) | ||
| require.Nil(t, d) | ||
| require.Error(t, err) | ||
| assert.Equal(t, "1016", meshkiterrors.GetCode(err)) |
There was a problem hiding this comment.
Use meshsync.ErrNilClientCode here instead of the literal "1016" (one added import of github.com/meshery/meshsync/meshsync) so this test tracks the constant if the code ever changes, matching how meshsync_test.go already asserts it.
| nil, | ||
| internalconfig.OutputFiltrationContainer{}, | ||
| ) | ||
| if h != nil { |
There was a problem hiding this comment.
Minor consistency point: this file hand-rolls its assertions while the companion test in internal/discovery/kubernetes uses testify require/assert. Matching that style keeps the two new tests reading the same way.
Description
When
meshsync.Newis invoked with a nilkubeClient, it unconditionally dereferenceskubeClient.KubeClientwhile resolving the cluster ID and dynamic shared informer, causing an unhandled nil pointer dereference panic.meshsync/error.godefines and registersErrNilClient(ErrNilClientCode = "1016") with the remediation "Supply a valid Kubernetes client to meshsync.New", but the check was only present inUpdateInformer()and missing from the constructor itself.This PR checks
kubeClient == nilat the start ofmeshsync.Newand returnsErrNilClient(), preventing panics when constructing a Handler or when initializing the Kubernetes Discoverer adapter (internal/discovery/kubernetes.New).Notes for Reviewers
TestNewWithNilKubeClientReturnsErrNilClientinmeshsync/meshsync_test.go.TestNewWithNilKubeClientReturnsErrNilClientininternal/discovery/kubernetes/kubernetes_test.go.go test -failfast --short ./... -race(all 7 packages pass) andmake build.Signed commits
Summary by CodeRabbit