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

integr8ly/grafana-operator: pkg/controller/grafanadashboard/dashboard_controller.go; 69 LoC

Open
#6,268 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 [integr8ly/grafana-operator](https://www.github.com/integr8ly/grafana-operator) at [pkg/controller/grafanadashboard/dashboard_controller.go](https://github.com/integr8ly/grafana-operator/blob/5472984c528dbd53e0ca3c50b7480eb6d32ec3d0/pkg/controller/grafanadashboard/dashboard_controller.go#L237-L305)

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.

> function call at line 254 may store a reference to dashboard

[Click here to see the code in its original context.](https://github.com/integr8ly/grafana-operator/blob/5472984c528dbd53e0ca3c50b7480eb6d32ec3d0/pkg/controller/grafanadashboard/dashboard_controller.go#L237-L305)

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

```go
for _, dashboard := range namespaceDashboards.Items {
// Is this a dashboard we care about (matches the label selectors)?
if !r.isMatch(&dashboard) {
log.V(1).Info(fmt.Sprintf("dashboard %v/%v found but selectors do not match",
dashboard.Namespace, dashboard.Name))
continue
}

folderName := dashboard.Namespace
if dashboard.Spec.CustomFolderName != "" {
folderName = dashboard.Spec.CustomFolderName
}

folder, err := grafanaClient.CreateOrUpdateFolder(folderName)

if err != nil {
log.Error(err, fmt.Sprintf("failed to get or create namespace folder %v for dashboard %v", folderName, request.Name))
r.manageError(&dashboard, err)
continue
}

var folderId int64
if folder.ID == nil {
folderId = 0
} else {
folderId = *folder.ID
}

// Process the dashboard. Use the known hash of an existing dashboard
// to determine if an update is required
knownHash := findHash(&dashboard)

pipeline := NewDashboardPipeline(r.client, &dashboard, r.context)
processed, err := pipeline.ProcessDashboard(knownHash, &folderId, folderName)

if err != nil {
log.Error(err, fmt.Sprintf("cannot process dashboard %v/%v", dashboard.Namespace, dashboard.Name))
r.manageError(&dashboard, err)
continue
}

if processed == nil {
r.config.SetPluginsFor(&dashboard)
continue
}
// Check labels only when DashboardNamespaceSelector isnt empty
if r.state.DashboardNamespaceSelector != nil {
matchesNamespaceLabels, err := r.checkNamespaceLabels(&dashboard)
if err != nil {
r.manageError(&dashboard, err)
continue
}

if matchesNamespaceLabels == false {
log.V(1).Info(fmt.Sprintf("dashboard %v skipped because the namespace labels do not match", dashboard.Name))
continue
}
}

_, err = grafanaClient.CreateOrUpdateDashboard(processed, folderId, folderName)
if err != nil {
log.Error(err, fmt.Sprintf("cannot submit dashboard %v/%v", dashboard.Namespace, dashboard.Name))
r.manageError(&dashboard, err)

continue
}

r.manageSuccess(&dashboard, &folderId, folderName)
}

```

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: 5472984c528dbd53e0ca3c50b7480eb6d32ec3d0

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.