Skip to content

Commit

Permalink
fix: handle svc objects with empty annotations (#560)
Browse files Browse the repository at this point in the history
Check if svc objects have no annotations and create a map to avoid a nil
pointer reference. Inspired by:
https://github.com/kubernetes-sigs/cluster-api/blob/v1.7.3/util/annotations/helpers.go

Fixes: #477
  • Loading branch information
cprivitere committed Jun 26, 2024
2 parents 5b6801a + cfb9955 commit 9ec4f48
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions metal/loadbalancers/emlb/emlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ func (l *LB) reconcileService(ctx context.Context, svc *v1.Service, n []*v1.Node

patch := client.MergeFrom(svc.DeepCopy())

svc.Annotations[LoadBalancerIDAnnotation] = loadBalancer.GetId()
svc.Annotations["equinix.com/loadbalancerMetro"] = l.manager.GetMetro()
annotations := svc.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}

annotations[LoadBalancerIDAnnotation] = loadBalancer.GetId()
annotations["equinix.com/loadbalancerMetro"] = l.manager.GetMetro()

svc.SetAnnotations(annotations)

return l.client.Patch(ctx, svc, patch)
}
Expand Down

0 comments on commit 9ec4f48

Please sign in to comment.