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

feat: Add support for API served via HTTPS when preferService: true #772



Copy link

@weisdd weisdd commented Jun 6, 2022


Noticed the issue #642, where a user complains that grafana-operator cannot manage grafana instance which exposes its API via https.

The reason for that is quite simple. - (r *ReconcileGrafana) getGrafanaAdminUrl always assumes that grafana instance serves HTTP when preferService: true.
Grafana itself supports http, https, h2, and socket (source). I think operator can only be guaranteed to work with http and https. h2 might be served via different protocols (HTTP / HTTPS), which makes its setup more complicated, so IMO it's better not support it at all. socket is definitely not the way operator is set up to work.

Relevant issues/tickets

Fixes: #642

Type of change

  • Bug fix (non-breaking change which fixes an issue)


  • This change requires a documentation update
  • I have added tests that prove my fix is effective or that my feature works
  • I have added a test case that will be used to verify my changes
  • Verified independently on a cluster by reviewer

Verification steps

  1. Generate cert:
$ openssl genrsa -out ca.key 2048
$ openssl req -x509 -new -nodes -days 365 -key ca.key -out ca.crt -subj "/"
kubectl create secret tls my-tls-secret --key ca.key --cert ca.crt
  1. Deploy grafana with a spec similar to this:
    preferService: true
    timeout: 5
      cert_file: /etc/grafana/secrets/tls/tls.crt
      cert_key: /etc/grafana/secrets/tls/tls.key
      protocol: https
  - matchLabels: grafana-operator
    - mountPath: /etc/grafana/secrets/tls
      name: tls
    - name: tls
        secretName: my-tls-secret

For discussion

Please, let me know if you agree with the overall implementation. Once that is done, I can add some tests.

Signed-off-by: Igor Beliakov <>
Copy link

@HubertStefanski HubertStefanski left a comment

LGTM! Thanks for the contribution! @weisdd

Signed-off-by: Igor Beliakov <>
Copy link
Contributor Author

weisdd commented Jun 7, 2022

@HubertStefanski yw. I've just added some tests. Since there are plenty of factors that influence the end result and I tried to cover the preexisting cases as well, the code is slightly monstrous :) Please, feel free to make any changes if needed.

@HubertStefanski HubertStefanski merged commit 3fe7486 into grafana-operator:master Jun 12, 2022
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

[Bug] CRDS not working when Grafana running under protocol https
2 participants