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

[Bug] Deployed GrafanaDashboards don't use nameSuffixHashes of ConfigMaps #869

Closed
bergerst opened this issue Jan 16, 2023 · 4 comments
Closed
Labels
bug Something isn't working triage/needs-information Indicates an issue needs more information in order to work on it.

Comments

@bergerst
Copy link

Describe the bug
Normally, when you use kustomize to create a Deployment referencing a ConfigMap, the ConfigMap will be deployed with a hash suffix in the name. (e.g. app-config-88g924ftgk). The Deployment will reference the suffixed name instead of using the original name.

When you update the ConfigMap and redeploy, the Deployment will then reference the ConfigMap with the new hash suffix.

For the GrafanaDashboard objects, this is not how it works. For example if you deploy https://github.com/bergerst/grafana-operator-nameSuffixHash with kustomize, the GrafanaDashboard will use "simple-dashboard-from-cm" while the ConfigMap is actually named something like "simple-dashboard-from-cm-bg87454kb7".

This can be circumvented using disableNameSuffixHash: true, but then the dashboards in Grafana will not be updated when the ConfigMap changes.

Version
4.8.0

To Reproduce
Steps to reproduce the behavior:

  1. Deploy https://github.com/bergerst/grafana-operator-nameSuffixHash
  2. The dashboard does not show up in Grafana

Expected behavior
If the ConfigMap is changed with nameSuffixHash enabled, the deployed GrafanaDashboard object should reference the ConfigMap with the nameSuffixHash.

Suspect component/Location where the bug might be occuring
The CRD is incorrectly defined here https://github.com/grafana-operator/grafana-operator/blob/a7d7fa58455730a734baf20e6bee8843c6e0f1af/bundle/manifests/integreatly.org_grafanadashboards.yaml#L37

I have found this guide on how to correctly implement configMapRef fields, but I'm not sure how to correctly apply it: kubernetes-sigs/kustomize#97 (comment)

Runtime (please complete the following information):

  • OS: Red Hat Enterprise Linux CoreOS
  • Grafana Operator Version 4.8.0
  • Environment: Openshift 4.10
  • Deployment type: deployed
  • Other:
@bergerst bergerst added bug Something isn't working needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 16, 2023
@pb82
Copy link
Collaborator

pb82 commented Jan 17, 2023

@bergerst is the issue here that when using kustomize, the name of the configmap cannot be known? And if you suppress this behaviour using the flag, then the operator won't be notified when the configmap is updated?

@pb82 pb82 added triage/needs-information Indicates an issue needs more information in order to work on it. and removed needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 17, 2023
@bergerst
Copy link
Author

bergerst commented Jan 17, 2023

@pb82 Yes, you're right.

After I researched some more using different search keywords than before, I was able to find this: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs#name-reference-transformer

I've added a transformer in this branch and it works: https://github.com/bergerst/grafana-operator-nameSuffixHash/tree/transformer-configuration

The resulting file looks like this:

apiVersion: v1
data:
  simple-dashboard.json: "{\r\n    \"id\": null,\r\n    \"title\": \"Simple Dashboard
    from Config Map\",\r\n    \"tags\": [],\r\n    \"style\": \"dark\",\r\n    \"timezone\":
    \"browser\",\r\n    \"editable\": true,\r\n    \"hideControls\": false,\r\n    \"graphTooltip\":
    1,\r\n    \"panels\": [],\r\n    \"time\": {\r\n        \"from\": \"now-6h\",\r\n
    \       \"to\": \"now\"\r\n    },\r\n    \"timepicker\": {\r\n        \"time_options\":
    [],\r\n        \"refresh_intervals\": []\r\n    },\r\n    \"templating\": {\r\n
    \       \"list\": []\r\n    },\r\n    \"annotations\": {\r\n        \"list\":
    []\r\n    },\r\n    \"refresh\": \"5s\",\r\n    \"schemaVersion\": 17,\r\n    \"version\":
    0,\r\n    \"links\": []\r\n}"
kind: ConfigMap
metadata:
  name: simple-dashboard-from-cm-bg87454kb7
---
apiVersion: integreatly.org/v1alpha1
kind: GrafanaDashboard
metadata:
  labels:
    app: grafana
  name: grafana-dashboard-from-config-map
spec:
  configMapRef:
    key: simple-dashboard.json
    name: simple-dashboard-from-cm-bg87454kb7

The 2nd part of the solution described in kubernetes-sigs/kustomize#97 (comment) can probably only be used if you have the CRD JSON in your local file system or hosted somewhere.

So if the CRD YAML in this repo contains the openapi-gen=x-kubernetes-object-ref-kind annotation, kustomize should be able to resolve the name references correctly without the name reference transformer:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

crds:
- https://raw.githubusercontent.com/grafana-operator/grafana-operator/master/bundle/manifests/integreatly.org_grafanadashboards.yaml

resources:
- dashboard.yaml

configMapGenerator: 
- name: simple-dashboard-from-cm
  files:
  - simple-dashboard.json

But since downloading the CRD YAML on every deployment is not failsafe in case of downtimes, users should use a local copy of the CRD YAML file from this repo.

I'll definitely use the name reference transformer until the CRD YAML is properly annotated.

@pb82
Copy link
Collaborator

pb82 commented Feb 7, 2023

@bergerst I'm closing this, please reopen if you keep seeing issues.

@pb82 pb82 closed this as completed Feb 7, 2023
@bergerst
Copy link
Author

@pb82 Users can only reopen issues if they closed them themselves.

Regarding my issue, I tried using the CRD file feature of kustomize, but it's not documented well and doesn't accept any current form of OpenAPI CRD definition.

Seems like the solution of annotating the fields with x-kubernetes-object-ref-kind:Service no longer works, so using a nameReferenceTransformer as shown in my previous comment is the only supported way to achieve correct ConfigMap references right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage/needs-information Indicates an issue needs more information in order to work on it.
Projects
None yet
Development

No branches or pull requests

2 participants