kubernetes-sigs / cluster-api-provider-nested

Cluster API Provider for Nested Clusters
Apache License 2.0
299 stars 65 forks source link

🐛 Handle GetCluster == nil in CRD uws #306

Closed m-messiah closed 2 years ago

m-messiah commented 2 years ago

What this PR does / why we need it:

c.MultiClusterController.GetCluster method returns a pointer, but nil check was not done, so sometimes we could see the panic in logs, resulting syncer to be restarted or completely broken in that loop.

E0915 11:20:03.699391       1 runtime.go:78] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference)
goroutine 6354 [running]:
k8s.io/apimachinery/pkg/util/runtime.logPanic({0x1b6d040?, 0x30ce4b0})
    /go/pkg/mod/k8s.io/apimachinery@v0.21.1/pkg/util/runtime/runtime.go:74 +0x99
k8s.io/apimachinery/pkg/util/runtime.HandleCrash({0x0, 0x0, 0xc18faa20d0?})
    /go/pkg/mod/k8s.io/apimachinery@v0.21.1/pkg/util/runtime/runtime.go:48 +0x75
panic({0x1b6d040, 0x30ce4b0})
    /usr/local/go/src/runtime/panic.go:884 +0x212
sigs.k8s.io/cluster-api-provider-nested/virtualcluster/pkg/syncer/resources/crd.(*controller).BackPopulate(0xc0007f4480, {0xc18836d5e0?, 0xc18faa20d0?})
    /go/pkg/mod/sigs.k8s.io/cluster-api-provider-nested/virtualcluster@v0.0.0-20220825091205-ef058637a56e/pkg/syncer/resources/crd/uws.go:67 +0x149
...

The PR just adds a non-nil check for the object as it is already done in other invocations of the method

k8s-ci-robot commented 2 years ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: christopherhein, m-messiah

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[virtualcluster/OWNERS](https://github.com/kubernetes-sigs/cluster-api-provider-nested/blob/main/virtualcluster/OWNERS)~~ [christopherhein] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment