github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/testutil/dataprotection/backuprepo_factory.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package dataprotection 21 22 import ( 23 corev1 "k8s.io/api/core/v1" 24 "k8s.io/apimachinery/pkg/api/resource" 25 26 dpv1alpha1 "github.com/1aal/kubeblocks/apis/dataprotection/v1alpha1" 27 dptypes "github.com/1aal/kubeblocks/pkg/dataprotection/types" 28 testapps "github.com/1aal/kubeblocks/pkg/testutil/apps" 29 ) 30 31 type MockBackupRepoFactory struct { 32 testapps.BaseFactory[dpv1alpha1.BackupRepo, *dpv1alpha1.BackupRepo, MockBackupRepoFactory] 33 } 34 35 func NewBackupRepoFactory(namespace, name string) *MockBackupRepoFactory { 36 f := &MockBackupRepoFactory{} 37 f.Init(namespace, name, 38 &dpv1alpha1.BackupRepo{ 39 Spec: dpv1alpha1.BackupRepoSpec{ 40 VolumeCapacity: resource.MustParse("100Gi"), 41 PVReclaimPolicy: "Retain", 42 }, 43 }, f) 44 return f 45 } 46 47 func (factory *MockBackupRepoFactory) SetStorageProviderRef(providerName string) *MockBackupRepoFactory { 48 factory.Get().Spec.StorageProviderRef = providerName 49 return factory 50 } 51 52 func (factory *MockBackupRepoFactory) SetVolumeCapacity(amount string) *MockBackupRepoFactory { 53 factory.Get().Spec.VolumeCapacity = resource.MustParse(amount) 54 return factory 55 } 56 57 func (factory *MockBackupRepoFactory) SetPVReclaimPolicy(policy string) *MockBackupRepoFactory { 58 factory.Get().Spec.PVReclaimPolicy = corev1.PersistentVolumeReclaimPolicy(policy) 59 return factory 60 } 61 62 func (factory *MockBackupRepoFactory) SetConfig(config map[string]string) *MockBackupRepoFactory { 63 factory.Get().Spec.Config = config 64 return factory 65 } 66 67 func (factory *MockBackupRepoFactory) SetCredential(ref *corev1.SecretReference) *MockBackupRepoFactory { 68 factory.Get().Spec.Credential = ref 69 return factory 70 } 71 72 func (factory *MockBackupRepoFactory) SetAsDefaultRepo(v bool) *MockBackupRepoFactory { 73 if v { 74 obj := factory.Get() 75 if obj.Annotations == nil { 76 obj.Annotations = map[string]string{} 77 } 78 obj.Annotations[dptypes.DefaultBackupRepoAnnotationKey] = "true" 79 } else { 80 delete(factory.Get().Annotations, dptypes.DefaultBackupRepoAnnotationKey) 81 } 82 return factory 83 }