github-vet / github-vet/rangeloop-pointer-findings

teknologist/kube-lb: service_loadbalancer.go; 53 LoC

Open
#14,849 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [teknologist/kube-lb](https://www.github.com/teknologist/kube-lb) at [service_loadbalancer.go](https://github.com/teknologist/kube-lb/blob/cee54321d6110a2eb63dea1508d545e61c36df45/service_loadbalancer.go#L330-L382)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to s was used in a composite literal at line 356

[Click here to see the code in its original context.](https://github.com/teknologist/kube-lb/blob/cee54321d6110a2eb63dea1508d545e61c36df45/service_loadbalancer.go#L330-L382)

Click here to show the 53 line(s) of Go which triggered the analyzer.

```go
for _, s := range services.Items {
if s.Spec.Type == api.ServiceTypeLoadBalancer {
glog.Infof("Ignoring service %v, it already has a loadbalancer", s.Name)
continue
}
for _, servicePort := range s.Spec.Ports {
// TODO: headless services?
sName := s.Name
if servicePort.Protocol == api.ProtocolUDP ||
(lbc.targetService != "" && lbc.targetService != sName) {
glog.Infof("Ignoring %v: %+v", sName, servicePort)
continue
}

if lbc.forwardServices {
ep = []string{
fmt.Sprintf("%v:%v", s.Spec.ClusterIP, servicePort.Port)}
} else {
ep = lbc.getEndpoints(&s, &servicePort)
}
if len(ep) == 0 {
glog.Infof("No endpoints found for service %v, port %+v",
sName, servicePort)
continue
}
newSvc := service{
Name: getServiceNameForLBRule(&s, servicePort.Port),
Ep: ep,
}

if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getHost(); ok {
newSvc.Host = val
}

if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getAlgorithm(); ok {
for _, current := range supportedAlgorithms {
if val == current {
newSvc.Algorithm = val
break
}
}
}

if port, ok := lbc.tcpServices[sName]; ok && port == servicePort.Port {
newSvc.FrontendPort = servicePort.Port
tcpSvc = append(tcpSvc, newSvc)
} else {
newSvc.FrontendPort = lbc.httpPort
httpSvc = append(httpSvc, newSvc)
}
glog.Infof("Found service: %+v", newSvc)
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: cee54321d6110a2eb63dea1508d545e61c36df45

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.