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

grafana-operator: fix status of Grafana resources during reconciliation #1430

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions grafana-operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
FROM ghcr.io/cybozu/golang:1.22-jammy AS build
ARG VERSION=5.10.0

# After https://github.com/grafana/grafana-operator/issues/1678 is resolved,
# this patch will not be needed.
COPY grafana-status-fix.patch /work

WORKDIR /work/grafana-operator
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

Expand All @@ -13,6 +17,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# https://github.com/grafana-operator/grafana-operator/blob/master/.gitmodules
RUN git clone --depth 1 --single-branch -b v${VERSION} https://github.com/grafana/grafana-operator.git .
RUN git submodule update --init --recursive --recommend-shallow --depth 1
RUN patch -p1 < ../grafana-status-fix.patch
RUN CGO_ENABLED=0 GO111MODULE=on go build -o /usr/local/bin/grafana-operator main.go

# Stage2: setup runtime container
Expand Down
2 changes: 1 addition & 1 deletion grafana-operator/TAG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.10.0.1
5.10.0.2
44 changes: 44 additions & 0 deletions grafana-operator/grafana-status-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/controllers/dashboard_controller.go b/controllers/dashboard_controller.go
index 1bd4b466..39a6781f 100644
--- a/controllers/dashboard_controller.go
+++ b/controllers/dashboard_controller.go
@@ -398,6 +398,11 @@ func (r *GrafanaDashboardReconciler) onDashboardCreated(ctx context.Context, gra
}

if exists && cr.Unchanged(hash) && !cr.ResyncPeriodHasElapsed() {
+ if found, _ := grafana.Status.Dashboards.Find(cr.Namespace, cr.Name); !found {
+ r.Log.Info("fixing inconsistent Grafana.status.dashboards filed", "grafana", map[string]string{"name": grafana.Name, "namespace": grafana.Namespace})
+ grafana.Status.Dashboards = grafana.Status.Dashboards.Add(cr.Namespace, cr.Name, uid)
+ return r.Client.Status().Update(ctx, grafana)
+ }
return nil
}

@@ -407,6 +412,11 @@ func (r *GrafanaDashboardReconciler) onDashboardCreated(ctx context.Context, gra
}

if !remoteChanged {
+ if found, _ := grafana.Status.Dashboards.Find(cr.Namespace, cr.Name); !found {
+ r.Log.Info("fixing inconsistent Grafana.status.dashboards filed", "grafana", map[string]string{"name": grafana.Name, "namespace": grafana.Namespace})
+ grafana.Status.Dashboards = grafana.Status.Dashboards.Add(cr.Namespace, cr.Name, uid)
+ return r.Client.Status().Update(ctx, grafana)
+ }
return nil
}

diff --git a/controllers/datasource_controller.go b/controllers/datasource_controller.go
index cdf4e7ce..4f5753a7 100644
--- a/controllers/datasource_controller.go
+++ b/controllers/datasource_controller.go
@@ -335,6 +335,11 @@ func (r *GrafanaDatasourceReconciler) onDatasourceCreated(ctx context.Context, g
}

if exists && cr.Unchanged(hash) && !cr.ResyncPeriodHasElapsed() {
+ if found, _ := grafana.Status.Datasources.Find(cr.Namespace, cr.Name); !found {
+ r.Log.Info("fixing inconsistent Grafana.status.datasources filed", "grafana", map[string]string{"name": grafana.Name, "namespace": grafana.Namespace})
+ grafana.Status.Datasources = grafana.Status.Datasources.Add(cr.Namespace, cr.Name, datasource.UID)
+ return r.Client.Status().Update(ctx, grafana)
+ }
return nil
}

Loading