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

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

Open
#17,611 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#L578-L609)

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 desiredProvider is reassigned at line 596

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

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

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

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

ownerChanged, err := multiowner.InsertOwnerReference(catalog, foundProvider, r.Scheme)
if err != nil {
return fmt.Errorf("inserting OwnerReference: %w", err)
}
if !reflect.DeepEqual(desiredProvider.Spec, foundProvider.Spec) || ownerChanged {
foundProvider.Spec = desiredProvider.Spec
if err := r.Update(ctx, foundProvider); err != nil {
return fmt.Errorf("updaing Provider: %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 578-609 and review the linked classification descriptions. Check the Go range-loop pointer behavior involving desiredProvider and whether it can affect Provider creation or updates across iterations. Classify the finding as Bug, Mitigated, or Desirable Behavior with the corresponding reaction.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.