Skip to content

Commit

Permalink
Move metadata.name description into yaml-patch to move around inabili…
Browse files Browse the repository at this point in the history
…ty of kubebuilder to express that
  • Loading branch information
sttts committed Apr 21, 2021
1 parent 7d4e109 commit a8e94f9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_output
12 changes: 12 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
31 changes: 17 additions & 14 deletions manifests/storage_state_crd.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
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:
kind: StorageState
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
Expand All @@ -35,25 +30,27 @@ 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.
type: string
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
Expand All @@ -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
Expand All @@ -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: {}
6 changes: 6 additions & 0 deletions manifests/storage_state_crd.yaml-patch
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion pkg/apis/migration/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a8e94f9

Please sign in to comment.