github-vet / github-vet/rangeloop-pointer-findings
dts/kubernetes-haproxy-lb: service_loadbalancer.go; 95 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [dts/kubernetes-haproxy-lb](https://www.github.com/dts/kubernetes-haproxy-lb) at [service_loadbalancer.go](https://github.com/dts/kubernetes-haproxy-lb/blob/1bc97b737ee892b5260715c3fdb31b1b983251c3/service_loadbalancer.go#L541-L635)
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 567
[Click here to see the code in its original context.](https://github.com/dts/kubernetes-haproxy-lb/blob/1bc97b737ee892b5260715c3fdb31b1b983251c3/service_loadbalancer.go#L541-L635)
Click here to show the 95 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,
BackendPort: getTargetPort(&servicePort),
}
if priority, ok := serviceAnnotations(s.ObjectMeta.Annotations).getVirtualHostPriority(); ok {
newSvc.Priority = priority
}
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getVirtualHost(); ok {
newSvc.VirtualHost = val
newSvc.AclSets = calculateAcls(newSvc.Name,val);
}
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
}
}
} else {
newSvc.Algorithm = lbc.cfg.lbDefAlgorithm
}
// By default sticky session is disabled
newSvc.SessionAffinity = false
if s.Spec.SessionAffinity != "" {
newSvc.SessionAffinity = true
}
// By default sslTerm is disabled
newSvc.SslTerm = false
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getSslTerm(); ok {
b, err := strconv.ParseBool(val)
if err == nil {
newSvc.SslTerm = b
}
}
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getAclMatch(); ok {
newSvc.AclMatch = val
}
if port, ok := lbc.tcpServices[sName]; ok && port == servicePort.Port {
newSvc.FrontendPort = servicePort.Port
tcpSvc = append(tcpSvc, newSvc)
} else {
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getCookieStickySession(); ok {
b, err := strconv.ParseBool(val)
if err == nil {
newSvc.CookieStickySession = b
}
}
newSvc.FrontendPort = lbc.httpPort
if newSvc.SslTerm == true {
httpsTermSvc = append(httpsTermSvc, newSvc)
} else {
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: 1bc97b737ee892b5260715c3fdb31b1b983251c3
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.