github-vet / github-vet/rangeloop-pointer-findings
kubekit99/operator-ohm: armada-operator/pkg/services/watches.go; 45 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [kubekit99/operator-ohm](https://www.github.com/kubekit99/operator-ohm) at [armada-operator/pkg/services/watches.go](https://github.com/kubekit99/operator-ohm/blob/78349bb2a97da33955ad7a95c63bcfe5c8503cef/armada-operator/pkg/services/watches.go#L41-L85)
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 u was used in a composite literal at line 74
[Click here to see the code in its original context.](https://github.com/kubekit99/operator-ohm/blob/78349bb2a97da33955ad7a95c63bcfe5c8503cef/armada-operator/pkg/services/watches.go#L41-L85)
Click here to show the 45 line(s) of Go which triggered the analyzer.
```go
for _, u := range dependent {
gvk := u.GroupVersionKind()
wlog := log.WithValues("OwnerKind", owner.GroupVersionKind().GroupKind(), "resourceType", gvk.GroupVersion(), "resourceKind", gvk.Kind)
m.RLock()
_, ok := watches[gvk]
m.RUnlock()
if ok {
continue
}
restMapper := mgr.GetRESTMapper()
depMapping, err := restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil {
wlog.Error(err, "GetRESTMapper")
return err
}
ownerMapping, err := restMapper.RESTMapping(owner.GroupVersionKind().GroupKind(), owner.GroupVersionKind().Version)
if err != nil {
wlog.Error(err, "Build RESTMapping")
return err
}
depClusterScoped := depMapping.Scope.Name() == meta.RESTScopeNameRoot
ownerClusterScoped := ownerMapping.Scope.Name() == meta.RESTScopeNameRoot
if !ownerClusterScoped && depClusterScoped {
m.Lock()
watches[gvk] = struct{}{}
m.Unlock()
wlog.Info("Cannot watch cluster-scoped")
continue
}
err = c.Watch(&source.Kind{Type: &u}, &crthandler.EnqueueRequestForOwner{OwnerType: owner}, dependentPredicate)
if err != nil {
wlog.Error(err, "Add Watch to Controller")
return err
} else {
wlog.Info("Added watch")
}
m.Lock()
watches[gvk] = struct{}{}
m.Unlock()
}
```
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: 78349bb2a97da33955ad7a95c63bcfe5c8503cef
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.