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

Cannot create multiple Grafana in the same namespace. #174

Closed
dulltz opened this issue Apr 28, 2020 · 14 comments
Closed

Cannot create multiple Grafana in the same namespace. #174

dulltz opened this issue Apr 28, 2020 · 14 comments
Labels
feature-request requests a new feature that currently isn't implemented in the project triage/accepted Indicates an issue or PR is ready to be actively worked on. v5 A v5 specifc issue/feature
Milestone

Comments

@dulltz
Copy link

dulltz commented Apr 28, 2020

I tried to create multiple Grafana CRs in the same namesapce.
However, the generated resource names are duplicated since they are hard-coded such as grafana-service or grafana-admin-credentials.
As a result of it, I failed to create multiple Grafana CR on the same namesapce.

I think we should support multiple Grafana in the same namespace.
If grafana-operator builds resource names as ${grafana-name}-${resource-name}, this issue would be solved.

@dulltz
Copy link
Author

dulltz commented Apr 30, 2020

Moreover, it seems that grafana-operator cannot detect Grafana CRs in namespaces except for grafana-operator's namespace. (ref)

As a result of them, grafana-operator can deploy single grafana only, is it true?

@rverma-jm
Copy link

Facing issue cause of this, it would be nice if we can support a different namespace for grafana. Its alright(even preferred) to place data sources in same namespace as in grafana.

@HVBE
Copy link
Collaborator

HVBE commented Jun 26, 2020

@dulltz @rverma-jm There's some planned work involving the ability for Grafana's to be managed by operators from different namespaces coming up soon, Not sure of the timeframe though so I can't give a definite "When".

@dulltz
Copy link
Author

dulltz commented Jul 1, 2020

@HubertStefanski
Thank you for your reply.
By the way, where is the future development plan of grafana-operator being mainly discussed?
I would like to see it if possible.

@HVBE
Copy link
Collaborator

HVBE commented Jul 1, 2020

@dulltz Most of this planning for now is done internally as part of the development process for the Integreatly-Operator, as needs arise for functionality we delegate to work on the grafana-operator, we are actively ensuring that we take in a few issues for the grafana-operator in each sprint to keep it moving forward.
As of now I'm not sure if there are any external documents/places where work is being planned, but perhaps this is something to consider? @pb82

@pb82
Copy link
Collaborator

pb82 commented Jul 1, 2020

@dulltz @HubertStefanski Yes, currently the development of this operator is mainly discussed via Github issues and in our internal chat rooms. We can consider creating a google group for it.

@dulltz
Copy link
Author

dulltz commented Jul 2, 2020

@HubertStefanski @pb82
Thank you for your responce. I got the workflow of Integreatly-Operator a little.

We can consider creating a google group for it.

I'm concerned that running a Google Group will be too costly for the core members.
If the core members are not troubled at the moment, I think the current GitHub Issue-based development is fine.

@NissesSenap
Copy link
Collaborator

Any update on this?

@pb82
Copy link
Collaborator

pb82 commented Feb 9, 2021

@NissesSenap @dulltz We are working on publishing a roadmap, but it will still take some time. Multi namespace support is considered, but probably not one of the top priorities from our side (although we certainly will accept community pull requests for this).

@pb82 pb82 closed this as completed Feb 9, 2021
@pb82 pb82 reopened this Feb 9, 2021
@pb82 pb82 added feature-request requests a new feature that currently isn't implemented in the project triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Feb 9, 2021
@HVBE HVBE added this to the pre-req for multi namespace/instance grafana milestone Feb 23, 2021
@d-kuro
Copy link

d-kuro commented Mar 21, 2021

I'd like to address this issue.

As for running multiple Grafana in the same namespace, I believe that this can be easily solved by not creating resources with fixed names and prefixing them with the .metadata.name of the Grafana resource.

e.g.:

  func GrafanaDeployment(cr *v1alpha1.Grafana, configHash, dsHash string) *v1.Deployment {
	  return &v1.Deployment{
		  ObjectMeta: v12.ObjectMeta{
-			  Name:      GrafanaDeploymentName,
+			  Name:      fmt.Sprintf("%s-%s", cr.Name, GrafanaDeploymentName),
			  Namespace: cr.Namespace,
		  },
		  Spec: getDeploymentSpec(cr, nil, configHash, "", dsHash),
	  }
  }

https://github.com/integr8ly/grafana-operator/blob/v3.9.0/pkg/controller/model/grafanaDeployment.go#L561

However, there is a problem with the GrafanaDataSource resource.

The current logic looks like this (If I’m wrong, please comment):

  1. Grafana datasource config file is located in a ConfigMap named grafana-datasources.
  2. grafana-datasources ConfgMap is created by Grafana controller.
  3. In the reconciliation loop for GrafanaDataSource, refer to the ConfigMap with the fixed name grafana-datasources and write the Grafana datasource config file.

If you prefix grafana-datasource ConfigMap with the name of Grafana object, you will not be able to find ConfigMap in the reconciliation loop of GrafanaDataSource with the logic as it is.

Also, the GrafanaDashboard and GrafanaDataSource resources share the state of the Grafana controller in the ControllerState struct.
This struct is currently designed to manage only one Grafana, so multiple Grafanas cannot be managed.

I think grafana-operator is currently used by many companies, so we have to be careful about breaking changes.


I consider this to be a difficult and complex issue.
I think the solution with minimal changes is that the ReconcileGrafanaDashboard and ReconcileGrafanaDataSource have multiple ControllerState. (Alternatively, you may want to stop keeping the state in a structure and use the API to get it every time. Can consider storing the information needed to construct the ControllerState structure in the Grafana Object status.)
And add a new field to the Grafana CRD.

  dashboardLabelSelectors:
    type: array
    items:
      type: object
      description: Label selector or match expressions
+ datasourceLabelSelectors:
+   type: array
+   items:
+     type: object
+     description: Label selector or match expressions

GrafanaDashboard and GrafanaDataSource controllers refer to the labelselector of the multiple Grafana objects they hold, determine the match, and execute the process. (This can be may inefficient)

Do you have any other good ideas for this?

@d-kuro
Copy link

d-kuro commented Mar 31, 2021

We had a conversation in the Kubernetes Slack thread:
https://kubernetes.slack.com/archives/C019A1KTYKC/p1616416376015000

@d-kuro
Copy link

d-kuro commented Apr 11, 2021

I have created a PoC for architectural changes in grafana-operator to solve this problem:
https://github.com/d-kuro/grafana-operator/pull/1

@pb82
Copy link
Collaborator

pb82 commented Jul 13, 2021

@d-kuro thanks a lot! We'd like to evaluate your PR as soon as we can. This seems to address both issues. Would you mind trying a rebase on latest master on your branch?

@HVBE
Copy link
Collaborator

HVBE commented Mar 14, 2023

Resolved in #919

@HVBE HVBE closed this as completed Mar 14, 2023
Grafana Operator (Kanban) automation moved this from To do to Done Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request requests a new feature that currently isn't implemented in the project triage/accepted Indicates an issue or PR is ready to be actively worked on. v5 A v5 specifc issue/feature
Development

No branches or pull requests

6 participants