Skip to content

[feature]: Support reconciliation on metadata (annotation) is changed #803

@pantosha

Description

@pantosha

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

Our operator reacts to annotation changes in custom resources.
In the current implementation ReconcileAsync() is not called when only .metadata is changed:

https://github.com/buehler/dotnet-operator-sdk/blob/de986bf8dc9548bfeaccdd2fbe6cb174c302fe5f/src/KubeOps.Operator/Watcher/ResourceWatcher%7BTEntity%7D.cs#L246-L254

Reason is

The .metadata.generation value is incremented for all changes, except for changes to .metadata or .status.

https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#status-subresource

Describe the solution you would like

Any solution that allows reacting on metadata changes:

  • always call ReconcileAsync() when metadata is changed
  • provide an option to override behavior when ReconcileAsync() is called
  • add overload or new method that will be called to .metadata or .status changes

Additional Context

Similar issue #668

Now we are testing a workaround when .generation is reset during serialization using IJsonOnDeserialized:

public partial class V1CustomResource : CustomKubernetesEntity<V1V1CustomResource .EntitySpec>, IJsonOnDeserialized
{
    // ...
    public void OnDeserialized()
    {
        // HACK
        if (Metadata.Annotations?.ContainsKey("special-annotation") == true)
        {
            Metadata.Generation = null;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions