mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-02-18 18:28:18 -05:00
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>. apiextensions: add subresources for custom resources Fixes #38113 Fixes #58778 **Related**: - Proposal: https://github.com/kubernetes/community/pull/913 - For custom resources to work with `kubectl scale`: https://github.com/kubernetes/kubernetes/pull/58283 **Add types**: - Add `CustomResourceSubResources` type to CRD. - Fix proto generation for `CustomResourceSubResourceStatus`: https://github.com/kubernetes/kubernetes/pull/55970. - Add feature gate for `CustomResourceSubResources`. - Update CRD strategy: if feature gate is disabled, this feature is dropped (i.e. set to `nil`). - Add validation for `CustomResourceSubResources`: - `SpecReplicasPath` should not be empty and should be a valid json path under `.spec`. If there is no value under the given path in the CustomResource, the `/scale` subresource will return an error on GET. - `StatusReplicasPath` should not be empty and should be a valid json path under `.status`. If there is no value under the given path in the CustomResource, the status replica value in the /scale subresource will default to 0. - If present, `LabelSelectorPath` should be a valid json path. If there is no value under `LabelSelectorPath` in the CustomResource, the status label selector value in the `/scale` subresource will default to the empty string. - `ScaleGroupVersion` should be `autoscaling/v1`. - If `CustomResourceSubResources` is enabled, only `properties` is allowed under the root schema for CRD validation. **Add status and scale subresources**: - Use helper functions from `apimachinery/pkg/apis/meta/v1/unstructured/helpers.go`. - Improve error handling: https://github.com/kubernetes/kubernetes/pull/56563, https://github.com/kubernetes/kubernetes/pull/58215. - Introduce Registry interface for storage. - Update storage: - Introduce `CustomResourceStorage` which 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. - Introduce `StatusREST` and its `New()`, `Get()` and `Update()` methods. - Introduce `ScaleREST` and its `New()`, `Get()` and `Update()` methods. - Get and Update use the json paths from the CRD and use it to return an `autoscaling/v1.Scale` object. - Update strategy: - In `PrepareForCreate`, - Clear `.status`. - Set `.metadata.generation` = 1 - In `PrepareForUpdate`, - Do not update `.status`. - If both the old and new objects have `.status` and it is changed, set it back to its old value. - If the old object has a `.status` but the new object doesn't, set it to the old value. - If old object did not have a `.status` but the new object does, delete it. - Increment generation if spec changes i.e. in the following cases: - If both the old and new objects had `.spec` and it changed. - If the old object did not have `.spec` but the new object does. - If the old object had a `.spec` but the new object doesn't. - In `Validate` and `ValidateUpdate`, - ensure that values at `specReplicasPath` and `statusReplicasPath` are >=0 and < maxInt32. - make sure there are no errors in getting the value at all the paths. - Introduce `statusStrategy` with its methods. - In `PrepareForUpdate`: - Do not update `.spec`. - If both the old and new objects have `.spec` and it is changed, set it back to its old value. - If the old object has a `.spec` but the new object doesn't, set it to the old value. - If old object did not have a `.spec` but the new object does, delete it. - Do not update `.metadata`. - In `ValidateStatusUpdate`: - For CRD validation, validate only under `.status`. - Validate value at `statusReplicasPath` as above. If `labelSelectorPath` is a path under `.status`, then validate it as well. - Plug into the custom resource handler: - Store all three storage - customResource, status and scale in `crdInfo`. - Use the storage as per the subresource in the request. - Use the validator as per the subresource (for status, only use the schema for `status`, if present). - Serve the endpoint as per the subresource - see `serveResource`, `serveStatus` and `serveScale`. - Update discovery by adding the `/status` and `/scale` resources, if enabled. **Add tests**: - Add unit tests in `etcd_test.go`. - Add integration tests. - In `subresources_test.go`, use the [polymporphic scale client](https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/client-go/scale) to get and update `Scale`. - Add a test to check everything works fine with yaml in `yaml_test.go`. **Release note**: ```release-note `/status` and `/scale` subresources are added for custom resources. ``` |
||
|---|---|---|
| .. | ||
| boilerplate | ||
| cmd/teststale | ||
| e2e-internal | ||
| gen-swagger-doc | ||
| jenkins | ||
| lib | ||
| make-rules | ||
| testdata | ||
| verify-flags | ||
| .golint_failures | ||
| autogenerated_placeholder.txt | ||
| benchmark-go.sh | ||
| BUILD | ||
| build-cross.sh | ||
| build-go.sh | ||
| build-ui.sh | ||
| cherry_pick_pull.sh | ||
| dev-build-and-push.sh | ||
| dev-build-and-up.sh | ||
| dev-push-hyperkube.sh | ||
| e2e-node-test.sh | ||
| e2e.go | ||
| e2e_test.go | ||
| generate-bindata.sh | ||
| generate-docs.sh | ||
| get-build.sh | ||
| ginkgo-e2e.sh | ||
| godep-restore.sh | ||
| godep-save.sh | ||
| grab-profiles.sh | ||
| import-restrictions.yaml | ||
| install-etcd.sh | ||
| list-feature-tests.sh | ||
| local-up-cluster.sh | ||
| lookup_pull.py | ||
| OWNERS | ||
| print-workspace-status.sh | ||
| run-in-gopath.sh | ||
| test-cmd.sh | ||
| test-go.sh | ||
| test-integration.sh | ||
| test-update-storage-objects.sh | ||
| update-all.sh | ||
| update-api-reference-docs.sh | ||
| update-bazel.sh | ||
| update-cloudprovider-gce.sh | ||
| update-codegen.sh | ||
| update-generated-device-plugin-dockerized.sh | ||
| update-generated-device-plugin.sh | ||
| update-generated-docs.sh | ||
| update-generated-kms-dockerized.sh | ||
| update-generated-kms.sh | ||
| update-generated-protobuf-dockerized.sh | ||
| update-generated-protobuf.sh | ||
| update-generated-runtime-dockerized.sh | ||
| update-generated-runtime.sh | ||
| update-generated-swagger-docs.sh | ||
| update-godep-licenses.sh | ||
| update-gofmt.sh | ||
| update-openapi-spec.sh | ||
| update-staging-godeps-dockerized.sh | ||
| update-staging-godeps.sh | ||
| update-swagger-spec.sh | ||
| update-translations.sh | ||
| update_owners.py | ||
| verify-all.sh | ||
| verify-api-groups.sh | ||
| verify-api-reference-docs.sh | ||
| verify-bazel.sh | ||
| verify-boilerplate.sh | ||
| verify-cli-conventions.sh | ||
| verify-cloudprovider-gce.sh | ||
| verify-codegen.sh | ||
| verify-description.sh | ||
| verify-flags-underscore.py | ||
| verify-generated-device-plugin.sh | ||
| verify-generated-docs.sh | ||
| verify-generated-files-remake.sh | ||
| verify-generated-kms.sh | ||
| verify-generated-protobuf.sh | ||
| verify-generated-runtime.sh | ||
| verify-generated-swagger-docs.sh | ||
| verify-godep-licenses.sh | ||
| verify-godeps.sh | ||
| verify-gofmt.sh | ||
| verify-golint.sh | ||
| verify-govet.sh | ||
| verify-import-boss.sh | ||
| verify-imports.sh | ||
| verify-linkcheck.sh | ||
| verify-no-vendor-cycles.sh | ||
| verify-openapi-spec.sh | ||
| verify-pkg-names.sh | ||
| verify-readonly-packages.sh | ||
| verify-staging-godeps.sh | ||
| verify-swagger-spec.sh | ||
| verify-symbols.sh | ||
| verify-test-images.sh | ||
| verify-test-owners.sh | ||