From a8e94f96556b79ce9cac0790d79cb4cc253d5e9f Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Wed, 21 Apr 2021 17:05:27 +0200 Subject: [PATCH] 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.