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

flanksource/karina: pkg/provision/vsphere.go; 44 LoC

Open
#12,849 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 [flanksource/karina](https://www.github.com/flanksource/karina) at [pkg/provision/vsphere.go](https://github.com/flanksource/karina/blob/8b3a429f18c7121025763f5a20bd77149f104b0d/pkg/provision/vsphere.go#L123-L166)

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 nodeGroup used in defer or goroutine at line 156

[Click here to see the code in its original context.](https://github.com/flanksource/karina/blob/8b3a429f18c7121025763f5a20bd77149f104b0d/pkg/provision/vsphere.go#L123-L166)

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

```go
for nodeGroup, worker := range platform.Nodes {
vms, err := platform.Cluster.GetMachinesFor(&worker)
if err != nil {
return err
}
missing := []string{}
for _, vm := range vms {
if _, ok := existingNodes[vm.Name()]; !ok {
missing = append(missing, vm.Name())
}
}
for _, m := range missing {
platform.Errorf("vm did not join kubernetes cluster: %s", m)
delete(vms, m)
}

for i := 0; i < worker.Count-len(vms); i++ {
time.Sleep(1 * time.Second)
wg.Add(1)
_nodeGroup := nodeGroup
annotations := worker.Annotations
go func() {
defer wg.Done()
if w, err := createWorker(platform, _nodeGroup); err != nil {
platform.Errorf("Failed to provision worker %v", err)
} else {
if err := waitForNode(platform, w.Name(), burninPeriod); err != nil {
platform.Errorf("%s did not come up healthy, it may need to be re-provisioned %v", w.Name(), err)
} else {
if err := addNodeAnnotations(platform, w.Name(), annotations); err != nil {
platform.Errorf("failed to add annotations to worker %s: %v", w.Name(), err)
}
labels := map[string]string{
constants.NodePoolLabel: nodeGroup,
}
if err := addNodeLabels(platform, w.Name(), labels); err != nil {
platform.Errorf("failed to add labels to worker: %s: %v", w.Name(), err)
}
}
}
}()
}
wg.Wait()
}

```

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: 8b3a429f18c7121025763f5a20bd77149f104b0d

Contributor guide

No contributing guide indexed for this repository

Research direction

Read pkg/provision/vsphere.go around lines 123-166, starting with the range over platform.Nodes and the goroutine that provisions workers. Verify which node-group value is used when the goroutine adds labels, then confirm the provisioning behavior no longer associates a worker with the wrong group.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.