github-vet / github-vet/rangeloop-pointer-findings
munnerz/kube-acme: cmd/monitor/main.go; 58 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [munnerz/kube-acme](https://www.github.com/munnerz/kube-acme) at [cmd/monitor/main.go](https://github.com/munnerz/kube-acme/blob/9be662fd437862f17b099c9ad440d62f64551cfe/cmd/monitor/main.go#L241-L298)
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.
> range-loop variable t used in defer or goroutine at line 258
[Click here to see the code in its original context.](https://github.com/munnerz/kube-acme/blob/9be662fd437862f17b099c9ad440d62f64551cfe/cmd/monitor/main.go#L241-L298)
Click here to show the 58 line(s) of Go which triggered the analyzer.
```go
for _, t := range ing.Spec.TLS {
certRequest, secretExists, err := getCertificateRequest(t.SecretName, ing.Namespace, t.Hosts)
if err != nil {
glog.Errorf("[%s] not requesting certificate for hosts %s: %s", t.SecretName, t.Hosts, err.Error())
continue TLSLoop
}
locks, err := acquireAllLocks(t.Hosts)
if err != nil {
glog.Errorf("[%s] failed to acquire all locks for ingress: %s", t.SecretName, err.Error())
continue TLSLoop
}
defer func() {
_, errs := lockSvc.UnlockAll(locks...)
for _, err := range errs {
glog.Errorf("[%s] error releasing lock: %s", t.SecretName, err.Error())
}
}()
glog.Errorf("[%s] acquired all locks for resource: %s", t.SecretName, ing.Name)
certs, err := acmeImpl.Perform(certRequest)
if err != nil {
glog.Errorf("[%s] failed to obtain certificate for hosts '%s': %s", t.SecretName, t.Hosts, err.Error())
// TODO: because we unlock in a defer func, they will not be released until
// after attempting to obtain certificates for the entire Ingress resource
continue TLSLoop
}
tlsSecret := monitor.DefaultTLSSecret{
Name: t.SecretName,
Namespace: ing.Namespace,
CertificateResource: certs,
}
secret, err := tlsSecret.Secret()
if err != nil {
glog.Errorf("[%s] failed to create ingress secret: %s", tlsSecret.Name, err.Error())
continue TLSLoop
}
if secretExists {
secret, err = kubeClient.Secrets(secret.Namespace).Update(secret)
} else {
secret, err = kubeClient.Secrets(secret.Namespace).Create(secret)
}
if err != nil {
glog.Errorf("[%s] error saving certificate to kubernetes: %s", t.SecretName, err)
continue TLSLoop
}
glog.Errorf("[%s] Successfully saved secret", secret.Name)
}
```
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: 9be662fd437862f17b099c9ad440d62f64551cfe
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.