Skip to content

Commit 2363f2d

Browse files
committed
fix(backups): carry dropdown option sources in CRD annotations, not schema
The four backups.cozystack.io CRDs injected the x-cozystack-options vendor extension into their OpenAPI validation schema. apiextensions JSONSchemaProps is a closed struct that only preserves x-kubernetes-* vendor extensions, so helm-controller's server-side apply rejected the unknown key ("field not declared in schema") and the CRDs never applied — the controller crash-looped and backups were non-functional. Move the field-to-source mapping the dashboard needs into CRD metadata.annotations (preserved by the apiserver), emitted via +kubebuilder:metadata:annotations markers, and drop the post-processing awk injector. The dashboard reattaches the extension client-side. A helm-unittest suite pins the contract: each dropdown field carries its source in metadata.annotations and must not carry x-cozystack-options in the schema, guarding against re-introducing the injector. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent adb9989 commit 2363f2d

12 files changed

Lines changed: 97 additions & 82 deletions

‎api/backups/v1alpha1/backup_types.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type BackupStatus struct {
112112
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.apiGroup`
113113
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.kind`
114114
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.name`
115+
// +kubebuilder:metadata:annotations={"options.cozystack.io/source.applicationRef.kind=appkind"}
115116

116117
// Backup represents a single backup artifact for a given application.
117118
type Backup struct {

‎api/backups/v1alpha1/backupjob_types.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type BackupJobStatus struct {
100100
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.apiGroup`
101101
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.kind`
102102
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.name`
103+
// +kubebuilder:metadata:annotations={"options.cozystack.io/source.applicationRef.kind=appkind","options.cozystack.io/source.planRef.name=plan","options.cozystack.io/source.backupClassName=backupclass"}
103104

104105
// BackupJob represents a single execution of a backup.
105106
// It is typically created by a Plan controller when a schedule fires.

‎api/backups/v1alpha1/plan_types.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.apiGroup`
4141
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.kind`
4242
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.name`
43+
// +kubebuilder:metadata:annotations={"options.cozystack.io/source.applicationRef.kind=appkind","options.cozystack.io/source.backupClassName=backupclass"}
4344

4445
// Plan describes the schedule, method and storage location for the
4546
// backup of a given target application.

‎api/backups/v1alpha1/restorejob_types.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type RestoreJobStatus struct {
7979
// +kubebuilder:object:root=true
8080
// +kubebuilder:subresource:status
8181
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",priority=0
82+
// +kubebuilder:metadata:annotations={"options.cozystack.io/source.backupRef.name=backup","options.cozystack.io/source.targetApplicationRef.kind=appkind"}
8283

8384
// RestoreJob represents a single execution of a restore from a Backup.
8485
type RestoreJob struct {

‎hack/inject-cozystack-options.awk‎

Lines changed: 0 additions & 51 deletions
This file was deleted.

‎hack/update-codegen.sh‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,6 @@ mv ${TMPDIR}/cozystack.io_applicationdefinitions.yaml \
102102
mv ${TMPDIR}/backups.cozystack.io*.yaml ${BACKUPS_CORE_CRDDIR}/
103103
mv ${TMPDIR}/strategy.backups.cozystack.io*.yaml ${BACKUPSTRATEGY_CRDDIR}/
104104

105-
# controller-gen cannot emit the x-cozystack-options vendor extension that the
106-
# dashboard reads to render dropdowns from live cluster state. Re-apply it to
107-
# the backup CRDs. Targets are per-CRD (the same field is a dropdown in one
108-
# kind but free-text in another); keep them in sync with the Option providers
109-
# in pkg/registry/core/option/providers.go.
110-
inject_cozystack_options() {
111-
local file="${BACKUPS_CORE_CRDDIR}/$1"
112-
awk -v TARGETS="$2" -f "${SCRIPT_ROOT}/hack/inject-cozystack-options.awk" "${file}" > "${file}.tmp"
113-
mv "${file}.tmp" "${file}"
114-
}
115-
inject_cozystack_options backups.cozystack.io_backupjobs.yaml "applicationRef:kind:appkind planRef:name:plan spec:backupClassName:backupclass"
116-
inject_cozystack_options backups.cozystack.io_backups.yaml "applicationRef:kind:appkind"
117-
inject_cozystack_options backups.cozystack.io_plans.yaml "applicationRef:kind:appkind spec:backupClassName:backupclass"
118-
inject_cozystack_options backups.cozystack.io_restorejobs.yaml "backupRef:name:backup targetApplicationRef:kind:appkind"
119-
120105
mv ${TMPDIR}/*.yaml ${COZY_CONTROLLER_CRDDIR}/
121106

122107
# Tidy dependencies for standalone api/apps/v1alpha1 submodule

‎packages/system/backup-controller/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ NAMESPACE=cozy-backup-controller
44
include ../../../hack/common-envs.mk
55
include ../../../hack/package.mk
66

7+
test:
8+
helm unittest .
9+
710
image: image-backup-controller
811

912
image-backup-controller:

‎packages/system/backup-controller/definitions/backups.cozystack.io_backupjobs.yaml‎

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/system/backup-controller/definitions/backups.cozystack.io_backups.yaml‎

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/system/backup-controller/definitions/backups.cozystack.io_plans.yaml‎

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)