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 Feb 7, 2023
1 parent 710e89c commit ae3aec0
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 @@ -655,19 +655,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 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 @@ -689,7 +696,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)
}

func (c *Controller) handleErr(err error, key interface{}) {
Expand Down

0 comments on commit ae3aec0

Please sign in to comment.