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

Implement finalizers for GrafanaFolder #1807

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

Conversation

Baarsgaard
Copy link
Contributor

@Baarsgaard Baarsgaard commented Dec 30, 2024

Should close #1680

Testing with the resources in tests/example-resources.yaml

Finalizers are correctly applied and removed on deletion

kubectl apply -f tests/example-resources.yaml
kubectl get grafanafolders.grafana.integreatly.org -o yaml
apiVersion: v1
items:
  - apiVersion: grafana.integreatly.org/v1beta1
    kind: GrafanaFolder
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"grafana.integreatly.org/v1beta1","kind":"GrafanaFolder","metadata":{"annotations":{},"name":"testdata","namespace":"default"},"spec":{"instanceSelector":{"matchLabels":{"test":"testdata"}},"resyncPeriod":"3s","title":"Folder!","uid":"testdata"}}
      creationTimestamp: "2024-12-30T16:44:42Z"
      finalizers:
        - operator.grafana.com/finalizer # <--------
      generation: 1
      name: testdata
      namespace: default
      resourceVersion: "973"
      uid: dd4b350c-f302-410e-93bd-894d34edca2c
    spec:
      allowCrossNamespaceImport: false
      instanceSelector:
        matchLabels:
          test: testdata
      resyncPeriod: 3s
      title: Folder!
      uid: testdata
    status:
      conditions:
        - lastTransitionTime: "2024-12-30T16:45:08Z"
          message: Folder was successfully applied to 1 instances
          observedGeneration: 1
          reason: ApplySuccessful
          status: "True"
          type: FolderSynchronized
      hash: 56e78eb86a0cd663f626b0291607a35d7c8dab8abc91495ed8fe1366c0485d95
      lastResync: "2024-12-30T16:45:14Z"
kind: List
metadata:
  resourceVersion: ""
kubectl delete grafanafolders.grafana.integreatly.org testdata
  grafanafolder.grafana.integreatly.org "testdata" deleted

Finalizers are correctly removed when no grafana instances match

kubectl apply -f tests/example-resources.yaml
kubectl get grafanafolders.grafana.integreatly.org -o yaml
apiVersion: v1
items:
  - apiVersion: grafana.integreatly.org/v1beta1
    kind: GrafanaFolder
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"grafana.integreatly.org/v1beta1","kind":"GrafanaFolder","metadata":{"annotations":{},"name":"testdata","namespace":"default"},"spec":{"instanceSelector":{"matchLabels":{"test":"testdata"}},"resyncPeriod":"3s","title":"Folder!","uid":"testdata"}}
      creationTimestamp: "2024-12-30T16:44:42Z"
      finalizers:
        - operator.grafana.com/finalizer # <--------
      generation: 1
      name: testdata
      namespace: default
      resourceVersion: "973"
      uid: a2af72ab-552b-4763-8d94-5562dbb28128
    spec:
      allowCrossNamespaceImport: false
      instanceSelector:
        matchLabels:
          test: testdata
      resyncPeriod: 3s
      title: Folder!
      uid: testdata
    status:
      conditions:
        - lastTransitionTime: "2024-12-30T16:45:08Z"
          message: Folder was successfully applied to 1 instances
          observedGeneration: 1
          reason: ApplySuccessful
          status: "True"
          type: FolderSynchronized
      hash: 56e78eb86a0cd663f626b0291607a35d7c8dab8abc91495ed8fe1366c0485d95
      lastResync: "2024-12-30T16:45:14Z"
kind: List
metadata:
  resourceVersion: ""
kubectl delete grafanas grafana-testdata
  grafana.grafana.integreatly.org "grafana-testdata" deleted
kubectl get grafanafolders.grafana.integreatly.org -o yaml
apiVersion: v1
items:
  - apiVersion: grafana.integreatly.org/v1beta1
    kind: GrafanaFolder
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"grafana.integreatly.org/v1beta1","kind":"GrafanaFolder","metadata":{"annotations":{},"name":"testdata","namespace":"default"},"spec":{"instanceSelector":{"matchLabels":{"test":"testdata"}},"resyncPeriod":"3s","title":"Folder!","uid":"testdata"}}
      creationTimestamp: "2024-12-30T16:45:46Z"
      generation: 1
      name: testdata
      namespace: default
      resourceVersion: "1204"
      uid: a2af72ab-552b-4763-8d94-5562dbb28128
    spec:
      allowCrossNamespaceImport: false
      instanceSelector:
        matchLabels:
          test: testdata
      resyncPeriod: 3s
      title: Folder!
      uid: testdata
    status:
      NoMatchingInstances: true # <------
      conditions:
        - lastTransitionTime: "2024-12-30T16:46:19Z"
          message: Instances could not be fetched, reconciliation will be retried
          observedGeneration: 1
          reason: EmptyAPIReply
          status: "True"
          type: NoMatchingInstance # <------
      hash: 56e78eb86a0cd663f626b0291607a35d7c8dab8abc91495ed8fe1366c0485d95
      lastResync: "2024-12-30T16:46:24Z"
kind: List
metadata:
  resourceVersion: ""

@Baarsgaard Baarsgaard force-pushed the impl_finalizers_folder branch 2 times, most recently from e9efc98 to c0de72c Compare December 30, 2024 17:27
@Baarsgaard Baarsgaard marked this pull request as ready for review December 30, 2024 17:38
@Baarsgaard Baarsgaard force-pushed the impl_finalizers_folder branch 2 times, most recently from cd2f1c5 to 1915843 Compare January 1, 2025 15:31
@Baarsgaard Baarsgaard force-pushed the impl_finalizers_folder branch from 1915843 to 7d1bdbf Compare January 4, 2025 13:24
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.

Add finalizer to GrafanaFolder
1 participant