grafana / grafana-operator

An operator for Grafana that installs and manages Grafana instances, Dashboards and Datasources through Kubernetes/OpenShift CRs
https://grafana.github.io/grafana-operator/
Apache License 2.0
863 stars 384 forks source link

Add folder UID to grafanaFolder #1599

Closed atos-cosmin-gavagiuc closed 2 months ago

atos-cosmin-gavagiuc commented 2 months ago

Can we specify the folder UID, as optional, when creating the Grafana folder? This way, we can pre-provision the parent folder and use its UID as the parentUID for the child folder.

Otherwise, I fear that the folder UID will be autogenerated and will differ in each Grafana environment.

theSuess commented 2 months ago

Hey, the folder UID will be taken from the kubernetes metadata.uid field. When provisioning from scratch, this will be the same across all instances.

For example:

apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaFolder
metadata:
  name: grafanafolder-sample
  namespace: default
  uid: a4de2d73-0cc1-425f-b9d1-7142e5c6d4bc
spec:
  instanceSelector: {}
  resyncPeriod: 5m
  title: Example Folder

Will use a4de2d73-0cc1-425f-b9d1-7142e5c6d4bc as the UID.

We'll add folderRef to the folder resource next, which will allow you to reference other folder resources without ever having to think about UIDs

For future versions of the resources (https://github.com/grafana/grafana-operator/milestone/4) we can consider a user-provided UID field.

atos-cosmin-gavagiuc commented 2 months ago

metadata

Hey, the folder UID will be taken from the kubernetes metadata.uid field. When provisioning from scratch, this will be the same across all instances.

For example:

apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaFolder
metadata:
  name: grafanafolder-sample
  namespace: default
  uid: a4de2d73-0cc1-425f-b9d1-7142e5c6d4bc
spec:
  instanceSelector: {}
  resyncPeriod: 5m
  title: Example Folder

Will use a4de2d73-0cc1-425f-b9d1-7142e5c6d4bc as the UID.

We'll add folderRef to the folder resource next, which will allow you to reference other folder resources without ever having to think about UIDs

For future versions of the resources (https://github.com/grafana/grafana-operator/milestone/4) we can consider a user-provided UID field.

I was searching through the CRD and couldn't find a way to do that, so this is awesome. Thanks! I'll test it now.

tippl commented 1 month ago

Hello, I've been looking forward to support for nested folders in Grafana Operator, however I'm at a bit of a loss here. I legitimately wonder what is the point of the parentUID if the UID is not user-selectable.

As far as i can tell, metadata.uid is a read-only field that is generated on resource creation, any attempt to manually set it at creation just leads to the manual value being thrown away and replaced by an autogenerated one. This goes from both manually testing it out and the k8s documentation here.

So the only way to create a nested folder now seems to be to create a folder, describe the object and use the UID in creating the nested folder. Also as dashboards do not take a folderUID, there seems to be no way to actually use the operator to create a dashboard in the nested folder...

Please tell me if I'm mistaken in any of this, but my testing seems to match what i wrote. There seems to be no way to actually use this feature.

theSuess commented 1 month ago

We're not quite finished implementing this feature. #1604 will add parentFolderRef in addition to parentFolderUid. This will allow you to reference folders without the need to wait for a UID and enables you to create complex folder structures