From 98550122a82dc255db760e6678b442b520d2bf67 Mon Sep 17 00:00:00 2001 From: Pavel Timofeev Date: Wed, 3 Jul 2024 09:59:51 -0600 Subject: [PATCH 1/2] fix: use correct folder uid to update permissions --- controllers/grafanafolder_controller.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/controllers/grafanafolder_controller.go b/controllers/grafanafolder_controller.go index 0653f121e..c25e994ff 100644 --- a/controllers/grafanafolder_controller.go +++ b/controllers/grafanafolder_controller.go @@ -389,7 +389,12 @@ func (r *GrafanaFolderReconciler) onFolderCreated(ctx context.Context, grafana * return fmt.Errorf("failed to unmarshal spec.permissions: %w", err) } - _, err = grafanaClient.FolderPermissions.UpdateFolderPermissions(uid, &permissions) //nolint + targetUID := uid + if exists { + targetUID = remoteUID + } + + _, err = grafanaClient.FolderPermissions.UpdateFolderPermissions(targetUID, &permissions) //nolint if err != nil { return fmt.Errorf("failed to update folder permissions: %w", err) } From 36954161a3e7d08b90b569a4393ee665c2a5ca81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=BC=C3=9F?= Date: Thu, 4 Jul 2024 09:32:47 +0200 Subject: [PATCH 2/2] refactor: move uid reassignment to existing conditional --- controllers/grafanafolder_controller.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/controllers/grafanafolder_controller.go b/controllers/grafanafolder_controller.go index c25e994ff..74504d6ad 100644 --- a/controllers/grafanafolder_controller.go +++ b/controllers/grafanafolder_controller.go @@ -332,6 +332,8 @@ func (r *GrafanaFolderReconciler) onFolderCreated(ctx context.Context, grafana * } if exists { + // make sure we use the correct UID + uid = remoteUID // Add to status to cover cases: // - operator have previously failed to update status // - the folder was created outside of operator @@ -389,12 +391,7 @@ func (r *GrafanaFolderReconciler) onFolderCreated(ctx context.Context, grafana * return fmt.Errorf("failed to unmarshal spec.permissions: %w", err) } - targetUID := uid - if exists { - targetUID = remoteUID - } - - _, err = grafanaClient.FolderPermissions.UpdateFolderPermissions(targetUID, &permissions) //nolint + _, err = grafanaClient.FolderPermissions.UpdateFolderPermissions(uid, &permissions) //nolint if err != nil { return fmt.Errorf("failed to update folder permissions: %w", err) }