github-vet / github-vet/rangeloop-pointer-findings

longhorn/longhorn-manager: upgrade/v070to080/upgrade.go; 33 LoC

Open
#11,606 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [longhorn/longhorn-manager](https://www.github.com/longhorn/longhorn-manager) at [upgrade/v070to080/upgrade.go](https://github.com/longhorn/longhorn-manager/blob/24300a52841e7f66b6568e05c327b2797df8abca/upgrade/v070to080/upgrade.go#L70-L102)

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 im is reassigned at line 74

[Click here to see the code in its original context.](https://github.com/longhorn/longhorn-manager/blob/24300a52841e7f66b6568e05c327b2797df8abca/upgrade/v070to080/upgrade.go#L70-L102)

Click here to show the 33 line(s) of Go which triggered the analyzer.

```go
for _, im := range imList.Items {
if im.Spec.Image != "" {
continue
}
im := &im
if types.ValidateEngineImageChecksumName(im.Spec.EngineImage) {
ei, err := lhClient.LonghornV1beta1().EngineImages(namespace).Get(im.Spec.EngineImage, metav1.GetOptions{})
if err != nil {
return errors.Wrapf(err, upgradeLogPrefix+"failed to find out the related engine image %v during the instance managers upgrade", im.Spec.EngineImage)
}
im.Spec.EngineImage = ei.Spec.Image
}
im.Spec.Image = im.Spec.EngineImage
node, exist := nodeMap[im.Spec.NodeID]
if !exist {
return fmt.Errorf(upgradeLogPrefix+"cannot to find node %v for instance manager %v during the instance manager upgrade", im.Spec.NodeID, im.Name)
}
metadata, err := meta.Accessor(im)
if err != nil {
return err
}
metadata.SetOwnerReferences(datastore.GetOwnerReferencesForNode(&node))
metadata.SetLabels(types.GetInstanceManagerLabels(im.Spec.NodeID, im.Spec.Image, im.Spec.Type))
if im, err = lhClient.LonghornV1beta1().InstanceManagers(namespace).Update(im); err != nil {
return errors.Wrapf(err, upgradeLogPrefix+"failed to update the spec for instance manager %v during the instance managers upgrade", im.Name)
}

im.Status.APIMinVersion = engineapi.IncompatibleInstanceManagerAPIVersion
im.Status.APIVersion = engineapi.IncompatibleInstanceManagerAPIVersion
if _, err = lhClient.LonghornV1beta1().InstanceManagers(namespace).UpdateStatus(im); err != nil {
return errors.Wrapf(err, upgradeLogPrefix+"failed to update the version status for instance manager %v during the instance managers upgrade", im.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: 24300a52841e7f66b6568e05c327b2797df8abca

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.