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]: Support reconciliation on metadata (annotation) is changed #803

Open
pantosha opened this issue Aug 26, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@pantosha
Copy link

pantosha commented Aug 26, 2024

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:

// Check if entity spec has changed through "Generation" value increment. Skip reconcile if not changed.
if (entity.Generation() <= cachedGeneration)
{
logger.LogDebug(
"""Entity "{Kind}/{Name}" modification did not modify generation. Skip event.""",
entity.Kind,
entity.Name());
return;
}

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;
        }
    }
}
@pantosha pantosha added the enhancement New feature or request label Aug 26, 2024
Repository owner deleted a comment Aug 26, 2024
Repository owner deleted a comment Aug 26, 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
Projects
None yet
Development

No branches or pull requests

1 participant