From 5f282e0809c21476de73dbe1c7dc3c5ff222f396 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 19 Apr 2021 14:43:27 +0200 Subject: [PATCH 1/4] hack/update-codegen.sh: add -mod=vendor to work with recent Golang --- hack/update-codegen.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 14e99003e..e22c33548 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -23,24 +23,24 @@ API_PKG="${THIS_REPO}/pkg/apis/migration/v1alpha1" # Absolute path to this repo THIS_REPO_ABSOLUTE="$(cd "$(dirname "${BASH_SOURCE}")/.." && pwd -P)" -go run ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen \ +go run -mod=vendor ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen \ schemapatch:manifests="${THIS_REPO_ABSOLUTE}/manifests" \ paths="${THIS_REPO_ABSOLUTE}/pkg/apis/migration/v1alpha1" \ output:dir="${THIS_REPO_ABSOLUTE}/manifests" -go run ./vendor/k8s.io/code-generator/cmd/client-gen \ +go run -mod=vendor ./vendor/k8s.io/code-generator/cmd/client-gen \ --output-package "${THIS_REPO}/pkg/clients" \ --clientset-name="clientset" \ --input-base="${THIS_REPO}" \ --input="pkg/apis/migration/v1alpha1" \ --go-header-file "${THIS_REPO_ABSOLUTE}/hack/boilerplate/boilerplate.generatego.txt" -go run ./vendor/k8s.io/code-generator/cmd/lister-gen \ +go run -mod=vendor ./vendor/k8s.io/code-generator/cmd/lister-gen \ --output-package "${THIS_REPO}/pkg/clients/lister" \ --input-dirs="${API_PKG}" \ --go-header-file "${THIS_REPO_ABSOLUTE}/hack/boilerplate/boilerplate.generatego.txt" -go run ./vendor/k8s.io/code-generator/cmd/informer-gen \ +go run -mod=vendor ./vendor/k8s.io/code-generator/cmd/informer-gen \ --output-package "${THIS_REPO}/pkg/clients/informer" \ --input-dirs="${API_PKG}" \ --go-header-file "${THIS_REPO_ABSOLUTE}/hack/boilerplate/boilerplate.generatego.txt" \ @@ -48,7 +48,7 @@ go run ./vendor/k8s.io/code-generator/cmd/informer-gen \ --versioned-clientset-package "${THIS_REPO}/pkg/clients/clientset" \ --listers-package "${THIS_REPO}/pkg/clients/lister" -go run ./vendor/k8s.io/code-generator/cmd/deepcopy-gen \ +go run -mod=vendor ./vendor/k8s.io/code-generator/cmd/deepcopy-gen \ --input-dirs="${API_PKG}" \ --output-file-base="zz_generated.deepcopy" \ --go-header-file "${THIS_REPO_ABSOLUTE}/hack/boilerplate/boilerplate.generatego.txt" From cc3f07210b68754fded3200d7ba7c96d91db9924 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 19 Apr 2021 14:49:40 +0200 Subject: [PATCH 2/4] hack/update-codegen: update CRDs --- manifests/storage_migration_crd.yaml | 14 +++++++------- manifests/storage_state_crd.yaml | 19 ++++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/manifests/storage_migration_crd.yaml b/manifests/storage_migration_crd.yaml index 501e8e63b..a7dabab3f 100644 --- a/manifests/storage_migration_crd.yaml +++ b/manifests/storage_migration_crd.yaml @@ -21,8 +21,8 @@ spec: status: {} schema: openAPIV3Schema: - description: StorageVersionMigration represents a migration of stored data to - the latest storage version. + description: StorageVersionMigration represents a migration of stored data + to the latest storage version. type: object properties: apiVersion: @@ -45,9 +45,9 @@ spec: properties: continueToken: description: The token used in the list options to get the next chunk - of objects to migrate. When the .status.conditions indicates the migration - is "Running", users can use this token to check the progress of the - migration. + of objects to migrate. When the .status.conditions indicates the + migration is "Running", users can use this token to check the progress + of the migration. type: string resource: description: The resource that is being migrated. The migrator sends @@ -68,8 +68,8 @@ spec: type: object properties: conditions: - description: The latest available observations of the migration's current - state. + description: The latest available observations of the migration's + current state. type: array items: description: Describes the state of a migration at a certain point. diff --git a/manifests/storage_state_crd.yaml b/manifests/storage_state_crd.yaml index 30f577ab0..a06e14455 100644 --- a/manifests/storage_state_crd.yaml +++ b/manifests/storage_state_crd.yaml @@ -35,11 +35,8 @@ spec: submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: + description: The name must be "<.spec.resource.resouce>.<.spec.resource.group>". type: object - properties: - name: - description: The name must be "<.spec.resource.resouce>.<.spec.resource.group>". - type: string spec: description: Specification of the storage state. type: object @@ -71,14 +68,14 @@ spec: format: date-time persistedStorageVersionHashes: description: The hash values of storage versions that persisted instances - of spec.resource might still be encoded in. "Unknown" is a valid value - in the list, and is the default value. It is not safe to upgrade or - downgrade to an apiserver binary that does not support all versions + of spec.resource might still be encoded in. "Unknown" is a valid + value in the list, and is the default value. It is not safe to upgrade + or downgrade to an apiserver binary that does not support all versions listed in this field, or if "Unknown" is listed. Once the storage - version migration for this resource has completed, the value of this - field is refined to only contain the currentStorageVersionHash. Once - the apiserver has changed the storage version, the new storage version - is appended to the list. + version migration for this resource has completed, the value of + this field is refined to only contain the currentStorageVersionHash. + Once the apiserver has changed the storage version, the new storage + version is appended to the list. type: array items: type: string From 7d4e109a101744e58fb467db1688df62e87a421f Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 19 Apr 2021 14:49:49 +0200 Subject: [PATCH 3/4] hack/update-codegen: update clients --- pkg/clients/clientset/fake/register.go | 2 +- pkg/clients/lister/migration/v1alpha1/storagestate.go | 3 +++ .../lister/migration/v1alpha1/storageversionmigration.go | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/clients/clientset/fake/register.go b/pkg/clients/clientset/fake/register.go index a9d41977c..248667094 100644 --- a/pkg/clients/clientset/fake/register.go +++ b/pkg/clients/clientset/fake/register.go @@ -29,7 +29,7 @@ import ( var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) -var parameterCodec = runtime.NewParameterCodec(scheme) + var localSchemeBuilder = runtime.SchemeBuilder{ migrationv1alpha1.AddToScheme, } diff --git a/pkg/clients/lister/migration/v1alpha1/storagestate.go b/pkg/clients/lister/migration/v1alpha1/storagestate.go index 2cb398236..a555aa2f1 100644 --- a/pkg/clients/lister/migration/v1alpha1/storagestate.go +++ b/pkg/clients/lister/migration/v1alpha1/storagestate.go @@ -26,10 +26,13 @@ import ( ) // StorageStateLister helps list StorageStates. +// All objects returned here must be treated as read-only. type StorageStateLister interface { // List lists all StorageStates in the indexer. + // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*v1alpha1.StorageState, err error) // Get retrieves the StorageState from the index for a given name. + // Objects returned here must be treated as read-only. Get(name string) (*v1alpha1.StorageState, error) StorageStateListerExpansion } diff --git a/pkg/clients/lister/migration/v1alpha1/storageversionmigration.go b/pkg/clients/lister/migration/v1alpha1/storageversionmigration.go index c57dd54b8..8858bd2dd 100644 --- a/pkg/clients/lister/migration/v1alpha1/storageversionmigration.go +++ b/pkg/clients/lister/migration/v1alpha1/storageversionmigration.go @@ -26,10 +26,13 @@ import ( ) // StorageVersionMigrationLister helps list StorageVersionMigrations. +// All objects returned here must be treated as read-only. type StorageVersionMigrationLister interface { // List lists all StorageVersionMigrations in the indexer. + // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*v1alpha1.StorageVersionMigration, err error) // Get retrieves the StorageVersionMigration from the index for a given name. + // Objects returned here must be treated as read-only. Get(name string) (*v1alpha1.StorageVersionMigration, error) StorageVersionMigrationListerExpansion } From a8e94f96556b79ce9cac0790d79cb4cc253d5e9f Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Wed, 21 Apr 2021 17:05:27 +0200 Subject: [PATCH 4/4] Move metadata.name description into yaml-patch to move around inability of kubebuilder to express that --- .gitignore | 1 + hack/update-codegen.sh | 12 ++++++++++ manifests/storage_state_crd.yaml | 31 ++++++++++++++------------ manifests/storage_state_crd.yaml-patch | 6 +++++ pkg/apis/migration/v1alpha1/types.go | 1 - 5 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 .gitignore create mode 100644 manifests/storage_state_crd.yaml-patch diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..be1c5a42e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +_output diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index e22c33548..dd57ae0a9 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -23,11 +23,23 @@ API_PKG="${THIS_REPO}/pkg/apis/migration/v1alpha1" # Absolute path to this repo THIS_REPO_ABSOLUTE="$(cd "$(dirname "${BASH_SOURCE}")/.." && pwd -P)" +mkdir -p _output go run -mod=vendor ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen \ schemapatch:manifests="${THIS_REPO_ABSOLUTE}/manifests" \ paths="${THIS_REPO_ABSOLUTE}/pkg/apis/migration/v1alpha1" \ output:dir="${THIS_REPO_ABSOLUTE}/manifests" +# download and run yaml-patch to add the metadata.name schema. Kubebuilder's controller-tools lacks +# experessivity for that. +curl -s -f -L https://github.com/krishicks/yaml-patch/releases/download/v0.0.10/yaml_patch_$(go env GOHOSTOS) -o _output/yaml-patch +chmod +x _output/yaml-patch +for m in "${THIS_REPO_ABSOLUTE}/manifests/"*.yaml; do + if [ -f "${m}-patch" ]; then + _output/yaml-patch -o "${m}-patch" < "${m}" > "_output/$(basename "${m}")" + mv _output/$(basename "${m}") "${THIS_REPO_ABSOLUTE}/manifests" + fi +done + go run -mod=vendor ./vendor/k8s.io/code-generator/cmd/client-gen \ --output-package "${THIS_REPO}/pkg/clients" \ --clientset-name="clientset" \ diff --git a/manifests/storage_state_crd.yaml b/manifests/storage_state_crd.yaml index a06e14455..b230721cb 100644 --- a/manifests/storage_state_crd.yaml +++ b/manifests/storage_state_crd.yaml @@ -1,9 +1,9 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: storagestates.migration.k8s.io annotations: - "api-approved.kubernetes.io": "https://github.com/kubernetes/enhancements/pull/747" + api-approved.kubernetes.io: https://github.com/kubernetes/enhancements/pull/747 + name: storagestates.migration.k8s.io spec: group: migration.k8s.io names: @@ -11,18 +11,13 @@ spec: listKind: StorageStateList plural: storagestates singular: storagestate - scope: Cluster preserveUnknownFields: false + scope: Cluster versions: - name: v1alpha1 - served: true - storage: true - subresources: - status: {} schema: openAPIV3Schema: description: The state of the storage of a specific resource. - type: object properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -35,15 +30,16 @@ spec: submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: - description: The name must be "<.spec.resource.resouce>.<.spec.resource.group>". + properties: + name: + description: name must be "<.spec.resource.resouce>.<.spec.resource.group>". + type: string type: object spec: description: Specification of the storage state. - type: object properties: resource: description: The resource this storageState is about. - type: object properties: group: description: The name of the group. @@ -51,9 +47,10 @@ spec: resource: description: The name of the resource. type: string + type: object + type: object status: description: Status of the storage state. - type: object properties: currentStorageVersionHash: description: The hash value of the current storage version, as shown @@ -64,8 +61,8 @@ spec: description: LastHeartbeatTime is the last time the storage migration triggering controller checks the storage version hash of this resource in the discovery document and updates this field. - type: string format: date-time + type: string persistedStorageVersionHashes: description: The hash values of storage versions that persisted instances of spec.resource might still be encoded in. "Unknown" is a valid @@ -76,6 +73,12 @@ spec: this field is refined to only contain the currentStorageVersionHash. Once the apiserver has changed the storage version, the new storage version is appended to the list. - type: array items: type: string + type: array + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/manifests/storage_state_crd.yaml-patch b/manifests/storage_state_crd.yaml-patch new file mode 100644 index 000000000..5fdce4790 --- /dev/null +++ b/manifests/storage_state_crd.yaml-patch @@ -0,0 +1,6 @@ +- op: add + path: /spec/versions/name=v1alpha1/schema/openAPIV3Schema/properties/metadata/properties + value: + name: + description: name must be "<.spec.resource.resouce>.<.spec.resource.group>". + type: string \ No newline at end of file diff --git a/pkg/apis/migration/v1alpha1/types.go b/pkg/apis/migration/v1alpha1/types.go index dde42a5b3..427350b1e 100644 --- a/pkg/apis/migration/v1alpha1/types.go +++ b/pkg/apis/migration/v1alpha1/types.go @@ -120,7 +120,6 @@ type StorageVersionMigrationList struct { // The state of the storage of a specific resource. type StorageState struct { metav1.TypeMeta `json:",inline"` - // The name must be "<.spec.resource.resouce>.<.spec.resource.group>". // +optional metav1.ObjectMeta `json:"metadata,omitempty"` // Specification of the storage state.