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

improbable-eng/etcd-cluster-operator: controllers/etcdcluster_controller.go; 27 LoC

Open
#13,036 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 [improbable-eng/etcd-cluster-operator](https://www.github.com/improbable-eng/etcd-cluster-operator) at [controllers/etcdcluster_controller.go](https://github.com/improbable-eng/etcd-cluster-operator/blob/f84abc6561735814debd67d45bb62d2d2ed8cf4a/controllers/etcdcluster_controller.go#L379-L405)

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

[Click here to see the code in its original context.](https://github.com/improbable-eng/etcd-cluster-operator/blob/f84abc6561735814debd67d45bb62d2d2ed8cf4a/controllers/etcdcluster_controller.go#L379-L405)

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

```go
for _, peer := range peers.Items {
if !memberNames.Has(peer.Name) {
if !peer.DeletionTimestamp.IsZero() {
log.V(2).Info("Peer is already marked for deletion", "peer", peer.Name)
continue
}
if !hasPvcDeletionFinalizer(peer) {
updated := peer.DeepCopy()
controllerutil.AddFinalizer(updated, pvcCleanupFinalizer)
err := r.Patch(ctx, updated, client.MergeFrom(&peer))
if err != nil {
return result, nil, fmt.Errorf("failed to add PVC cleanup finalizer: %w", err)
}
log.V(2).Info("Added PVC cleanup finalizer", "peer", peer.Name)
return result, nil, nil
}
err := r.Delete(ctx, &peer)
if err != nil {
return result, nil, fmt.Errorf("failed to remove peer: %w", err)
}
peerRemovedEvent := &reconcilerevent.PeerRemovedEvent{
Object: &peer,
PeerName: peer.Name,
}
return result, peerRemovedEvent, nil
}
}

```

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: f84abc6561735814debd67d45bb62d2d2ed8cf4a

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.