Skip to content

Commit

Permalink
Fixup nil pointer dereference panic
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielXiao committed Aug 23, 2024
1 parent 7f57993 commit 73b55e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,14 @@ func (c *Controller) syncNode(key string) error {
switch {
case apierrors.IsNotFound(err):
// node absence in store means watcher caught the deletion, ensure Pod CIDR of this Node is released
klog.V(4).Infof("Node %s is not found, releasing Pod CIDR %s", node.Name, node.Spec.PodCIDR)
err = c.nsxIPManager.ReleasePodCIDR(node)
klog.V(4).Infof("Node %s is not found, releasing its Pod CIDR", name)
err = c.nsxIPManager.ReleasePodCIDR(&corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: name}})
case err != nil:
utilruntime.HandleError(fmt.Errorf("unable to retrieve node %v from store: %v", key, err))
utilruntime.HandleError(fmt.Errorf("unable to retrieve node %v from store: %v", name, err))
default:
if !node.DeletionTimestamp.IsZero() {
// node is being deleted, ensure Pod CIDR of this Node is released
klog.V(4).Infof("Node %s is being deleted, releasing Pod CIDR %s", node.Name, node.Spec.PodCIDR)
err = c.nsxIPManager.ReleasePodCIDR(node)
} else {
// node exists in store, ensure Pod CIDR of this Node is claimed
klog.V(4).Infof("Node %s is found, ensuring Pod CIDR claimed", node.Name)
err = c.nsxIPManager.ClaimPodCIDR(node)
}
// node exists in store, ensure Pod CIDR of this Node is claimed
klog.V(4).Infof("Node %s is found, ensuring Pod CIDR claimed", name)
err = c.nsxIPManager.ClaimPodCIDR(node)
}

return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloudprovider/vsphereparavirtual/nsxipmanager/nsx_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type NSXVPCIPManager struct {
}

func (m *NSXVPCIPManager) createIPAddressAllocation(name string) error {
klog.V(4).Infof("Creating IPAddressAllocation CR %s/%s", m.svNamespace, name)
klog.V(4).Infof("Creating IPAddressAllocation %s/%s", m.svNamespace, name)
ipAddressAllocation := &vpcapisv1.IPAddressAllocation{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -73,6 +73,7 @@ func (m *NSXVPCIPManager) ReleasePodCIDR(node *corev1.Node) error {
return err
}

klog.V(4).Infof("Deleting IPAddressAllocations %s/%s", m.svNamespace, node.Name)
return m.client.CrdV1alpha1().IPAddressAllocations(m.svNamespace).Delete(context.Background(), node.Name, metav1.DeleteOptions{})
}

Expand Down

0 comments on commit 73b55e2

Please sign in to comment.