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

kubernetes-retired/contrib: service-loadbalancer/service_loadbalancer.go; 80 LoC

Open
#15,441 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 [kubernetes-retired/contrib](https://www.github.com/kubernetes-retired/contrib) at [service-loadbalancer/service_loadbalancer.go](https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L419-L498)

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 servicePort was used in a composite literal at line 442

[Click here to see the code in its original context.](https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L419-L498)

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

```go
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 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: 89f6948e24578fed2a90a87871b2263729f90ac3

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.