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 14e99003e..dd57ae0a9 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -23,24 +23,36 @@ 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 \ +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" -go run ./vendor/k8s.io/code-generator/cmd/client-gen \ +# 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" \ --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 +60,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" 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..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,18 +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: - type: object properties: name: - description: The name must be "<.spec.resource.resouce>.<.spec.resource.group>". + 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. @@ -54,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 @@ -67,18 +61,24 @@ 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 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. - type: array + 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. 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. 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 }