Skip to content

Commit 241211c

Browse files
feat: Add parentFolderUID in GrafanaFolder CRD
1 parent f64b541 commit 241211c

File tree

7 files changed

+34
-2
lines changed

7 files changed

+34
-2
lines changed

api/v1beta1/grafanafolder_types.go

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ type GrafanaFolderSpec struct {
4444
// +optional
4545
AllowCrossNamespaceImport *bool `json:"allowCrossNamespaceImport,omitempty"`
4646

47+
// find parent folder where the folder will be created with it UID value
48+
// +optional
49+
ParentFolderUID string `json:"parentFolderUID,omitempty"`
50+
4751
// how often the folder is synced, defaults to 5m if not set
4852
// +optional
4953
// +kubebuilder:validation:Type=string
@@ -145,3 +149,7 @@ func (in *GrafanaFolder) ResyncPeriodHasElapsed() bool {
145149
deadline := in.Status.LastResync.Add(in.GetResyncPeriod())
146150
return time.Now().After(deadline)
147151
}
152+
153+
func (in *GrafanaFolder) HasAParentFolder() bool {
154+
return in.Spec.ParentFolderUID != ""
155+
}

config/crd-for-docs-generation/grafana.integreatly.org_grafanafolders.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ spec:
9999
x-kubernetes-validations:
100100
- message: Value is immutable
101101
rule: self == oldSelf
102+
parentFolderUID:
103+
description: find parent folder where the folder will be created with
104+
it UID value
105+
type: string
102106
permissions:
103107
description: raw json with folder permissions
104108
type: string

config/crd/bases/grafana.integreatly.org_grafanafolders.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ spec:
6464
x-kubernetes-validations:
6565
- message: Value is immutable
6666
rule: self == oldSelf
67+
parentFolderUID:
68+
type: string
6769
permissions:
6870
type: string
6971
resyncPeriod:

controllers/grafanafolder_controller.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,14 @@ func (r *GrafanaFolderReconciler) onFolderCreated(ctx context.Context, grafana *
328328
}
329329
}
330330
} else {
331-
folderResp, err := grafanaClient.Folders.CreateFolder(&models.CreateFolderCommand{
331+
body := &models.CreateFolderCommand{
332332
Title: title,
333333
UID: uid,
334-
})
334+
}
335+
if cr.HasAParentFolder() {
336+
body.ParentUID = cr.Spec.ParentFolderUID
337+
}
338+
folderResp, err := grafanaClient.Folders.CreateFolder(body)
335339
if err != nil {
336340
return err
337341
}
@@ -373,6 +377,9 @@ func (r *GrafanaFolderReconciler) Exists(client *genapi.GrafanaHTTPAPI, cr *graf
373377
limit := int64(10000)
374378
for {
375379
params := folders.NewGetFoldersParams().WithPage(&page).WithLimit(&limit)
380+
if cr.HasAParentFolder() {
381+
params.WithParentUID(&cr.Spec.ParentFolderUID)
382+
}
376383
foldersResp, err := client.Folders.GetFolders(params)
377384
if err != nil {
378385
return false, "", err

deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanafolders.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ spec:
6464
x-kubernetes-validations:
6565
- message: Value is immutable
6666
rule: self == oldSelf
67+
parentFolderUID:
68+
type: string
6769
permissions:
6870
type: string
6971
resyncPeriod:

deploy/kustomize/base/crds.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ spec:
861861
x-kubernetes-validations:
862862
- message: Value is immutable
863863
rule: self == oldSelf
864+
parentFolderUID:
865+
type: string
864866
permissions:
865867
type: string
866868
resyncPeriod:

docs/docs/api.md

+7
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,13 @@ GrafanaFolderSpec defines the desired state of GrafanaFolder
24722472
allow to import this resources from an operator in a different namespace<br/>
24732473
</td>
24742474
<td>false</td>
2475+
</tr><tr>
2476+
<td><b>parentFolderUID</b></td>
2477+
<td>string</td>
2478+
<td>
2479+
find parent folder where the folder will be created with it UID value<br/>
2480+
</td>
2481+
<td>false</td>
24752482
</tr><tr>
24762483
<td><b>permissions</b></td>
24772484
<td>string</td>

0 commit comments

Comments
 (0)