From 9261965be0bca9007d64e934545debd3c73816c2 Mon Sep 17 00:00:00 2001 From: Sonny <355656+sonnyg@users.noreply.github.com> Date: Tue, 28 Nov 2023 06:59:02 -0500 Subject: [PATCH] fix(deployment reconciler): Couldn't parse image reference "docker.io/grafana/grafana@9.1.6" (#1320) * use ':' for deployment image tag delimiter * rename 'setGrafanaImage' to 'getGrafanaImage' changing verb to 'get' since the function returns a value --- .../grafana/deployment_reconciler.go | 6 ++--- .../grafana/deployment_reconciler_test.go | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 controllers/reconcilers/grafana/deployment_reconciler_test.go diff --git a/controllers/reconcilers/grafana/deployment_reconciler.go b/controllers/reconcilers/grafana/deployment_reconciler.go index a57bc9569..972422635 100644 --- a/controllers/reconcilers/grafana/deployment_reconciler.go +++ b/controllers/reconcilers/grafana/deployment_reconciler.go @@ -133,10 +133,10 @@ 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 } @@ -144,7 +144,7 @@ func setGrafanaImage() string { 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 diff --git a/controllers/reconcilers/grafana/deployment_reconciler_test.go b/controllers/reconcilers/grafana/deployment_reconciler_test.go new file mode 100644 index 000000000..786457f86 --- /dev/null +++ b/controllers/reconcilers/grafana/deployment_reconciler_test.go @@ -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()) +}