github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/types/migrationapi/type.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 v1alpha1 21 22 import ( 23 "strings" 24 25 appv1 "k8s.io/api/apps/v1" 26 batchv1 "k8s.io/api/batch/v1" 27 v1 "k8s.io/api/core/v1" 28 "k8s.io/apimachinery/pkg/runtime" 29 ) 30 31 // DBTypeEnum defines the MigrationTemplate CR .spec.Source.DbType or .spec.Sink.DbType 32 // +enum 33 // +kubebuilder:validation:Enum={MySQL, PostgreSQL} 34 type DBTypeEnum string 35 36 const ( 37 MigrationDBTypeMySQL DBTypeEnum = "MySQL" // default value 38 MigrationDBTypePostgreSQL DBTypeEnum = "PostgreSQL" 39 ) 40 41 func (d DBTypeEnum) String() string { 42 return string(d) 43 } 44 45 // TaskTypeEnum defines the MigrationTask CR .spec.taskType 46 // +enum 47 // +kubebuilder:validation:Enum={initialization,cdc,initialization-and-cdc,initialization-and-twoway-cdc} 48 type TaskTypeEnum string 49 50 const ( 51 Initialization TaskTypeEnum = "initialization" 52 CDC TaskTypeEnum = "cdc" 53 InitializationAndCdc TaskTypeEnum = "initialization-and-cdc" // default value 54 ) 55 56 // EndpointTypeEnum defines the MigrationTask CR .spec.source.endpointType and .spec.sink.endpointType 57 // +enum 58 // +kubebuilder:validation:Enum={address} 59 type EndpointTypeEnum string 60 61 const ( 62 AddressDirectConnect EndpointTypeEnum = "address" // default value 63 ) 64 65 // non-use yet 66 67 type ConflictPolicyEnum string 68 69 const ( 70 Ignore ConflictPolicyEnum = "ignore" // default in FullLoad 71 Override ConflictPolicyEnum = "override" // default in CDC 72 ) 73 74 // DMLOpEnum defines the MigrationTask CR .spec.migrationObj 75 // +enum 76 // +kubebuilder:validation:Enum={all,none,insert,update,delete} 77 type DMLOpEnum string 78 79 const ( 80 AllDML DMLOpEnum = "all" 81 NoneDML DMLOpEnum = "none" 82 Insert DMLOpEnum = "insert" 83 Update DMLOpEnum = "update" 84 Delete DMLOpEnum = "delete" 85 ) 86 87 // DDLOpEnum defines the MigrationTask CR .spec.migrationObj 88 // +enum 89 // +kubebuilder:validation:Enum={all,none} 90 type DDLOpEnum string 91 92 const ( 93 AllDDL DDLOpEnum = "all" 94 NoneDDL DDLOpEnum = "none" 95 ) 96 97 // DCLOpEnum defines the MigrationTask CR .spec.migrationObj 98 // +enum 99 // +kubebuilder:validation:Enum={all,none} 100 type DCLOpEnum string 101 102 const ( 103 AllDCL DDLOpEnum = "all" 104 NoneDCL DDLOpEnum = "none" 105 ) 106 107 // TaskStatus defines the MigrationTask CR .status.taskStatus 108 // +enum 109 // +kubebuilder:validation:Enum={Prepare,InitPrepared,Init,InitFinished,Running,Cached,Pause,Done} 110 type TaskStatus string 111 112 const ( 113 PrepareStatus TaskStatus = "Prepare" 114 InitPrepared TaskStatus = "InitPrepared" 115 InitStatus TaskStatus = "Init" 116 InitFinished TaskStatus = "InitFinished" 117 RunningStatus TaskStatus = "Running" 118 CachedStatus TaskStatus = "Cached" 119 PauseStatus TaskStatus = "Pause" 120 DoneStatus TaskStatus = "Done" 121 ) 122 123 // StepEnum defines the MigrationTask CR .spec.steps 124 // +enum 125 // +kubebuilder:validation:Enum={preCheck,initStruct,initData,initStructLater} 126 type StepEnum string 127 128 const ( 129 StepPreCheck StepEnum = "preCheck" 130 StepStructPreFullLoad StepEnum = "initStruct" 131 StepFullLoad StepEnum = "initData" 132 StepStructAfterFullLoad StepEnum = "initStructLater" 133 StepInitialization StepEnum = "initialization" 134 StepPreDelete StepEnum = "preDelete" 135 StepCdc StepEnum = "cdc" 136 ) 137 138 func (s StepEnum) String() string { 139 return string(s) 140 } 141 142 func (s StepEnum) LowerCaseString() string { 143 return strings.ToLower(s.String()) 144 } 145 146 func (s StepEnum) CliString() string { 147 switch s { 148 case StepPreCheck: 149 return CliStepPreCheck.String() 150 case StepStructPreFullLoad: 151 return CliStepInitStruct.String() 152 case StepFullLoad: 153 return CliStepInitData.String() 154 case StepCdc: 155 return CliStepCdc.String() 156 default: 157 return "unknown" 158 } 159 } 160 161 type CliStepEnum string 162 163 const ( 164 CliStepGlobal CliStepEnum = "global" 165 CliStepPreCheck CliStepEnum = "precheck" 166 CliStepInitStruct CliStepEnum = "init-struct" 167 CliStepInitData CliStepEnum = "init-data" 168 CliStepCdc CliStepEnum = "cdc" 169 ) 170 171 func (s CliStepEnum) String() string { 172 return string(s) 173 } 174 175 // Phase defines the MigrationTemplate CR .status.phase 176 // +enum 177 // +kubebuilder:validation:Enum={Available,Unavailable} 178 type Phase string 179 180 const ( 181 AvailablePhase Phase = "Available" 182 UnavailablePhase Phase = "Unavailable" 183 ) 184 185 type MigrationObjects struct { 186 Task *MigrationTask 187 Template *MigrationTemplate 188 189 Jobs *batchv1.JobList 190 Pods *v1.PodList 191 StatefulSets *appv1.StatefulSetList 192 } 193 194 // +k8s:deepcopy-gen=false 195 196 type IntOrStringMap map[string]interface{} 197 198 func (in *IntOrStringMap) DeepCopyInto(out *IntOrStringMap) { 199 if in == nil { 200 *out = nil 201 } else { 202 *out = runtime.DeepCopyJSON(*in) 203 } 204 } 205 206 func (in *IntOrStringMap) DeepCopy() *IntOrStringMap { 207 if in == nil { 208 return nil 209 } 210 out := new(IntOrStringMap) 211 in.DeepCopyInto(out) 212 return out 213 }