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

[feature] instanceSelectors should be made immutable #1519

Closed
weisdd opened this issue May 5, 2024 · 1 comment · Fixed by #1525
Closed

[feature] instanceSelectors should be made immutable #1519

weisdd opened this issue May 5, 2024 · 1 comment · Fixed by #1525
Labels
enhancement New feature or request triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@weisdd
Copy link
Collaborator

weisdd commented May 5, 2024

Describe the bug

As it was highlighted in #1497 (comment), the operator does not clean up resources (across Grafana instances) that no longer match instanceSelector.

Version
v5.9.0

To Reproduce
Steps to reproduce the behavior:

0. Deploy `Grafana`
apiVersion: grafana.integreatly.org/v1beta1
kind: Grafana
metadata:
  name: grafana
  labels:
    dashboards: "grafana"
spec:
  config:
    log:
      mode: "console"
    auth:
      disable_login_form: "false"
    security:
      admin_user: root
      admin_password: secret
1. Deploy `GrafanaDashboard` that matches the `Grafana` instance
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaDashboard
metadata:
  name: grafanadashboard-sample
spec:
  resyncPeriod: 30s
  instanceSelector:
    matchLabels:
      dashboards: "grafana"
  json: >
    {
      "id": null,
      "title": "Simple Dashboard",
      "tags": [],
      "style": "dark",
      "timezone": "browser",
      "editable": true,
      "hideControls": false,
      "graphTooltip": 1,
      "panels": [],
      "time": {
        "from": "now-6h",
        "to": "now"
      },
      "timepicker": {
        "time_options": [],
        "refresh_intervals": []
      },
      "templating": {
        "list": []
      },
      "annotations": {
        "list": []
      },
      "refresh": "5s",
      "schemaVersion": 17,
      "version": 0,
      "links": []
    }
2. Adjust `instanceSelector` in `GrafanaDashboard`, so it no longer matches the `Grafana` instance
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaDashboard
metadata:
  name: grafanadashboard-sample
spec:
  resyncPeriod: 30s
  instanceSelector:
    matchLabels:
      dashboards: "grafana2"
  json: >
    {
      "id": null,
      "title": "Simple Dashboard",
      "tags": [],
      "style": "dark",
      "timezone": "browser",
      "editable": true,
      "hideControls": false,
      "graphTooltip": 1,
      "panels": [],
      "time": {
        "from": "now-6h",
        "to": "now"
      },
      "timepicker": {
        "time_options": [],
        "refresh_intervals": []
      },
      "templating": {
        "list": []
      },
      "annotations": {
        "list": []
      },
      "refresh": "5s",
      "schemaVersion": 17,
      "version": 0,
      "links": []
    }

Expected behavior

The dashboard should be gone from Grafana.

Runtime (please complete the following information):

  • Grafana Operator Version: v5.9.0
  • Environment: Kubernetes
@weisdd weisdd added bug Something isn't working needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 5, 2024
@theSuess
Copy link
Member

theSuess commented May 6, 2024

Cleaning up resources on a change of the instanceSelector is difficult to realize since the operator only ever knows about the current version of the resource.

This is also the reason as to why the selector field of deployments and stateful sets are immutable.

To be consistent with the rest of the Kubernetes ecosystem, this should be resolved by setting the instanceSelector to be immutable like this: https://kubernetes.io/blog/2022/09/29/enforce-immutability-using-cel/#immutablility-after-first-modification

@theSuess theSuess added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 6, 2024
@weisdd weisdd added enhancement New feature or request and removed bug Something isn't working labels May 6, 2024
@weisdd weisdd changed the title [Bug] Resources are not cleaned up in Grafana when changes in instanceSelector are made [feature] instanceSelectors should be made immutable May 6, 2024
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/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants