Skip to content

Commit

Permalink
refactor: Remove useless HasAParentFolder method and fix description …
Browse files Browse the repository at this point in the history
…of ParentFolderUID field
  • Loading branch information
aboulay-numspot committed Jun 21, 2024
1 parent 45107ba commit 6054405
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
6 changes: 1 addition & 5 deletions api/v1beta1/grafanafolder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type GrafanaFolderSpec struct {
// +optional
AllowCrossNamespaceImport *bool `json:"allowCrossNamespaceImport,omitempty"`

// find parent folder where the folder will be created with it UID value
// UID of the folder in which the current folder should be created
// +optional
ParentFolderUID string `json:"parentFolderUID,omitempty"`

Expand Down Expand Up @@ -149,7 +149,3 @@ func (in *GrafanaFolder) ResyncPeriodHasElapsed() bool {
deadline := in.Status.LastResync.Add(in.GetResyncPeriod())
return time.Now().After(deadline)
}

func (in *GrafanaFolder) HasAParentFolder() bool {
return in.Spec.ParentFolderUID != ""
}
2 changes: 2 additions & 0 deletions config/crd/bases/grafana.integreatly.org_grafanafolders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ spec:
- message: Value is immutable
rule: self == oldSelf
parentFolderUID:
description: UID of the folder in which the current folder should
be created
type: string
permissions:
description: raw json with folder permissions
Expand Down
15 changes: 6 additions & 9 deletions controllers/grafanafolder_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,11 @@ func (r *GrafanaFolderReconciler) onFolderCreated(ctx context.Context, grafana *
}
} else {
body := &models.CreateFolderCommand{
Title: title,
UID: uid,
}
if cr.HasAParentFolder() {
body.ParentUID = cr.Spec.ParentFolderUID
Title: title,
UID: uid,
ParentUID: cr.Spec.ParentFolderUID,
}

folderResp, err := grafanaClient.Folders.CreateFolder(body)
if err != nil {
return err
Expand Down Expand Up @@ -376,10 +375,8 @@ func (r *GrafanaFolderReconciler) Exists(client *genapi.GrafanaHTTPAPI, cr *graf
page := int64(1)
limit := int64(10000)
for {
params := folders.NewGetFoldersParams().WithPage(&page).WithLimit(&limit)
if cr.HasAParentFolder() {
params.WithParentUID(&cr.Spec.ParentFolderUID)
}
params := folders.NewGetFoldersParams().WithPage(&page).WithLimit(&limit).WithParentUID(&cr.Spec.ParentFolderUID)

foldersResp, err := client.Folders.GetFolders(params)
if err != nil {
return false, "", err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ spec:
- message: Value is immutable
rule: self == oldSelf
parentFolderUID:
description: UID of the folder in which the current folder should
be created
type: string
permissions:
description: raw json with folder permissions
Expand Down
2 changes: 2 additions & 0 deletions deploy/kustomize/base/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,8 @@ spec:
- message: Value is immutable
rule: self == oldSelf
parentFolderUID:
description: UID of the folder in which the current folder should
be created
type: string
permissions:
description: raw json with folder permissions
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ GrafanaFolderSpec defines the desired state of GrafanaFolder
<td><b>parentFolderUID</b></td>
<td>string</td>
<td>
find parent folder where the folder will be created with it UID value<br/>
UID of the folder in which the current folder should be created<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down

0 comments on commit 6054405

Please sign in to comment.