anza-labs / scribe

Tool for propagation of annotations in Kubernetes
Apache License 2.0
0 stars 0 forks source link

[FEATURE]: Delete annotations from objects after they are deleted from the namespace #14

Open shanduur opened 3 weeks ago

shanduur commented 3 weeks ago

Is your feature request related to a problem? Please describe.

Currently, when annotations are removed from the namespace, they remain on the previously annotated objects (e.g., Deployments, Services) unless manually removed. This can lead to outdated or incorrect annotations persisting on resources, which might cause confusion or unwanted behavior.

Describe the solution you'd like.

I would like Scribe to automatically remove annotations from resources when they are deleted from the namespace's annotations. This would ensure that resources stay in sync with the current state of the namespace's annotations.

Example:

  1. Namespace example has the following annotation:
    apiVersion: v1
    kind: Namespace
    metadata:
      name: example
      annotations:
        scribe.anza-labs.dev/annotations: |
          app.kubernetes.io/name=example
  2. The annotation is propagated to all resources within the namespace.
  3. Later, the annotation is removed from the namespace:
    apiVersion: v1
    kind: Namespace
    metadata:
      name: example
      annotations:
        scribe.anza-labs.dev/annotations: ""
  4. Scribe should detect the change and remove the app.kubernetes.io/name=example annotation from all relevant resources automatically.

Describe alternatives you've considered.

  1. Manually removing annotations from resources when they are no longer needed, which can be time-consuming and error-prone in large environments.
  2. Using custom scripts or jobs to periodically clean up outdated annotations, but this adds complexity and overhead.

Additional Information

No response

Abiji-2020 commented 2 weeks ago

I am interested in this issue.

Proposed solution:

shanduur commented 2 weeks ago

Hi @Abiji-2020! Thanks for reaching out.

I think that the changes to annotations on Namespace should be already watched, so the only thing left is to save annotations in something like scribe.anza-labs.devl/last-applied-annotations and update existing ones based on the diff between namespace and the aforementioned annotation.