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

goodrain/rainbond: worker/master/volumes/provider/rainbondsslc.go; 59 LoC

Open
#6,317 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [goodrain/rainbond](https://www.github.com/goodrain/rainbond) at [worker/master/volumes/provider/rainbondsslc.go](https://github.com/goodrain/rainbond/blob/513ed524893ea9f12e801230f55f39f701cca3f2/worker/master/volumes/provider/rainbondsslc.go#L71-L129)

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 node is reassigned at line 118

[Click here to see the code in its original context.](https://github.com/goodrain/rainbond/blob/513ed524893ea9f12e801230f55f39f701cca3f2/worker/master/volumes/provider/rainbondsslc.go#L71-L129)

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

```go
for _, node := range allnode.Items {
nodeReady := false
if node.Labels[client.LabelOS] != nodeOS {
continue
}

// filter out ignore nodes
if strings.Contains(ignore, node.Name) {
logrus.Debugf("[rainbondsslcProvisioner] [selectNode] ignore node %s based on %s", node.Name, ignore)
continue
}

for _, condition := range node.Status.Conditions {
if condition.Type == v1.NodeReady {
nodeReady = true
if condition.Status == v1.ConditionTrue {
ip := ""
for _, address := range node.Status.Addresses {
if address.Type == v1.NodeInternalIP {
ip = address.Address
break
}
}
if ip == "" {
logrus.Warningf("Node: %s; node internal address not found", node.Name)
break
}
//only contains rainbond pod
//pods, err := p.store.GetPodLister().Pods(v1.NamespaceAll).List(labels.NewSelector())
pods, err := p.kubecli.CoreV1().Pods(v1.NamespaceAll).List(metav1.ListOptions{
FieldSelector: "spec.nodeName=" + node.Name,
})
if err != nil {
logrus.Errorf("list pods list from node ip error %s", err.Error())
break
}
var nodeUsedMemory int64
for _, pod := range pods.Items {
for _, con := range pod.Spec.Containers {
memory := con.Resources.Requests.Memory()
nodeUsedMemory += memory.Value()
}
}
available := node.Status.Allocatable.Memory().Value() - nodeUsedMemory
if available >= maxavailable {
logrus.Infof("select node: %s", node.Name)
maxavailable = available
selectnode = &node
} else {
logrus.Infof("Node: %s; node available memory(%d) is less than max available "+
"memory(%d)", node.Name, available, maxavailable)
}
}
}
}
if !nodeReady {
logrus.Warningf("Node: %s; not ready", node.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: 513ed524893ea9f12e801230f55f39f701cca3f2

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.