github-vet / github-vet/rangeloop-pointer-findings
bluek8s/kubedirector: pkg/controller/secret/secret.go; 60 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [bluek8s/kubedirector](https://www.github.com/bluek8s/kubedirector) at [pkg/controller/secret/secret.go](https://github.com/bluek8s/kubedirector/blob/5fca5b9b3708829a252b036e98ac5297e2f84875/pkg/controller/secret/secret.go#L64-L123)
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.
> function call at line 68 may store a reference to kubecluster
[Click here to see the code in its original context.](https://github.com/bluek8s/kubedirector/blob/5fca5b9b3708829a252b036e98ac5297e2f84875/pkg/controller/secret/secret.go#L64-L123)
Click here to show the 60 line(s) of Go which triggered the analyzer.
```go
for _, kubecluster := range allClusters.Items {
if isClusterUsingSecret(secret.Name, kubecluster) {
shared.LogInfof(
reqLogger,
&kubecluster,
shared.EventReasonSecret,
"connected secret {%s} has changed",
secret.Name,
)
shared.LogInfof(
reqLogger,
secret,
shared.EventReasonCluster,
"connected to cluster {%s}; updating it",
kubecluster.Name,
)
//Notify cluster by incrementing configmetaGenerator
wait := time.Second
maxWait := 4096 * time.Second
for {
updateMetaGenerator := &kubecluster
annotations := updateMetaGenerator.Annotations
if annotations == nil {
annotations = make(map[string]string)
updateMetaGenerator.Annotations = annotations
}
if v, ok := annotations[shared.ConnectionsIncrementor]; ok {
newV, _ := strconv.Atoi(v)
annotations[shared.ConnectionsIncrementor] = strconv.Itoa(newV + 1)
} else {
annotations[shared.ConnectionsIncrementor] = "1"
}
updateMetaGenerator.Annotations = annotations
if shared.Update(context.TODO(), updateMetaGenerator) == nil {
break
}
// Since update failed, get a fresh copy of this cluster to work with and
// try update
updateMetaGenerator, fetchErr := observer.GetCluster(kubecluster.Namespace, kubecluster.Name)
if fetchErr != nil {
if errors.IsNotFound(fetchErr) {
break
}
}
if wait > maxWait {
shared.LogErrorf(
reqLogger,
fmt.Errorf("failed to update cluster"),
secret,
shared.EventReasonSecret,
"Unable to notify cluster {%s} of configmeta change",
updateMetaGenerator.Name)
break
}
time.Sleep(wait)
wait = wait * 2
}
}
}
```
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: 5fca5b9b3708829a252b036e98ac5297e2f84875
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.