Skip to content

Commit

Permalink
fix(deployment reconciler): Couldn't parse image reference "docker.io…
Browse files Browse the repository at this point in the history
…/grafana/[email protected]" (#1320)

* use ':' for deployment image tag delimiter
* rename 'setGrafanaImage' to 'getGrafanaImage'

changing verb to 'get' since the function returns a value
  • Loading branch information
sonnyg authored Nov 28, 2023
1 parent 859c184 commit 9261965
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions controllers/reconcilers/grafana/deployment_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,18 @@ func getVolumeMounts(cr *v1beta1.Grafana, scheme *runtime.Scheme) []v1.VolumeMou
return mounts
}

func setGrafanaImage() string {
func getGrafanaImage() string {
grafanaImg := os.Getenv("RELATED_IMAGE_GRAFANA")
if grafanaImg == "" {
grafanaImg = fmt.Sprintf("%s@%s", config2.GrafanaImage, config2.GrafanaVersion)
grafanaImg = fmt.Sprintf("%s:%s", config2.GrafanaImage, config2.GrafanaVersion)
}
return grafanaImg
}

func getContainers(cr *v1beta1.Grafana, scheme *runtime.Scheme, vars *v1beta1.OperatorReconcileVars, openshiftPlatform bool) []v1.Container {
var containers []v1.Container

image := setGrafanaImage()
image := getGrafanaImage()
plugins := model.GetPluginsConfigMap(cr, scheme)

// env var to restart containers if plugins change
Expand Down
23 changes: 23 additions & 0 deletions controllers/reconcilers/grafana/deployment_reconciler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package grafana

import (
"fmt"
"testing"

config2 "github.com/grafana-operator/grafana-operator/v5/controllers/config"

"github.com/stretchr/testify/assert"
)

func Test_getGrafanaImage(t *testing.T) {
expectedDeploymentImage := fmt.Sprintf("%s:%s", config2.GrafanaImage, config2.GrafanaVersion)

assert.Equal(t, expectedDeploymentImage, getGrafanaImage())
}

func Test_getGrafanaImage_withEnvironmentOverride(t *testing.T) {
expectedDeploymentImage := "I want this grafana image"
t.Setenv("RELATED_IMAGE_GRAFANA", expectedDeploymentImage)

assert.Equal(t, expectedDeploymentImage, getGrafanaImage())
}

0 comments on commit 9261965

Please sign in to comment.