From d1bc0901b60689c511f423b81a4fb8dd0173e71e Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 28 Oct 2024 21:36:25 +0800 Subject: [PATCH] feat(backup): update k8s/crds.yaml ref: longhorn/longhorn 5411 Signed-off-by: James Lu --- k8s/crds.yaml | 26 +++++++++++++++++--------- webhook/resources/backup/mutator.go | 9 ++++----- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/k8s/crds.yaml b/k8s/crds.yaml index b6cc71217c..f6168f1ae3 100644 --- a/k8s/crds.yaml +++ b/k8s/crds.yaml @@ -564,8 +564,9 @@ spec: ownerID: type: string realSize: - description: Real size of image in bytes, which may be smaller than the size - when the file is a sparse file. Will be zero until known (e.g. while a backing image is uploading) + description: Real size of image in bytes, which may be smaller than + the size when the file is a sparse file. Will be zero until known + (e.g. while a backing image is uploading) format: int64 type: integer size: @@ -574,8 +575,9 @@ spec: uuid: type: string virtualSize: - description: Virtual size of image in bytes, which may be larger than physical - size. Will be zero until known (e.g. while a backing image is uploading) + description: Virtual size of image in bytes, which may be larger than + physical size. Will be zero until known (e.g. while a backing image + is uploading) format: int64 type: integer type: object @@ -653,8 +655,9 @@ spec: backing image backup properties: backingImage: - description: The backing image name.. - nullable: true + description: |- + The backing image name. + Required type: string backupTargetName: description: The backup target name. @@ -677,6 +680,7 @@ spec: Required type: boolean required: + - backingImage - userCreated type: object status: @@ -732,7 +736,8 @@ spec: description: Record the secret if this backup backing image is encrypted type: string secretNamespace: - description: Record the secret namespace if this backup backing image is encrypted + description: Record the secret namespace if this backup backing image + is encrypted type: string size: description: The backing image size. @@ -878,6 +883,7 @@ spec: - full - incremental - "" + type: string backupTargetName: description: The backup target name. nullable: true @@ -1120,7 +1126,8 @@ spec: the backup target. type: string readOnly: - description: ReadOnly indicates if it can create a backup on the remote backup target or not. + description: ReadOnly indicates if it can create a backup on the remote + backup target or not. type: boolean syncRequestedAt: description: The time to request run sync the remote backup target. @@ -4214,7 +4221,8 @@ spec: - gzip type: string backupTargetName: - description: 'The backup target name that the volume will be backed up to or is synced.' + description: The backup target name that the volume will be backed + up to or is synced. type: string dataEngine: enum: diff --git a/webhook/resources/backup/mutator.go b/webhook/resources/backup/mutator.go index d0ed6b085d..842cd823d0 100644 --- a/webhook/resources/backup/mutator.go +++ b/webhook/resources/backup/mutator.go @@ -86,12 +86,11 @@ func (b *backupMutator) Create(request *admission.Request, newObj runtime.Object } if backup.Spec.BackupTargetName == "" { - backupTargetName := types.DefaultBackupTargetName - if volume, err := b.ds.GetVolumeRO(volumeName); err == nil { - backupTargetName = volume.Spec.BackupTargetName + volume, err := b.ds.GetVolumeRO(volumeName) + if err != nil { + return nil, werror.NewInvalidError(errors.Wrapf(err, "failed to get volume %v", volumeName).Error(), "") } - backup.Spec.BackupTargetName = backupTargetName - patchOps = append(patchOps, fmt.Sprintf(`{"op": "replace", "path": "/spec/backupTargetName", "value": "%s"}`, backupTargetName)) + patchOps = append(patchOps, fmt.Sprintf(`{"op": "replace", "path": "/spec/backupTargetName", "value": "%s"}`, volume.Spec.BackupTargetName)) } labels := backup.Labels