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

Fix: GrafanaDashboard incorrect NoMatchingInstances #1751

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Baarsgaard
Copy link
Contributor

@Baarsgaard Baarsgaard commented Nov 9, 2024

This is a not so simple fix for #1164
Inspiration was taken from the GrafanaContactPoint but this moves more instance checking logic into the GetMatchingDashboardInstances function

kubectl get grafanadashboards.grafana.integreatly.org -n test
NAME                   NO MATCHING INSTANCES   LAST RESYNC   AGE
cross-namespace                                1s            54m
cross-namespace-fail   true                    4m6s          54m
Test resources

Should result in logs like:
2024-11-09T19:33:43Z ERROR GrafanaDashboardReconciler could not find matching instances {"name": "cross-namespace-fail", "error": "no matching instances"}

---
apiVersion: v1
kind: Namespace
metadata:
  name: test
---
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaDashboard
metadata:
  name: cross-namespace-fail
  namespace: test
spec:
  folder: General
  allowCrossNamespaceImport: true
  resyncPeriod: 10s
  instanceSelector:
    matchLabels:
      grafana: "dashboards"
  json: >
    {
      "annotations": {
        "list": [
          {
            "builtIn": 1,
            "datasource": {
              "type": "grafana",
              "uid": "-- Grafana --"
            },
            "enable": true,
            "hide": true,
            "iconColor": "rgba(0, 211, 255, 1)",
            "name": "Annotations & Alerts",
            "type": "dashboard"
          }
        ]
      },
      "editable": true,
      "fiscalYearStartMonth": 0,
      "graphTooltip": 0,
      "links": [],
      "panels": [
        {
          "datasource": {
            "type": "grafana-testdata-datasource",
            "uid": "grafana-testdata"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "custom": {
                "align": "auto",
                "cellOptions": {
                  "type": "auto"
                },
                "inspect": false
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": [
              {
                "matcher": {
                  "id": "byName",
                  "options": "id"
                },
                "properties": [
                  {
                    "id": "custom.width",
                    "value": 72
                  }
                ]
              }
            ]
          },
          "gridPos": {
            "h": 8,
            "w": 24,
            "x": 0,
            "y": 0
          },
          "id": 2,
          "options": {
            "cellHeight": "sm",
            "footer": {
              "countRows": false,
              "fields": "",
              "reducer": [
                "sum"
              ],
              "show": false
            },
            "showHeader": true,
            "sortBy": []
          },
          "pluginVersion": "10.4.3",
          "targets": [
            {
              "datasource": {
                "type": "grafana-testdata-datasource",
                "uid": "grafana-testdata"
              },
              "refId": "A",
              "scenarioId": "grafana_api",
              "stringInput": "datasources"
            }
          ],
          "title": "Panel Title",
          "type": "table"
        },
        {
          "datasource": {
            "type": "grafana-testdata-datasource",
            "uid": "grafana-testdata"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "custom": {
                "align": "auto",
                "cellOptions": {
                  "type": "auto"
                },
                "inspect": false
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 7,
            "w": 24,
            "x": 0,
            "y": 8
          },
          "id": 1,
          "options": {
            "cellHeight": "sm",
            "footer": {
              "countRows": false,
              "fields": "",
              "reducer": [
                "sum"
              ],
              "show": false
            },
            "showHeader": true
          },
          "pluginVersion": "10.4.3",
          "targets": [
            {
              "datasource": {
                "type": "grafana-testdata-datasource",
                "uid": "grafana-testdata"
              },
              "hide": false,
              "refId": "A",
              "scenarioId": "grafana_api",
              "stringInput": "search"
            }
          ],
          "title": "Panel Title",
          "type": "table"
        }
      ],
      "schemaVersion": 39,
      "tags": [],
      "templating": {
        "list": []
      },
      "time": {
        "from": "now-6h",
        "to": "now"
      },
      "timepicker": {},
      "timezone": "browser",
      "title": "Failure",
      "version": 0,
      "weekStart": ""
    }
---
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaDashboard
metadata:
  name: cross-namespace
  namespace: test
spec:
  folder: General
  allowCrossNamespaceImport: true
  resyncPeriod: 10s
  instanceSelector:
    matchLabels:
      test: "testdata"
  json: >
    {
      "annotations": {
        "list": [
          {
            "builtIn": 1,
            "datasource": {
              "type": "grafana",
              "uid": "-- Grafana --"
            },
            "enable": true,
            "hide": true,
            "iconColor": "rgba(0, 211, 255, 1)",
            "name": "Annotations & Alerts",
            "type": "dashboard"
          }
        ]
      },
      "editable": true,
      "fiscalYearStartMonth": 0,
      "graphTooltip": 0,
      "links": [],
      "panels": [
        {
          "datasource": {
            "type": "grafana-testdata-datasource",
            "uid": "grafana-testdata"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "custom": {
                "align": "auto",
                "cellOptions": {
                  "type": "auto"
                },
                "inspect": false
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": [
              {
                "matcher": {
                  "id": "byName",
                  "options": "id"
                },
                "properties": [
                  {
                    "id": "custom.width",
                    "value": 72
                  }
                ]
              }
            ]
          },
          "gridPos": {
            "h": 8,
            "w": 24,
            "x": 0,
            "y": 0
          },
          "id": 2,
          "options": {
            "cellHeight": "sm",
            "footer": {
              "countRows": false,
              "fields": "",
              "reducer": [
                "sum"
              ],
              "show": false
            },
            "showHeader": true,
            "sortBy": []
          },
          "pluginVersion": "10.4.3",
          "targets": [
            {
              "datasource": {
                "type": "grafana-testdata-datasource",
                "uid": "grafana-testdata"
              },
              "refId": "A",
              "scenarioId": "grafana_api",
              "stringInput": "datasources"
            }
          ],
          "title": "Panel Title",
          "type": "table"
        },
        {
          "datasource": {
            "type": "grafana-testdata-datasource",
            "uid": "grafana-testdata"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "custom": {
                "align": "auto",
                "cellOptions": {
                  "type": "auto"
                },
                "inspect": false
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 7,
            "w": 24,
            "x": 0,
            "y": 8
          },
          "id": 1,
          "options": {
            "cellHeight": "sm",
            "footer": {
              "countRows": false,
              "fields": "",
              "reducer": [
                "sum"
              ],
              "show": false
            },
            "showHeader": true
          },
          "pluginVersion": "10.4.3",
          "targets": [
            {
              "datasource": {
                "type": "grafana-testdata-datasource",
                "uid": "grafana-testdata"
              },
              "hide": false,
              "refId": "A",
              "scenarioId": "grafana_api",
              "stringInput": "search"
            }
          ],
          "title": "Panel Title",
          "type": "table"
        }
      ],
      "schemaVersion": 39,
      "tags": [],
      "templating": {
        "list": []
      },
      "time": {
        "from": "now-6h",
        "to": "now"
      },
      "timepicker": {},
      "timezone": "browser",
      "title": "Matching",
      "version": 0,
      "weekStart": ""
    }

@Baarsgaard Baarsgaard marked this pull request as ready for review November 9, 2024 19:51
@Baarsgaard
Copy link
Contributor Author

Baarsgaard commented Nov 10, 2024

Having looked at a lot of the controllers over the last few weeks, I've noticed that there's little to no consistency in setting conditions and NoMatchingInstances.
Any reconciler using the shared setNoMatchingInstances function never sets the status.NoMatchingInstances flag or their status is lacking it outright.
It might make sense to refactor getMatchingInstances and the status specs handling before more changes are planned.
I'm specifically referring to the following issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant