From 1edfd318cf68c46c6654e41633c805c681312b34 Mon Sep 17 00:00:00 2001 From: d976045024 <976045024@qq.com> Date: Tue, 7 May 2024 15:21:12 +0800 Subject: [PATCH 1/4] fix: check if the specified backup method exists when creating a backup (#326) --- pkg/cmd/cluster/dataprotection.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/cmd/cluster/dataprotection.go b/pkg/cmd/cluster/dataprotection.go index 667f4f974..1121e4d1a 100644 --- a/pkg/cmd/cluster/dataprotection.go +++ b/pkg/cmd/cluster/dataprotection.go @@ -191,6 +191,19 @@ func (o *CreateBackupOptions) Validate() error { if o.BackupSpec.BackupMethod == "" { return fmt.Errorf("backup method can not be empty, you can specify it by --method") } + + // check if the backup method exists in backup policy + supportMethods, exist := backupPolicy.Spec.BackupMethods, false + for _, method := range supportMethods { + if o.BackupSpec.BackupMethod == method.Name { + exist = true + break + } + } + if !exist { + return fmt.Errorf("specified backup method does not exist") + } + // TODO: check if pvc exists // valid retention period From 3d5602ef104fe70e04a41267492fb57411b99167 Mon Sep 17 00:00:00 2001 From: d976045024 <976045024@qq.com> Date: Tue, 7 May 2024 15:45:28 +0800 Subject: [PATCH 2/4] fix: check if the specified backup method exists when creating a backup (#326) --- pkg/cmd/cluster/dataprotection.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/cluster/dataprotection.go b/pkg/cmd/cluster/dataprotection.go index 1121e4d1a..335200b7d 100644 --- a/pkg/cmd/cluster/dataprotection.go +++ b/pkg/cmd/cluster/dataprotection.go @@ -193,8 +193,8 @@ func (o *CreateBackupOptions) Validate() error { } // check if the backup method exists in backup policy - supportMethods, exist := backupPolicy.Spec.BackupMethods, false - for _, method := range supportMethods { + exist := false + for _, method := range backupPolicy.Spec.BackupMethods { if o.BackupSpec.BackupMethod == method.Name { exist = true break From 6172d1ac822799d59072e5acb55c6f37d9f9ed12 Mon Sep 17 00:00:00 2001 From: d976045024 <976045024@qq.com> Date: Tue, 7 May 2024 20:48:32 +0800 Subject: [PATCH 3/4] fix: modify msg format (#326) --- pkg/cmd/cluster/dataprotection.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/cluster/dataprotection.go b/pkg/cmd/cluster/dataprotection.go index 335200b7d..fe6618574 100644 --- a/pkg/cmd/cluster/dataprotection.go +++ b/pkg/cmd/cluster/dataprotection.go @@ -193,15 +193,17 @@ func (o *CreateBackupOptions) Validate() error { } // check if the backup method exists in backup policy - exist := false + exist, methods := false, make([]string, 0) for _, method := range backupPolicy.Spec.BackupMethods { + methods = append(methods, method.Name) if o.BackupSpec.BackupMethod == method.Name { exist = true break } } if !exist { - return fmt.Errorf("specified backup method does not exist") + return fmt.Errorf("specified backup method %s does not exist in backup policy %s, available methods: [%s]\n", + o.BackupSpec.BackupMethod, backupPolicy.Name, strings.Join(methods, ", ")) } // TODO: check if pvc exists From b3c6e134efde0eb023c24277b1580ab3b4688117 Mon Sep 17 00:00:00 2001 From: d976045024 <976045024@qq.com> Date: Tue, 7 May 2024 20:59:29 +0800 Subject: [PATCH 4/4] fix: modify msg format (#326) --- pkg/cmd/cluster/dataprotection.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/cluster/dataprotection.go b/pkg/cmd/cluster/dataprotection.go index fe6618574..8e8a54073 100644 --- a/pkg/cmd/cluster/dataprotection.go +++ b/pkg/cmd/cluster/dataprotection.go @@ -193,9 +193,9 @@ func (o *CreateBackupOptions) Validate() error { } // check if the backup method exists in backup policy - exist, methods := false, make([]string, 0) + exist, availableMethods := false, make([]string, 0) for _, method := range backupPolicy.Spec.BackupMethods { - methods = append(methods, method.Name) + availableMethods = append(availableMethods, method.Name) if o.BackupSpec.BackupMethod == method.Name { exist = true break @@ -203,7 +203,7 @@ func (o *CreateBackupOptions) Validate() error { } if !exist { return fmt.Errorf("specified backup method %s does not exist in backup policy %s, available methods: [%s]\n", - o.BackupSpec.BackupMethod, backupPolicy.Name, strings.Join(methods, ", ")) + o.BackupSpec.BackupMethod, backupPolicy.Name, strings.Join(availableMethods, ", ")) } // TODO: check if pvc exists