mirror of https://github.com/k3s-io/k3s
Merge pull request #63619 from roycaihw/get-crd-status
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. CRD Status subresource support get+update+patch CRD Status previously only supports PUT and returns 405 on GET and PATCH /assign @sttts /sig api-machinery **Release note**: ```release-note CustomResourceDefinitions Status subresource now supports GET and PATCH ```pull/8/head
commit
769b7dadca
|
@ -20060,6 +20060,41 @@
|
|||
]
|
||||
},
|
||||
"/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/{name}/status": {
|
||||
"get": {
|
||||
"description": "read status of the specified CustomResourceDefinition",
|
||||
"consumes": [
|
||||
"*/*"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/yaml",
|
||||
"application/vnd.kubernetes.protobuf"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"tags": [
|
||||
"apiextensions_v1beta1"
|
||||
],
|
||||
"operationId": "readApiextensionsV1beta1CustomResourceDefinitionStatus",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinition"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Unauthorized"
|
||||
}
|
||||
},
|
||||
"x-kubernetes-action": "get",
|
||||
"x-kubernetes-group-version-kind": {
|
||||
"group": "apiextensions.k8s.io",
|
||||
"kind": "CustomResourceDefinition",
|
||||
"version": "v1beta1"
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"description": "replace status of the specified CustomResourceDefinition",
|
||||
"consumes": [
|
||||
|
@ -20111,6 +20146,53 @@
|
|||
"version": "v1beta1"
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"description": "partially update status of the specified CustomResourceDefinition",
|
||||
"consumes": [
|
||||
"application/json-patch+json",
|
||||
"application/merge-patch+json",
|
||||
"application/strategic-merge-patch+json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/yaml",
|
||||
"application/vnd.kubernetes.protobuf"
|
||||
],
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"tags": [
|
||||
"apiextensions_v1beta1"
|
||||
],
|
||||
"operationId": "patchApiextensionsV1beta1CustomResourceDefinitionStatus",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinition"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Unauthorized"
|
||||
}
|
||||
},
|
||||
"x-kubernetes-action": "patch",
|
||||
"x-kubernetes-group-version-kind": {
|
||||
"group": "apiextensions.k8s.io",
|
||||
"kind": "CustomResourceDefinition",
|
||||
"version": "v1beta1"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"uniqueItems": true,
|
||||
|
|
|
@ -116,6 +116,8 @@ type StatusREST struct {
|
|||
store *genericregistry.Store
|
||||
}
|
||||
|
||||
var _ = rest.Patcher(&StatusREST{})
|
||||
|
||||
func (r *StatusREST) New() runtime.Object {
|
||||
return &unstructured.Unstructured{}
|
||||
}
|
||||
|
|
|
@ -160,12 +160,17 @@ type StatusREST struct {
|
|||
store *genericregistry.Store
|
||||
}
|
||||
|
||||
var _ = rest.Updater(&StatusREST{})
|
||||
var _ = rest.Patcher(&StatusREST{})
|
||||
|
||||
func (r *StatusREST) New() runtime.Object {
|
||||
return &apiextensions.CustomResourceDefinition{}
|
||||
}
|
||||
|
||||
// Get retrieves the object from the storage. It is required to support Patch.
|
||||
func (r *StatusREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
return r.store.Get(ctx, name, options)
|
||||
}
|
||||
|
||||
// Update alters the status subset of an object.
|
||||
func (r *StatusREST) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (runtime.Object, bool, error) {
|
||||
return r.store.Update(ctx, name, objInfo, createValidation, updateValidation)
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
@ -799,3 +800,38 @@ func TestNameConflict(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusGetAndPatch(t *testing.T) {
|
||||
stopCh, apiExtensionClient, dynamicClient, err := testserver.StartDefaultServerWithClients()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer close(stopCh)
|
||||
|
||||
noxuDefinition := testserver.NewNoxuCustomResourceDefinition(apiextensionsv1beta1.NamespaceScoped)
|
||||
err = testserver.CreateNewCustomResourceDefinition(noxuDefinition, apiExtensionClient, dynamicClient)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// make sure we don't get 405 Method Not Allowed from Getting CRD/status subresource
|
||||
result := &apiextensionsv1beta1.CustomResourceDefinition{}
|
||||
err = apiExtensionClient.ApiextensionsV1beta1().RESTClient().Get().
|
||||
Resource("customresourcedefinitions").
|
||||
Name(noxuDefinition.Name).
|
||||
SubResource("status").
|
||||
Do().
|
||||
Into(result)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// make sure we don't get 405 Method Not Allowed from Patching CRD/status subresource
|
||||
_, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().
|
||||
Patch(noxuDefinition.Name, types.StrategicMergePatchType,
|
||||
[]byte(fmt.Sprintf(`{"labels":{"test-label":"dummy"}}`)),
|
||||
"status")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue