crossplane-contrib / provider-kubernetes

Crossplane provider to provision and manage Kubernetes objects on (remote) Kubernetes clusters.
Apache License 2.0
136 stars 80 forks source link

Implement extracted state cache to avoid SSA dry run calls #269

Open turkenh opened 3 days ago

turkenh commented 3 days ago

What problem are you facing?

https://github.com/crossplane-contrib/provider-kubernetes/pull/246 introduces support for SSA (server side apply) as an alpha feature. It includes a workaround for https://github.com/kubernetes/kubernetes/issues/115563 which utilizes a dry run request to decide whether the resources is in the desired state or not. This will be executed in each reconciliation, in the Observe method.

How could Crossplane help solve your problem?

We could avoid that dry run request by implementing a cache holding extracted state for a given desired state (e.g. spec.forProvidder.manifest), very roughly:

  1. Get the object from controller runtime cache.
  2. Extract state using applymetav1.UnstructuredExtractor.
  3. Get the cached extracted state for the current desired state (spec.forProvidder.manifest).
  4. If they differ, object is not up to date.
  5. Apply again, extract state and update the cache.