Move snapshot APIs and client to v1 (no controller changes)

This commit is contained in:
xing-yang
2020-11-02 22:16:37 +00:00
parent e56a75b271
commit 9e21c6240d
65 changed files with 5914 additions and 220 deletions

View File

@@ -8,7 +8,7 @@ This README documents:
This is the script to update clientset/informers/listers and API deepcopy code using [code-generator](https://github.com/kubernetes/code-generator).
Make sure to run this script after making changes to /client/apis/volumesnapshot/v1beta1/types.go.
Make sure to run this script after making changes to /client/apis/volumesnapshot/v1/types.go.
Pre-requisites for running update-generated-code.sh:
@@ -30,31 +30,36 @@ Run: ./hack/update-generated-code.sh from the client directory.
Once you run the script, you will get an output as follows:
```bash
Generating deepcopy funcs
Generating clientset for volumesnapshot:v1beta1 at github.com/kubernetes-csi/external-snapshotter/client/v3/clientset
Generating listers for volumesnapshot:v1beta1 at github.com/kubernetes-csi/external-snapshotter/client/v3/listers
Generating informers for volumesnapshot:v1beta1 at github.com/kubernetes-csi/external-snapshotter/client/v3/informers
Generating clientset for volumesnapshot:v1 at github.com/kubernetes-csi/external-snapshotter/client/v3/clientset
Generating listers for volumesnapshot:v1 at github.com/kubernetes-csi/external-snapshotter/client/v3/listers
Generating informers for volumesnapshot:v1 at github.com/kubernetes-csi/external-snapshotter/client/v3/informers
```
NOTE: We need to keep both v1beta1 and v1 snapshot clients at the current phase.
## update-crd.sh
NOTE: We need to serve both v1beta1 and v1 snapshot APIs and keep storage version at v1beta1 at the current phase.
This is the script to update CRD yaml files under /client/config/crd/ based on types.go file.
Make sure to run this script after making changes to /client/apis/volumesnapshot/v1beta1/types.go.
Make sure to run this script after making changes to /client/apis/volumesnapshot/v1/types.go.
Follow these steps to update the CRD:
* Run ./hack/update-crd.sh from client directory, new yaml files should have been created under ./config/crd/
* Add api-approved.kubernetes.io annotation value in all yaml files in the metadata section with the PR where the API is approved by the API reviewers. The current approved PR for snapshot beta API is https://github.com/kubernetes-csi/external-snapshotter/pull/139. Refer to https://github.com/kubernetes/enhancements/pull/1111 for details about this annotation.
* Add api-approved.kubernetes.io annotation value in all yaml files in the metadata section with the PR where the API is approved by the API reviewers. The current approved PR for snapshot v1 API is https://github.com/kubernetes-csi/external-snapshotter/pull/419. Refer to https://github.com/kubernetes/enhancements/pull/1111 for details about this annotation.
* Remove any metadata sections from the yaml file which does not belong to the generated type.
For example, the following command will add a metadata section for a nested object, remove any newly added metadata sections. TODO(xiangqian): this is to make sure the generated CRD is compatible with apiextensions.k8s.io/v1. Once controller-gen supports generating CRD with apiextensions.k8s.io/v1, switch to use the correct version of controller-gen and remove the last step from this README.
```bash
./hack/update-crd.sh; git diff
+ metadata:
+ description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
type: object
```
* Update the restoreSize property to string in snapshot.storage.k8s.io_volumesnapshots.yaml
@@ -95,3 +100,106 @@ Update the restoreSize property to use type string only:
```
* In `client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml`, we need to add the `oneOf` constraint to make sure only one of `persistentVolumeClaimName` and `volumeSnapshotContentName` is specified in the `source` field of the `spec` of `VolumeSnapshot`.
```
source:
description: source specifies where a snapshot will be created from. This field is immutable after creation. Required.
properties:
persistentVolumeClaimName:
description: persistentVolumeClaimName specifies the name of the PersistentVolumeClaim object representing the volume from which a snapshot should be created. This PVC is assumed to be in the same namespace as the VolumeSnapshot object. This field should be set if the snapshot does not exists, and should be created. This field is immutable.
type: string
volumeSnapshotContentName:
description: volumeSnapshotContentName specifies the name of a pre-existing VolumeSnapshotContent object representing an existing volume snapshot. This field should be set if the snapshot already exists. This field is immutable.
type: string
type: object
oneOf:
- required: ["persistentVolumeClaimName"]
- required: ["volumeSnapshotContentName"]
volumeSnapshotClassName:
```
* In `client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml `, we need to add the `oneOf` constraint to make sure only one of `snapshotHandle` and `volumeHandle` is specified in the `source` field of the `spec` of `VolumeSnapshotContent`.
```
source:
description: source specifies from where a snapshot will be created. This field is immutable after creation. Required.
properties:
snapshotHandle:
description: snapshotHandle specifies the CSI "snapshot_id" of a pre-existing snapshot on the underlying storage system. This field is immutable.
type: string
volumeHandle:
description: volumeHandle specifies the CSI "volume_id" of the volume from which a snapshot should be dynamically taken from. This field is immutable.
type: string
type: object
oneOf:
- required: ["snapshotHandle"]
- required: ["volumeHandle"]
volumeSnapshotClassName:
```
* Because we need to serve both v1 and v1beta1 snapshot APIs, we need to make sure that both v1 and v1beta1 APIs are in the manifest yaml file. Because `update-crd.sh` only generates v1 manifest, make sure to copy the v1beta1 manifest below the v1 manifest after running `update-crd.sh` in the manifest yaml files. See `snapshot.storage.k8s.io_volumesnapshots.yaml` as an example. `served` is true for both v1beta1 and v1. `storage` is true for v1beta and false for v1.
```
spec:
group: snapshot.storage.k8s.io
names:
kind: VolumeSnapshot
listKind: VolumeSnapshotList
plural: volumesnapshots
singular: volumesnapshot
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: Indicates if a snapshot is ready to be used to restore a volume.
jsonPath: .status.readyToUse
name: ReadyToUse
type: boolean
......
- description: Timestamp when the point-in-time snapshot is taken by the underlying storage system.
jsonPath: .status.creationTime
name: CreationTime
type: date
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1
schema:
openAPIV3Schema:
description: VolumeSnapshot is a user's request for either creating a point-in-time snapshot of a persistent volume, or binding to a pre-existing snapshot.
properties:
......
served: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
- description: Indicates if a snapshot is ready to be used to restore a volume.
jsonPath: .status.readyToUse
name: ReadyToUse
type: boolean
......
- description: Timestamp when the point-in-time snapshot is taken by the underlying storage system.
jsonPath: .status.creationTime
name: CreationTime
type: date
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1beta1
schema:
openAPIV3Schema:
description: VolumeSnapshot is a user's request for either creating a point-in-time snapshot of a persistent volume, or binding to a pre-existing snapshot.
properties:
......
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
``````

View File

@@ -39,7 +39,7 @@ then
exit 1;
fi
$CONTROLLER_GEN crd:crdVersions=v1,trivialVersions=true paths=${SCRIPT_ROOT}/apis/volumesnapshot/v1beta1
$CONTROLLER_GEN crd:crdVersions=v1,trivialVersions=false paths=${SCRIPT_ROOT}/apis/volumesnapshot/v1
# To use your own boilerplate text use:
# --go-header-file ${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt

View File

@@ -24,9 +24,10 @@ SCRIPT_ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
# We should only be generating code for v1 now, while keeping the existing generated code for v1beta1
${GOPATH}/src/k8s.io/code-generator/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/kubernetes-csi/external-snapshotter/client/v3 github.com/kubernetes-csi/external-snapshotter/client/v3/apis \
volumesnapshot:v1beta1 \
volumesnapshot:v1beta1,v1 \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt
# To use your own boilerplate text use: