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

Add lifecycle to main grafana container #575

Closed
aivanov-citc opened this issue Oct 20, 2021 · 3 comments
Closed

Add lifecycle to main grafana container #575

aivanov-citc opened this issue Oct 20, 2021 · 3 comments
Labels
enhancement New feature or request triage/duplicate Indicates an issue is a duplicate of other open issue.

Comments

@aivanov-citc
Copy link

Hi.
Please add handlers lifecycle events to the main grafana container.

apiVersion: integreatly.org/v1alpha1
kind: Grafana
metadata:
  name: grafana
spec:
...
  deployment:
    lifecycle:
      postStart:
        exec:
          command: ["/bin/sh", "-c", "example.sh"]
...

This will allow us to run commands after grafana starts. For example, add users declaratively, referring to api grafana

@aivanov-citc aivanov-citc added enhancement New feature or request needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 20, 2021
@NissesSenap
Copy link
Collaborator

Personally I'm not a fan of this idea, I think it will be a great source of potential issues and I think it will be hard to maintain.
Overall it's also a security issue to allow any commands to run in arbiary in your application.

If you want to add users declaratively (something I want as well) we should do it through the controller.

If you want a workaround a friend of mine have done this workaround:
It's not beautiful but it gets the job done.

I have remove a bunch of config so it won't work out of the box but I think you will get the idea.
More or less start a extra container and run a script towards the grafana API using the grafana admin password.
When it's done just tail /dev/null to not crash.

apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-extra-config
data:
  script.sh: |
    # Create screen user and playlist
    until curl -vvv -X POST -H "Content-Type: application/json" --data "{\"name\":\"screen\",\"email\":\"screen@example.com\",\"login\":\"screen\",\"password\":\"${GF_SCREEN_PASSWORD}\"}" ${GF_SECURITY_ADMIN_USER}:${GF_SECURITY_ADMIN_PASSWORD}@localhost:3000/api/admin/users
    do
      echo "retry create screen user"
      sleep 2
    done

    tail -f /dev/null # wait forever
---
apiVersion: integreatly.org/v1alpha1
kind: Grafana
metadata:
  name: grafana
spec:
  containers:
    - name: extra-config
      image: curlimages/curl
      command: ["/bin/sh", "/tmp/script/script.sh"]
      envFrom:
        - secretRef:
            name: grafana-admin-credentials
        - secretRef:
            name: grafana-screen-credentials
      volumeMounts:
        - name: grafana-extra-config
          mountPath: /tmp/script
  deployment:
    extraVolumeMounts:
      - name: tmp
        mountPath: /tmp
    extraVolumes:
      - name: tmp
        emptyDir: {}
      - name: grafana-extra-config
        configMap:
          name: grafana-extra-config

So please create a new issue with what you actually need or +1 one of the existing issues that you might need so we know what to prioritise.

@NissesSenap NissesSenap added the v4 label Oct 21, 2021
@hubeadmin
Copy link
Collaborator

Hey @aivanov-citc We're going to reject this issue, we don't see this as something crucial to the operator, we are also hesitant to allow commands to be run from within the container in a lifecycle way, but it seems like your issue is closer to #408, in the way you want to manage users with the operator. Please leave your feedback or further suggestions on that issue.
You can use @NissesSenap solution for now. We are planning on resolving the issue some time in the future, but we have different priorities as of now. Thanks!

@hubeadmin hubeadmin added triage/duplicate Indicates an issue is a duplicate of other open issue. and removed needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 26, 2021
@aivanov-citc
Copy link
Author

We use a similar solution. It is inconvenient when creating multiple users.
Thanks. We will wait for the decision to create users through the operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage/duplicate Indicates an issue is a duplicate of other open issue.
Projects
None yet
Development

No branches or pull requests

3 participants