apiextensions: add subresources for custom resources#55168
apiextensions: add subresources for custom resources#55168k8s-github-robot merged 3 commits intokubernetes:masterfrom
Conversation
There was a problem hiding this comment.
do we use typographical quotes?
There was a problem hiding this comment.
This should be fixed when proto generation is fixed. Currently, update-generated-protobuf fails on CustomResourceSubResourceStatus
There was a problem hiding this comment.
we have public unstructured helpers now. Would they work for you? apimachinery/pkg/apis/meta/v1/unstructured/helpers.go
There was a problem hiding this comment.
yes, they probably should. I'll try with them.
There was a problem hiding this comment.
This makes every CR part of kubectl get all. Wondering, do we have a way to opt-in to that group in a CRD?
There was a problem hiding this comment.
Wondering, do we have a way to opt-in to that group in a CRD?
Maybe another field in the CRD? 🤔
There was a problem hiding this comment.
would make all of the paths explicit here
There was a problem hiding this comment.
To have something like this:
scaleJSONPath["specReplicasPath"] = crd.Spec.SubResources.Scale.SpecReplicasPath
scaleJSONPath["statusReplicasPath"] = crd.Spec.SubResources.Scale.StatusReplicasPath
scaleJSONPath["labelSelectorPath"] = crd.Spec.SubResources.Scale.LabelSelectorPath
There was a problem hiding this comment.
would make all of the paths explicit here
👍
There was a problem hiding this comment.
3 string fields would do as well?
There was a problem hiding this comment.
These tests should go into the CRD validation.
There was a problem hiding this comment.
This validates the "custom resource". So I think it should not go in the CRD strategy and should instead remain the in the CR strategy.
@sttts WDYT?
There was a problem hiding this comment.
hmm, I think customResource["oneOf"] does not make sense here. We have to check that OneOf is not used in the root of the JSON schema in the CRD.
There was a problem hiding this comment.
:-(. It was fun while it lasted
|
@kubernetes/sig-autoscaling-api-reviews |
DirectXMan12
left a comment
There was a problem hiding this comment.
You're using the scheme used internally to the scale client as your internal version, which I'd say is not ok.
Other comments inline
There was a problem hiding this comment.
why is StatusReplicas optional? If it defaults to something otherwise, you should probably write that here (same with the other optional fields)
There was a problem hiding this comment.
If I remember right, the idea was that a scale subresource could exist without the scale being reflected in the status. So there is no defaulting of this field.
There was a problem hiding this comment.
Adding on to what @sttts said, the user cannot write to the /status.status of the scale object at all. It is completely read-only for the user. Only a controller has write access to the status fields. So we can leave it empty and not have it default to anything. This also matches our plan with CRDs.
There was a problem hiding this comment.
This was intended to be purely internal to the scale client. The internal types aren't supposed to be used by other people.
There was a problem hiding this comment.
you mean change the name? Because they are marked as having the version be __internal.
There was a problem hiding this comment.
We don't make any use of that, but Go 1.5+ has packages called internal which can only be imported if your package and the internal one shares a common root. Does not belong into this PR, but I really think we should move a lot of internal code into internal packages. These client schemes are candidates for that. So I agree, we probably should not use the scale scheme here in the registry.
There was a problem hiding this comment.
Uses external type for autoscaling now. 👍
There was a problem hiding this comment.
I don't see what purpose this serves. This is never supposed to be used as an API server type.
b716144 to
b80000b
Compare
There was a problem hiding this comment.
This needs fixing. Will do that.
There was a problem hiding this comment.
Oops, done in 6f36088. Should be fine after a squash.
b80000b to
30fe1d1
Compare
|
/lgtm |
1 similar comment
|
/lgtm |
|
/lgtm |
There was a problem hiding this comment.
Per discussion in slack:
- This should be DefaultScaleGroupVersion, as it's not intended to prevent the server from serving additional versions. The version of polymorphic subresources is intended to be whatever the client of the subresource wants it to be. We haven't built this out because we don't have any multi-versioned subresources yet.
- The default is probably always going to be autoscaling/v1/scale.
- In the unlikely event we do change the default, we could always add this field at that time and backfill.
Therefore, let's remove this field, it's not necessary at the moment.
There was a problem hiding this comment.
Sorry to not have figured this out yesterday when I asked for changes!
|
/lgtm |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cblecker, deads2k, lavalamp, nikhita, sttts The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/test all [submit-queue is verifying that this PR is safe to merge] |
|
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here. |
|
🎉 |
|
@nikhita @sttts can you please link this to an issue in https://github.com/kubernetes/features |
|
@idvoretskyi It is a part of kubernetes/enhancements#95. |
|
/lgtm |
| func (r *crdHandler) serveResource(w http.ResponseWriter, req *http.Request, requestInfo *apirequest.RequestInfo, crdInfo *crdInfo, terminating bool, supportedTypes []string) http.HandlerFunc { | ||
| requestScope := crdInfo.requestScope | ||
| storage := crdInfo.storage.CustomResource | ||
| minRequestTimeout := 1 * time.Minute |
There was a problem hiding this comment.
@nikhita do you know what's the point of setting a constant timeout here?
Fixes #38113
Fixes #58778
Related:
kubectl scale: kubectl scale: support Unstructured objects #58283Add types:
CustomResourceSubresourcestype to CRD.CustomResourceSubresourceStatus: Fix protobuf generation for empty struct #55970.CustomResourceSubresources.nil).CustomResourceSubresources:SpecReplicasPathshould not be empty and should be a valid json path under.spec. If there is no value under the given path in the custom resource, the/scalesubresource will return an error on GET.StatusReplicasPathshould not be empty and should be a valid json path under.status. If there is no value under the given path in the custom resource, the status replica value in the/scalesubresource will default to 0.LabelSelectorPathis optional and should be a valid json path under.status. If there is no value underLabelSelectorPathin the custom resource, the status label selector value in the/scalesubresource will default to the empty string.CustomResourceSubresourcesfeature gate is enabled, onlypropertiesis allowed under the root schema for CRD validation.Add status and scale subresources:
apimachinery/pkg/apis/meta/v1/unstructured/helpers.go.CustomResourceStoragewhich acts as storage for the custom resource and its status and scale subresources. Note: storage for status and scale is only enabled when the feature gate is enabled and the respective fields are enabled in the CRD.StatusRESTand itsNew(),Get()andUpdate()methods.ScaleRESTand itsNew(),Get()andUpdate()methods.autoscaling/v1.Scaleobject.PrepareForCreate,.status..metadata.generation= 1PrepareForUpdate,.status..statusand it is changed, set it back to its old value..statusbut the new object doesn't, set it to the old value..statusbut the new object does, delete it..specand it changed..specbut the new object does..specbut the new object doesn't.ValidateandValidateUpdate,specReplicasPathandstatusReplicasPathare >=0 and < maxInt32.statusStrategywith its methods.PrepareForUpdate:.spec..specand it is changed, set it back to its old value..specbut the new object doesn't, set it to the old value..specbut the new object does, delete it..metadata.ValidateStatusUpdate:.status.statusReplicasPathandlabelSelectorPathas above.crdInfo.status, if present).serveResource,serveStatusandserveScale./statusand/scaleresources, if enabled.Add tests:
etcd_test.go.subresources_test.go, use the polymporphic scale client to get and updateScale.yaml_test.go.Release note: