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

kubermatic/kubecarrier: pkg/manager/internal/controllers/catalog_controller.go; 32 LoC

Open
#17,614 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 [kubermatic/kubecarrier](https://www.github.com/kubermatic/kubecarrier) at [pkg/manager/internal/controllers/catalog_controller.go](https://github.com/kubermatic/kubecarrier/blob/ac365a64b86530cc88c22ea27d3663b98f144ff6/pkg/manager/internal/controllers/catalog_controller.go#L534-L565)

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 desiredOffering is reassigned at line 552

[Click here to see the code in its original context.](https://github.com/kubermatic/kubecarrier/blob/ac365a64b86530cc88c22ea27d3663b98f144ff6/pkg/manager/internal/controllers/catalog_controller.go#L534-L565)

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

```go
for _, desiredOffering := range desiredOfferings {
if _, err := multiowner.InsertOwnerReference(catalog, &desiredOffering, r.Scheme); err != nil {
return fmt.Errorf("inserting OwnerReference: %w", err)
}

foundOffering := &catalogv1alpha1.Offering{}
err := r.Get(ctx, types.NamespacedName{
Name: desiredOffering.Name,
Namespace: desiredOffering.Namespace,
}, foundOffering)
if err != nil && !errors.IsNotFound(err) {
return fmt.Errorf("getting Offering: %w", err)
}
if errors.IsNotFound(err) {
// Create the Offering.
if err := r.Create(ctx, &desiredOffering); err != nil {
return fmt.Errorf("creating Offering: %w", err)
}
foundOffering = &desiredOffering
}

ownerChanged, err := multiowner.InsertOwnerReference(catalog, foundOffering, r.Scheme)
if err != nil {
return fmt.Errorf("inserting OwnerReference: %w", err)
}
if !reflect.DeepEqual(desiredOffering.Spec, foundOffering.Spec) || ownerChanged {
foundOffering.Spec = desiredOffering.Spec
if err := r.Update(ctx, foundOffering); err != nil {
return fmt.Errorf("updaing Offering: %w", err)
}
}
}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Read pkg/manager/internal/controllers/catalog_controller.go around lines 534-565 and inspect how the range variable desiredOffering is referenced and reassigned. Determine whether the analyzer finding represents a bug, mitigated behavior, or desirable behavior, then classify it using the corresponding reaction on the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.