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

markshuttle/juju-lostandfound: caas/kubernetes/provider/k8s.go; 66 LoC

Open
#11,461 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 [markshuttle/juju-lostandfound](https://www.github.com/markshuttle/juju-lostandfound) at [caas/kubernetes/provider/k8s.go](https://github.com/markshuttle/juju-lostandfound/blob/49d8394d9cbfb2e216b0cb41873b9eeb134a8a43/caas/kubernetes/provider/k8s.go#L2099-L2164)

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 p was used in a composite literal at line 2112

[Click here to see the code in its original context.](https://github.com/markshuttle/juju-lostandfound/blob/49d8394d9cbfb2e216b0cb41873b9eeb134a8a43/caas/kubernetes/provider/k8s.go#L2099-L2164)

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

```go
for _, p := range podsList.Items {
var ports []string
for _, c := range p.Spec.Containers {
for _, p := range c.Ports {
ports = append(ports, fmt.Sprintf("%v/%v", p.ContainerPort, p.Protocol))
}
}
terminated := p.DeletionTimestamp != nil
statusMessage, unitStatus, since, err := k.getPODStatus(p, now)
if err != nil {
return nil, errors.Trace(err)
}
unitInfo := caas.Unit{
Id: providerID(&p),
Address: p.Status.PodIP,
Ports: ports,
Dying: terminated,
Stateful: isStateful(&p),
Status: status.StatusInfo{
Status: unitStatus,
Message: statusMessage,
Since: &since,
},
}

volumesByName := make(map[string]core.Volume)
for _, pv := range p.Spec.Volumes {
volumesByName[pv.Name] = pv
}

// Gather info about how filesystems are attached/mounted to the pod.
// The mount name represents the filesystem tag name used by Juju.
for _, volMount := range p.Spec.Containers[0].VolumeMounts {
vol, ok := volumesByName[volMount.Name]
if !ok {
logger.Warningf("volume for volume mount %q not found", volMount.Name)
continue
}
var fsInfo *caas.FilesystemInfo
if vol.PersistentVolumeClaim != nil && vol.PersistentVolumeClaim.ClaimName != "" {
fsInfo, err = k.volumeInfoForPVC(vol, volMount, vol.PersistentVolumeClaim.ClaimName, now)
} else if vol.EmptyDir != nil {
fsInfo, err = k.volumeInfoForEmptyDir(vol, volMount, now)
} else {
// Ignore volumes which are not Juju managed filesystems.
logger.Debugf("ignoring blank EmptyDir, PersistentVolumeClaim or ClaimName")
continue
}
if err != nil {
return nil, errors.Annotatef(err, "finding filesystem info for %v", volMount.Name)
}
if fsInfo == nil {
continue
}
if fsInfo.StorageName == "" {
if valid := constants.LegacyPVNameRegexp.MatchString(volMount.Name); valid {
fsInfo.StorageName = constants.LegacyPVNameRegexp.ReplaceAllString(volMount.Name, "$storageName")
} else if valid := constants.PVNameRegexp.MatchString(volMount.Name); valid {
fsInfo.StorageName = constants.PVNameRegexp.ReplaceAllString(volMount.Name, "$storageName")
}
}
logger.Debugf("filesystem info for %v: %+v", volMount.Name, *fsInfo)
unitInfo.FilesystemInfo = append(unitInfo.FilesystemInfo, *fsInfo)
}
units = append(units, unitInfo)
}

```

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: 49d8394d9cbfb2e216b0cb41873b9eeb134a8a43

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.