controller-runtime icon indicating copy to clipboard operation
controller-runtime copied to clipboard

Feature: Native SSA Support

Open sbueringer opened this issue 8 months ago • 9 comments

Tasks:

  • [x] client.Apply: https://github.com/kubernetes-sigs/controller-runtime/issues/347
    • [x] https://github.com/kubernetes-sigs/controller-runtime/pull/3253
    • [x] k/k: interface for ApplyConfigurations: https://github.com/kubernetes/kubernetes/issues/118138
    • [x] Support for Unstructured
  • [x] fake client support for SSA: https://github.com/kubernetes-sigs/controller-runtime/issues/2341
    • [x] https://github.com/kubernetes-sigs/controller-runtime/pull/2981
    • [x] k/k: extend tracker: https://github.com/kubernetes/kubernetes/pull/132004
  • [ ] SubResource Apply: https://github.com/kubernetes-sigs/controller-runtime/pull/3321
    • [x] Real client
      • [x] Deprecate client.Apply again (see: https://github.com/kubernetes-sigs/controller-runtime/pull/3307)
    • [ ] Fake client
      • [ ] Non-Status subresources

Tasks controller-tools:

  • [x] Generation of ApplyConfigurations: https://github.com/kubernetes-sigs/controller-tools/pull/818
  • [ ] Generation of Extract functions (details: https://github.com/kubernetes-sigs/controller-runtime/issues/3183#issuecomment-2782827772)

sbueringer avatar Mar 30 '25 05:03 sbueringer

cc @alvaroaleman @vincepri

sbueringer avatar Mar 30 '25 05:03 sbueringer

cc @JoelSpeed

sbueringer avatar Mar 30 '25 05:03 sbueringer

@sbueringer Could you describe what's the gap with SSA in controller-runtime? I was under the impression SSA is already supported with Client.Patch(ctx, obj, client.Apply)

shashankram avatar Apr 03 '25 17:04 shashankram

@sbueringer Could you describe what's the gap with SSA in controller-runtime? I was under the impression SSA is already supported with Client.Patch(ctx, obj, client.Apply)

Yep that works, but we want it to be a first-class citizen. Please see the initial issue for a list of missing things.

alvaroaleman avatar Apr 03 '25 17:04 alvaroaleman

@sbueringer Could you describe what's the gap with SSA in controller-runtime? I was under the impression SSA is already supported with Client.Patch(ctx, obj, client.Apply)

Yep that works, but we want it to be a first-class citizen. Please see the initial issue for a list of missing things.

I think I ran into a bug with SSA: https://github.com/kubernetes-sigs/controller-runtime/issues/347#issuecomment-2776561905

Let me know if this is related to the issue being fixed.

shashankram avatar Apr 03 '25 18:04 shashankram

One gap that we have is the extraction functions for the ApplyConfigurations, which require openapi.json to be able to generate.

The first step of which is to use kube-openapi to generate the openapi definitions as generated Go code.

This code is then imported into models-schema which then generated an openapi.json file, much like you could retrieve from a Kube API server.

This openapi.json is then fed into the OpenAPISchemaFilePath argument to the applyconfiguration gen, which allows it to generate the extraction functions.

I'd be interested to see if there was a way that we could combine the first two stages so that we don't have to output the intermediate generated go code, and could put the openapi.json file in a known location or even a temp location for creating the extract functions

JoelSpeed avatar Apr 07 '25 10:04 JoelSpeed

The first step of which is to use kube-openapi to generate the openapi definitions as generated Go code.

This code is then imported into models-schema which then generated an openapi.json file, much like you could retrieve from a Kube API server.

This openapi.json is then fed into the OpenAPISchemaFilePath argument to the applyconfiguration gen, which allows it to generate the extraction functions.

@mrIncompetent pointed out that since we alerady have code for openapi generation in controller-tools as we generade the CRD schema, we might be able to re-use that for the first two steps in place of kube-openapi and models-schema.

alvaroaleman avatar Jul 19 '25 11:07 alvaroaleman

Hi, thanks a lot for this effort!

Is it also planned to provide Apply on SubResourceWriter? Or any advice what we should do with something like clnt.Status().Patch(ctx, obj, client.Apply)? My understanding is that we can't replace it with a clnt.Apply supplying an unstructured object like below because it can't write a subresource.

"Object": {
    "apiVersion": "foo/v1alpha1",
    "kind": "Bar",
    "metadata": {
      "name": "baz",
      "namespace": "default"
    },
    "status": {
      // ...
    }
}

c-pius avatar Sep 02 '25 12:09 c-pius

Is it also planned to provide Apply on SubResourceWriter?

Yeah, this is a known missing piece, I've added it to the top level description.

alvaroaleman avatar Sep 02 '25 12:09 alvaroaleman