Skip to content

Commit

Permalink
Merge pull request #1733 from grafana/fix-related-image-not-used
Browse files Browse the repository at this point in the history
fix: always use related image if it is a hash
  • Loading branch information
theSuess authored Oct 28, 2024
2 parents 37ecd68 + cfc8855 commit 0ad55a7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion controllers/reconcilers/grafana/deployment_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strings"

"github.com/grafana/grafana-operator/v5/api/v1beta1"
config2 "github.com/grafana/grafana-operator/v5/controllers/config"
Expand All @@ -30,6 +31,7 @@ const (
ReadinessProbePeriodSeconds int32 = 10
ReadinessProbeSuccessThreshold int32 = 1
ReadinessProbeTimeoutSeconds int32 = 3
RelatedImageGrafanaEnvVar = "RELATED_IMAGE_GRAFANA"
)

type DeploymentReconciler struct {
Expand All @@ -44,6 +46,10 @@ func NewDeploymentReconciler(client client.Client, isOpenShift bool) reconcilers
}
}

func IsImageSHA256(image string) bool {
return strings.Contains(image, "@sha256:")
}

func (r *DeploymentReconciler) Reconcile(ctx context.Context, cr *v1beta1.Grafana, status *v1beta1.GrafanaStatus, vars *v1beta1.OperatorReconcileVars, scheme *runtime.Scheme) (v1beta1.OperatorStageStatus, error) {
logger := log.FromContext(ctx).WithName("DeploymentReconciler")

Expand Down Expand Up @@ -135,10 +141,15 @@ func getVolumeMounts(cr *v1beta1.Grafana, scheme *runtime.Scheme) []v1.VolumeMou
}

func getGrafanaImage(cr *v1beta1.Grafana) string {
grafanaImg := os.Getenv(RelatedImageGrafanaEnvVar)
if IsImageSHA256(grafanaImg) {
return grafanaImg
}

if cr.Spec.Version != "" {
return fmt.Sprintf("%s:%s", config2.GrafanaImage, cr.Spec.Version)
}
grafanaImg := os.Getenv("RELATED_IMAGE_GRAFANA")

if grafanaImg == "" {
grafanaImg = fmt.Sprintf("%s:%s", config2.GrafanaImage, config2.GrafanaVersion)
}
Expand Down

0 comments on commit 0ad55a7

Please sign in to comment.