Skip to content

Commit

Permalink
fix(controller): fix bug if cnr is not found in lister
Browse files Browse the repository at this point in the history
Signed-off-by: caohe <caohe9603@gmail.com>
  • Loading branch information
caohe committed Jul 25, 2023
1 parent 1253f13 commit a32e408
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/controller/lifecycle/cnr.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ func (cl *CNRLifecycle) clearUnexpectedCNR() {

func (cl *CNRLifecycle) updateOrCreateCNR(node *corev1.Node) error {
cnr, err := cl.cnrLister.Get(node.Name)
if err != nil && !errors.IsNotFound(err) {
return fmt.Errorf("failed to get cnr from lister %s: %v", node.Name, err)
}
if errors.IsNotFound(err) {
cnr = &apis.CustomNodeResource{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -308,6 +311,12 @@ func (cl *CNRLifecycle) updateOrCreateCNR(node *corev1.Node) error {
if err != nil && !errors.IsAlreadyExists(err) {
return fmt.Errorf("failed to create cnr %s: %v", cnr.Name, err)
}
if errors.IsAlreadyExists(err) {
cnr, err = cl.client.InternalClient.NodeV1alpha1().CustomNodeResources().Get(cl.ctx, node.Name, metav1.GetOptions{ResourceVersion: "0"})
if err != nil {
return fmt.Errorf("failed to get cnr from apiserver %s: %v", node.Name, err)
}
}
}

newCNR := cnr.DeepCopy()
Expand Down

0 comments on commit a32e408

Please sign in to comment.