• Kubernetes Submit Queue's avatar
    Merge pull request #55168 from nikhita/customresources-subresources · 6e856480
    Kubernetes Submit Queue authored
    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.
    ```
    6e856480
Name
Last commit
Last update
..
Azure Loading commit data...
JeffAshton/win_pdh Loading commit data...
MakeNowJust/heredoc Loading commit data...
Microsoft Loading commit data...
NYTimes/gziphandler Loading commit data...
Nvveen/Gotty Loading commit data...
PuerkitoBio Loading commit data...
abbot/go-http-auth Loading commit data...
appc/spec Loading commit data...
armon/circbuf Loading commit data...
asaskevich/govalidator Loading commit data...
aws/aws-sdk-go Loading commit data...
beorn7/perks Loading commit data...
blang/semver Loading commit data...
chai2010/gettext-go Loading commit data...
cloudflare/cfssl Loading commit data...
clusterhq/flocker-go Loading commit data...
cockroachdb/cmux Loading commit data...
codedellemc/goscaleio Loading commit data...
codegangsta/negroni Loading commit data...
container-storage-interface/spec Loading commit data...
containerd Loading commit data...
containernetworking/cni Loading commit data...
coreos Loading commit data...
cpuguy83/go-md2man Loading commit data...
cyphar/filepath-securejoin Loading commit data...
d2g Loading commit data...
davecgh/go-spew Loading commit data...
daviddengcn/go-colortext Loading commit data...
dchest/safefile Loading commit data...
dgrijalva/jwt-go Loading commit data...
docker Loading commit data...
elazarl Loading commit data...
emicklei Loading commit data...
euank/go-kmsg-parser Loading commit data...
evanphx/json-patch Loading commit data...
exponent-io/jsonpath Loading commit data...
fatih/camelcase Loading commit data...
fsnotify/fsnotify Loading commit data...
garyburd/redigo Loading commit data...
ghodss/yaml Loading commit data...
go-ini/ini Loading commit data...
go-openapi Loading commit data...
godbus/dbus Loading commit data...
gogo/protobuf Loading commit data...
golang Loading commit data...
google Loading commit data...
googleapis/gnostic Loading commit data...
gophercloud/gophercloud Loading commit data...
gorilla Loading commit data...
gregjones/httpcache Loading commit data...
grpc-ecosystem Loading commit data...
hashicorp Loading commit data...
hawkular/hawkular-client-go Loading commit data...
heketi/heketi Loading commit data...
howeyc/gopass Loading commit data...
imdario/mergo Loading commit data...
inconshreveable/mousetrap Loading commit data...
influxdata/influxdb Loading commit data...
jmespath/go-jmespath Loading commit data...
jonboulle/clockwork Loading commit data...
json-iterator/go Loading commit data...
jteeuwen/go-bindata Loading commit data...
kardianos/osext Loading commit data...
kr Loading commit data...
libopenstorage/openstorage Loading commit data...
lpabon/godbc Loading commit data...
magiconair/properties Loading commit data...
mailru/easyjson Loading commit data...
marstr/guid Loading commit data...
matttproud/golang_protobuf_extensions Loading commit data...
miekg/dns Loading commit data...
mindprince/gonvml Loading commit data...
mistifyio/go-zfs Loading commit data...
mitchellh Loading commit data...
mohae/deepcopy Loading commit data...
mreiferson/go-httpclient Loading commit data...
mrunalp/fileutils Loading commit data...
mvdan/xurls Loading commit data...
mxk/go-flowrate Loading commit data...
onsi Loading commit data...
opencontainers Loading commit data...
pborman/uuid Loading commit data...
pelletier Loading commit data...
peterbourgon/diskv Loading commit data...
pkg Loading commit data...
pmezard/go-difflib Loading commit data...
pquerna/cachecontrol Loading commit data...
prometheus Loading commit data...
quobyte/api Loading commit data...
rancher/go-rancher Loading commit data...
renstrom/dedent Loading commit data...
robfig/cron Loading commit data...
rubiojr/go-vhd Loading commit data...
russross/blackfriday Loading commit data...
satori/go.uuid Loading commit data...
seccomp/libseccomp-golang Loading commit data...
shurcooL/sanitized_anchor_name Loading commit data...
sirupsen/logrus Loading commit data...
spf13 Loading commit data...
storageos/go-api Loading commit data...
stretchr Loading commit data...
syndtr/gocapability Loading commit data...
tools/godep Loading commit data...
ugorji/go Loading commit data...
vishvananda Loading commit data...
vmware Loading commit data...
xanzy/go-cloudstack Loading commit data...
xiang90/probing Loading commit data...
xyproto/simpleredis Loading commit data...