Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always use related image if it is a hash #1733

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading