github-vet / github-vet/rangeloop-pointer-findings
dotmesh-io/ds-deployer: internal/controller/service_controller.go; 51 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [dotmesh-io/ds-deployer](https://www.github.com/dotmesh-io/ds-deployer) at [internal/controller/service_controller.go](https://github.com/dotmesh-io/ds-deployer/blob/cf9c00239111686572d242d57742f0878e847562/internal/controller/service_controller.go#L19-L69)
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 modelDeployment used in defer or goroutine at line 57
[Click here to see the code in its original context.](https://github.com/dotmesh-io/ds-deployer/blob/cf9c00239111686572d242d57742f0878e847562/internal/controller/service_controller.go#L19-L69)
Click here to show the 51 line(s) of Go which triggered the analyzer.
```go
for _, modelDeployment := range c.cache.ModelDeployments() {
existing, ok := c.cache.GetService(modelDeployment.Namespace, getDeploymentName(modelDeployment))
if !ok {
if c.statusCache.Get(modelDeployment.Id).Service != status.StatusConfiguring {
c.statusCache.Set(modelDeployment.Id, status.ModuleService, status.StatusConfiguring)
}
wg.Add(1)
// creating new deployment
go func(modelDeployment *deployer_v1.Deployment) {
err := c.createService(modelDeployment)
if err != nil {
c.logger.Errorw("failed to create service",
"error", err,
"deployment_id", modelDeployment.GetId(),
)
}
wg.Done()
}(modelDeployment)
// should get created if it doesn't exist
continue
}
c.logger.Debugf("service %s/%s found, checking for updates", existing.Namespace, existing.Name)
if !servicesEqual(toKubernetesService(modelDeployment, c.controllerIdentifier), existing) {
if c.statusCache.Get(modelDeployment.Id).Service != status.StatusConfiguring {
c.statusCache.Set(modelDeployment.Id, status.ModuleService, status.StatusConfiguring)
}
updatedService := updateService(existing, modelDeployment)
wg.Add(1)
go func(updatedService *corev1.Service) {
err := c.client.Update(context.Background(), updatedService)
if err != nil {
c.logger.Errorw("failed to update service",
"error", err,
"service_namespace", modelDeployment.Namespace,
"service_name", updatedService.GetName(),
"deployment_id", modelDeployment.GetId(),
)
}
wg.Done()
}(updatedService)
} else {
if c.statusCache.Get(modelDeployment.Id).Service != status.StatusReady {
c.statusCache.Set(modelDeployment.Id, status.ModuleService, status.StatusReady)
}
}
}
```
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: cf9c00239111686572d242d57742f0878e847562
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.