kubernetes/vendor/github.com
Kubernetes Submit Queue 6e856480c0
Merge pull request #55168 from nikhita/customresources-subresources
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.
```
2018-02-22 13:37:35 -08:00
..
abbot/go-http-auth update BUILD files 2017-10-15 18:18:13 -07:00
appc/spec update BUILD files 2017-10-15 18:18:13 -07:00
armon/circbuf update BUILD files 2017-10-15 18:18:13 -07:00
asaskevich/govalidator update BUILD files 2017-10-15 18:18:13 -07:00
aws/aws-sdk-go Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
Azure Update Azure GO SDK to v12.4.0-beta 2018-02-12 14:07:05 +08:00
beorn7/perks update BUILD files 2017-10-15 18:18:13 -07:00
blang/semver update BUILD files 2017-10-15 18:18:13 -07:00
chai2010/gettext-go update BUILD files 2017-10-15 18:18:13 -07:00
cloudflare/cfssl update BUILD files 2017-10-15 18:18:13 -07:00
clusterhq/flocker-go update BUILD files 2017-10-15 18:18:13 -07:00
cockroachdb/cmux Version bump to etcd v3.2.13 2018-01-07 08:22:08 -08:00
codedellemc/goscaleio update BUILD files 2017-10-15 18:18:13 -07:00
codegangsta/negroni update BUILD files 2017-10-15 18:18:13 -07:00
container-storage-interface/spec Updating vendor file and dependency 2018-02-16 13:28:38 -05:00
containerd Bump runc to d5b4a3e 2018-01-12 14:22:50 -05:00
containernetworking/cni Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
coreos bump(github.com/coreos/go-oidc): 065b426bd41667456c1a924468f507673629c46b 2018-02-16 10:57:52 -08:00
cpuguy83/go-md2man update BUILD files 2017-10-15 18:18:13 -07:00
cyphar/filepath-securejoin Bump runc to d5b4a3e 2018-01-12 14:22:50 -05:00
d2g Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
davecgh/go-spew update BUILD files 2017-10-15 18:18:13 -07:00
daviddengcn/go-colortext Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
dchest/safefile Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
dgrijalva/jwt-go update BUILD files 2017-10-15 18:18:13 -07:00
docker Bump runc to d5b4a3e 2018-01-12 14:22:50 -05:00
elazarl update BUILD files 2017-10-15 18:18:13 -07:00
emicklei update BUILD files 2017-10-15 18:18:13 -07:00
euank/go-kmsg-parser update BUILD files 2017-10-15 18:18:13 -07:00
evanphx/json-patch update BUILD files 2017-10-15 18:18:13 -07:00
exponent-io/jsonpath update BUILD files 2017-10-15 18:18:13 -07:00
fatih/camelcase update BUILD files 2017-10-15 18:18:13 -07:00
fsnotify/fsnotify Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
garyburd/redigo update BUILD files 2017-10-15 18:18:13 -07:00
ghodss/yaml update BUILD files 2017-10-15 18:18:13 -07:00
go-ini/ini Update AWS SDK to 1.12.7 2017-10-27 20:19:27 -04:00
go-openapi bump(go-openapi/validate): d509235108fcf6ab4913d2dcb3a2260c0db2108e 2018-02-22 01:11:28 +05:30
godbus/dbus Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
gogo/protobuf udpate cadvisor dependency to v0.28.2 2017-11-22 08:45:26 -08:00
golang Version bump to etcd v3.2.13 2018-01-07 08:22:08 -08:00
google Update cadvisor to 6116f265302357cbb10f84737af30b1f13ce2d6c 2018-02-08 22:37:39 +00:00
googleapis/gnostic Update openapi to use kube-openapi code 2017-10-20 09:21:06 -07:00
gophercloud/gophercloud Update to latest gophercloud/gophercloud 2018-02-14 14:02:57 -05:00
gorilla update BUILD files 2017-10-15 18:18:13 -07:00
gregjones/httpcache update BUILD files 2017-10-15 18:18:13 -07:00
grpc-ecosystem Version bump to grpc-gateway v1.3.0 2018-01-07 08:22:08 -08:00
hashicorp update BUILD files 2017-10-15 18:18:13 -07:00
hawkular/hawkular-client-go update BUILD files 2017-10-15 18:18:13 -07:00
heketi/heketi update BUILD files 2017-10-15 18:18:13 -07:00
howeyc/gopass Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
imdario/mergo update BUILD files 2017-10-15 18:18:13 -07:00
inconshreveable/mousetrap Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
influxdata/influxdb update BUILD files 2017-10-15 18:18:13 -07:00
JeffAshton/win_pdh Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
jmespath/go-jmespath Update AWS SDK to 1.12.7 2017-10-27 20:19:27 -04:00
jonboulle/clockwork update BUILD files 2017-10-15 18:18:13 -07:00
json-iterator/go bump(github.com/json-iterator/go): 13f86432b882000a51c6e610c620974462691a97 2017-12-13 15:11:17 +05:30
jteeuwen/go-bindata Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
kardianos/osext Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
kr Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
libopenstorage/openstorage Update openapi to use kube-openapi code 2017-10-20 09:21:06 -07:00
lpabon/godbc update BUILD files 2017-10-15 18:18:13 -07:00
magiconair/properties update BUILD files 2017-10-15 18:18:13 -07:00
mailru/easyjson update BUILD files 2017-10-15 18:18:13 -07:00
MakeNowJust/heredoc Update vendored package heredoc 2017-11-02 12:57:22 +11:00
marstr/guid Update Azure GO SDK to v12.4.0-beta 2018-02-12 14:07:05 +08:00
matttproud/golang_protobuf_extensions update BUILD files 2017-10-15 18:18:13 -07:00
Microsoft Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
miekg/dns Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
mindprince/gonvml Update cAdvisor. 2017-11-10 14:54:28 -08:00
mistifyio/go-zfs update BUILD files 2017-10-15 18:18:13 -07:00
mitchellh update BUILD files 2017-10-15 18:18:13 -07:00
mohae/deepcopy update BUILD files 2017-10-15 18:18:13 -07:00
mreiferson/go-httpclient update BUILD files 2017-10-15 18:18:13 -07:00
mrunalp/fileutils update BUILD files 2017-10-15 18:18:13 -07:00
mvdan/xurls update BUILD files 2017-10-15 18:18:13 -07:00
mxk/go-flowrate update BUILD files 2017-10-15 18:18:13 -07:00
Nvveen/Gotty update BUILD files 2017-10-15 18:18:13 -07:00
NYTimes/gziphandler update BUILD files 2017-10-15 18:18:13 -07:00
onsi Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
opencontainers bump(github.com/opencontainers/runc): 595bea022f077a9e17d7473b34fbaf1adaed9e43 2018-02-20 14:07:00 -05:00
pborman/uuid update BUILD files 2017-10-15 18:18:13 -07:00
pelletier update BUILD files 2017-10-15 18:18:13 -07:00
peterbourgon/diskv update BUILD files 2017-10-15 18:18:13 -07:00
pkg Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
pmezard/go-difflib update BUILD files 2017-10-15 18:18:13 -07:00
pquerna/cachecontrol bump(github.com/coreos/go-oidc): 065b426bd41667456c1a924468f507673629c46b 2018-02-16 10:57:52 -08:00
prometheus update BUILD files 2017-10-15 18:18:13 -07:00
PuerkitoBio update BUILD files 2017-10-15 18:18:13 -07:00
quobyte/api update BUILD files 2017-10-15 18:18:13 -07:00
rancher/go-rancher update BUILD files 2017-10-15 18:18:13 -07:00
renstrom/dedent update BUILD files 2017-10-15 18:18:13 -07:00
robfig/cron update BUILD files 2017-10-15 18:18:13 -07:00
rubiojr/go-vhd update BUILD files 2017-10-15 18:18:13 -07:00
russross/blackfriday update BUILD files 2017-10-15 18:18:13 -07:00
satori/go.uuid Update Azure GO SDK to v12.1.0 2018-01-04 14:18:31 +08:00
seccomp/libseccomp-golang Bump dependencies for build tag fixes 2018-02-21 12:50:32 -08:00
shurcooL/sanitized_anchor_name update BUILD files 2017-10-15 18:18:13 -07:00
sirupsen/logrus Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
spf13 bump pflag 2017-12-25 16:23:37 +08:00
storageos/go-api Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
stretchr update BUILD files 2017-10-15 18:18:13 -07:00
syndtr/gocapability Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
tools/godep Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
ugorji/go update BUILD files 2017-10-15 18:18:13 -07:00
vishvananda Autogenerate BUILD files 2017-12-23 13:12:11 -08:00
vmware Bump dependencies for build tag fixes 2018-02-21 12:50:32 -08:00
xanzy/go-cloudstack update BUILD files 2017-10-15 18:18:13 -07:00
xiang90/probing update BUILD files 2017-10-15 18:18:13 -07:00
xyproto/simpleredis update BUILD files 2017-10-15 18:18:13 -07:00