Skip to content

Commit

Permalink
Remove Services.Get() from syncNegStatusAnnotation()
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravkghildiyal committed Jan 31, 2023
1 parent 92eb7b9 commit 6e17f4f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/neg/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,19 +694,26 @@ func (c *Controller) syncNegStatusAnnotation(namespace, name string, portMap neg
if err != nil {
return err
}
coreClient := c.client.CoreV1()
service, err := coreClient.Services(namespace).Get(context.TODO(), name, metav1.GetOptions{})
obj, exists, err := c.serviceLister.GetByKey(getServiceKey(namespace, name).Key())
if err != nil {
return err
}
if !exists {
// Service no longer exists so doesn't require any update.
return nil
}
service, ok := obj.(*apiv1.Service)
if !ok {
return fmt.Errorf("cannot convert to obj to Service; obj=%T", obj)
}

// Remove NEG Status Annotation when no NEG is needed
if len(portMap) == 0 {
if _, ok := service.Annotations[annotations.NEGStatusKey]; ok {
newSvcObjectMeta := service.ObjectMeta.DeepCopy()
delete(newSvcObjectMeta.Annotations, annotations.NEGStatusKey)
c.logger.V(2).Info("Removing NEG status annotation from service", "service", klog.KRef(namespace, name))
return patch.PatchServiceObjectMetadata(coreClient, service, *newSvcObjectMeta)
return patch.PatchServiceObjectMetadata(c.client.CoreV1(), service, *newSvcObjectMeta)
}
// service doesn't have the expose NEG annotation and doesn't need update
return nil
Expand All @@ -728,7 +735,7 @@ func (c *Controller) syncNegStatusAnnotation(namespace, name string, portMap neg
}
newSvcObjectMeta.Annotations[annotations.NEGStatusKey] = annotation
c.logger.V(2).Info("Updating NEG visibility annotation on service", "annotation", annotation, "service", klog.KRef(namespace, name))
return patch.PatchServiceObjectMetadata(coreClient, service, *newSvcObjectMeta)
return patch.PatchServiceObjectMetadata(c.client.CoreV1(), service, *newSvcObjectMeta)
}

// syncDestinationRuleNegStatusAnnotation syncs the destinationrule related neg status annotation
Expand Down

0 comments on commit 6e17f4f

Please sign in to comment.