github-vet / github-vet/rangeloop-pointer-findings
dotmesh-io/ds-deployer: internal/controller/deployment_controller.go; 63 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/deployment_controller.go](https://github.com/dotmesh-io/ds-deployer/blob/cf9c00239111686572d242d57742f0878e847562/internal/controller/deployment_controller.go#L29-L91)
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 75
[Click here to see the code in its original context.](https://github.com/dotmesh-io/ds-deployer/blob/cf9c00239111686572d242d57742f0878e847562/internal/controller/deployment_controller.go#L29-L91)
Click here to show the 63 line(s) of Go which triggered the analyzer.
```go
for _, modelDeployment := range c.cache.ModelDeployments() {
existing, ok := c.cache.GetDeployment(modelDeployment.Namespace, getDeploymentName(modelDeployment))
if !ok {
// updating status cache
if c.statusCache.Get(modelDeployment.Id).Deployment == status.StatusConfiguring {
c.statusCache.Set(modelDeployment.Id, status.ModuleDeployment, status.StatusConfiguring)
}
wg.Add(1)
// creating new deployment
go func(modelDeployment *deployer_v1.Deployment) {
err := c.createDeployment(modelDeployment)
if err != nil {
c.logger.Errorw("failed to create deployment",
"error", err,
"deployment_id", modelDeployment.GetId(),
)
}
wg.Done()
}(modelDeployment)
// should get created if it doesn't exist
continue
}
c.logger.Debugf("deployment %s/%s found, checking for updates", existing.Namespace, existing.Name)
if !deploymentsEqual(toKubernetesDeployment(modelDeployment, c.controllerIdentifier), existing) {
c.logger.Debugf("deployment %s/%s needs updating", existing.Namespace, existing.Name)
// updating status cache
deploymentStatus := c.statusCache.Get(modelDeployment.Id)
if deploymentStatus.Deployment != status.StatusConfiguring {
c.statusCache.Set(modelDeployment.Id, status.ModuleDeployment, status.StatusConfiguring)
}
if deploymentStatus.AvailableReplicas != int64(existing.Status.AvailableReplicas) {
c.statusCache.SetAvailableReplicas(modelDeployment.GetId(), int64(existing.Status.AvailableReplicas))
}
updatedDeployment := updateDeployment(existing, modelDeployment)
wg.Add(1)
go func(updatedDeployment *appsv1.Deployment) {
err := c.client.Update(context.Background(), updatedDeployment)
if err != nil {
c.logger.Errorw("failed to update deployment via k8s client",
"error", err,
"deployment_id", modelDeployment.GetId(),
)
}
wg.Done()
}(updatedDeployment)
} else {
// deployment is in sync
deploymentStatus := c.statusCache.Get(modelDeployment.Id)
if deploymentStatus.Deployment != status.StatusReady {
c.statusCache.Set(modelDeployment.Id, status.ModuleDeployment, status.StatusReady)
}
if deploymentStatus.AvailableReplicas != int64(existing.Status.AvailableReplicas) {
c.statusCache.SetAvailableReplicas(modelDeployment.GetId(), int64(existing.Status.AvailableReplicas))
}
}
}
```
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.