github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/types/types.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 types 21 22 import ( 23 "fmt" 24 25 appsv1 "k8s.io/api/apps/v1" 26 batchv1 "k8s.io/api/batch/v1" 27 corev1 "k8s.io/api/core/v1" 28 rbacv1 "k8s.io/api/rbac/v1" 29 "k8s.io/apimachinery/pkg/runtime/schema" 30 31 appsv1alpha1 "github.com/1aal/kubeblocks/apis/apps/v1alpha1" 32 workloads "github.com/1aal/kubeblocks/apis/workloads/v1alpha1" 33 ) 34 35 const ( 36 // CliDefaultHome defines kbcli default home name 37 CliDefaultHome = ".kbcli" 38 39 // CliClusterTypeConfigs defines kbcli cluster-type config file name 40 CliClusterTypeConfigs = "cluster_types" 41 42 // CliChartsCache defines kbcli charts cache dir name 43 CliChartsCache = "charts" 44 45 // CliHomeEnv defines kbcli home system env 46 CliHomeEnv = "KBCLI_HOME" 47 48 // DefaultLogFilePrefix is the default log file prefix 49 DefaultLogFilePrefix = "kbcli" 50 51 // DefaultNamespace is the namespace where kubeblocks is installed if 52 // no other namespace is specified 53 DefaultNamespace = "kb-system" 54 55 // GoosLinux is os.GOOS linux string 56 GoosLinux = "linux" 57 // GoosDarwin is os.GOOS darwin string 58 GoosDarwin = "darwin" 59 // GoosWindows is os.GOOS windows string 60 GoosWindows = "windows" 61 ) 62 63 // K8s core API group 64 const ( 65 K8sCoreAPIVersion = "v1" 66 ResourceDeployments = "deployments" 67 ResourceConfigmaps = "configmaps" 68 ResourceStatefulSets = "statefulsets" 69 ResourceDaemonSets = "daemonsets" 70 ResourceSecrets = "secrets" 71 ) 72 73 // K8s batch API group 74 const ( 75 K8SBatchAPIGroup = batchv1.GroupName 76 K8sBatchAPIVersion = "v1" 77 ResourceJobs = "jobs" 78 ResourceCronJobs = "cronjobs" 79 ) 80 81 // K8s webhook API group 82 const ( 83 WebhookAPIGroup = "admissionregistration.k8s.io" 84 K8sWebhookAPIVersion = "v1" 85 ResourceValidatingWebhookConfigurations = "validatingwebhookconfigurations" 86 ResourceMutatingWebhookConfigurations = "mutatingwebhookconfigurations" 87 ) 88 89 // Apps API group 90 const ( 91 AppsAPIGroup = "apps.kubeblocks.io" 92 AppsAPIVersion = "v1alpha1" 93 ResourcePods = "pods" 94 ResourceClusters = "clusters" 95 ResourceClusterDefs = "clusterdefinitions" 96 ResourceClusterVersions = "clusterversions" 97 ResourceOpsRequests = "opsrequests" 98 ResourceConfigConstraintVersions = "configconstraints" 99 ResourceComponentResourceConstraint = "componentresourceconstraints" 100 ResourceComponentClassDefinition = "componentclassdefinitions" 101 KindCluster = "Cluster" 102 KindComponentClassDefinition = "ComponentClassDefinition" 103 KindClusterDef = "ClusterDefinition" 104 KindClusterVersion = "ClusterVersion" 105 KindConfigConstraint = "ConfigConstraint" 106 KindBackup = "Backup" 107 KindRestore = "Restore" 108 KindBackupPolicy = "BackupPolicy" 109 KindOps = "OpsRequest" 110 KindBackupSchedule = "BackupSchedule" 111 KindBackupPolicyTemplate = "BackupPolicyTemplate" 112 KindStatefulSet = "StatefulSet" 113 KindDeployment = "Deployment" 114 KindRSM = "ReplicatedStateMachine" 115 KindConfigMap = "ConfigMap" 116 ) 117 118 // K8S rbac API group 119 const ( 120 RBACAPIGroup = rbacv1.GroupName 121 RBACAPIVersion = "v1" 122 ClusterRoles = "clusterroles" 123 ClusterRoleBindings = "clusterrolebindings" 124 Roles = "roles" 125 RoleBindings = "rolebindings" 126 ServiceAccounts = "serviceaccounts" 127 ) 128 129 // Annotations 130 const ( 131 ServiceHAVIPTypeAnnotationKey = "service.kubernetes.io/kubeblocks-havip-type" 132 ServiceHAVIPTypeAnnotationValue = "private-ip" 133 ServiceFloatingIPAnnotationKey = "service.kubernetes.io/kubeblocks-havip-floating-ip" 134 135 ClassProviderLabelKey = "class.kubeblocks.io/provider" 136 ReloadConfigMapAnnotationKey = "kubeblocks.io/reload-configmap" // mark an annotation to load configmap 137 ) 138 139 // DataProtection API group 140 const ( 141 DPAPIGroup = "dataprotection.kubeblocks.io" 142 DPAPIVersion = "v1alpha1" 143 ResourceBackups = "backups" 144 ResourceActionSets = "actionsets" 145 ResourceRestores = "restores" 146 ResourceBackupPolicies = "backuppolicies" 147 ResourceBackupRepos = "backuprepos" 148 ResourceBackupSchedules = "backupschedules" 149 ResourceBackupTemplates = "backuppolicytemplates" 150 ) 151 152 // Extensions API group 153 const ( 154 ExtensionsAPIGroup = "extensions.kubeblocks.io" 155 ExtensionsAPIVersion = "v1alpha1" 156 ResourceAddons = "addons" 157 ) 158 159 // Storage API group 160 const ( 161 StorageAPIGroup = "storage.kubeblocks.io" 162 StorageAPIVersion = "v1alpha1" 163 ResourceStorageProviders = "storageproviders" 164 ) 165 166 // Migration API group 167 const ( 168 MigrationAPIGroup = "datamigration.apecloud.io" 169 MigrationAPIVersion = "v1alpha1" 170 ResourceMigrationTasks = "migrationtasks" 171 ResourceMigrationTemplates = "migrationtemplates" 172 ) 173 174 // Crd Api group 175 const ( 176 CustomResourceDefinitionAPIGroup = "apiextensions.k8s.io" 177 CustomResourceDefinitionAPIVersion = "v1" 178 ResourceCustomResourceDefinition = "customresourcedefinitions" 179 ) 180 181 // Kubebench API group 182 const ( 183 KubebenchAPIGroup = "benchmark.apecloud.io" 184 KubebenchAPIVersion = "v1alpha1" 185 ResourcePgBench = "pgbenches" 186 ResourceSysBench = "sysbenches" 187 ResourceYcsb = "ycsbs" 188 ResourceTpcc = "tpccs" 189 ResourceTpch = "tpches" 190 ) 191 192 // Workload API group 193 const ( 194 ResourceRSM = "replicatedstatemachines" 195 ) 196 197 const ( 198 None = "<none>" 199 200 // AddonReleasePrefix is the prefix of addon release name 201 AddonReleasePrefix = "kb-addon" 202 ) 203 204 var ( 205 // KubeBlocksRepoName helm repo name for kubeblocks 206 KubeBlocksRepoName = "kubeblocks" 207 208 // KubeBlocksChartName helm chart name for kubeblocks 209 KubeBlocksChartName = "kubeblocks" 210 211 // KubeBlocksReleaseName helm release name for kubeblocks 212 KubeBlocksReleaseName = "kubeblocks" 213 214 // KubeBlocksChartURL the helm chart repo for installing kubeblocks 215 KubeBlocksChartURL = "https://apecloud.github.io/helm-charts" 216 217 // GitLabHelmChartRepo the helm chart repo in GitLab 218 GitLabHelmChartRepo = "https://jihulab.com/api/v4/projects/85949/packages/helm/stable" 219 220 // KubeBlocksHelmLabel name=kubeblocks,owner-helm, for helm secret 221 KubeBlocksHelmLabel = fmt.Sprintf("%s=%s,%s=%s", "name", KubeBlocksChartName, "owner", "helm") 222 223 // KubeBlocksManagerConfigMapName the kubeblocks manager configMap name 224 KubeBlocksManagerConfigMapName = fmt.Sprintf("%s-manager-config", KubeBlocksChartName) 225 ) 226 227 // Playground 228 var ( 229 // K3dClusterName is the k3d cluster name for playground 230 K3dClusterName = "kb-playground" 231 ) 232 233 type ConfigTemplateInfo struct { 234 Name string 235 TPL appsv1alpha1.ComponentConfigSpec 236 CMObj *corev1.ConfigMap 237 } 238 239 func PodGVR() schema.GroupVersionResource { 240 return schema.GroupVersionResource{Group: "", Version: K8sCoreAPIVersion, Resource: ResourcePods} 241 } 242 243 func ClusterGVR() schema.GroupVersionResource { 244 return schema.GroupVersionResource{Group: AppsAPIGroup, Version: AppsAPIVersion, Resource: ResourceClusters} 245 } 246 247 func ClusterDefGVR() schema.GroupVersionResource { 248 return schema.GroupVersionResource{Group: AppsAPIGroup, Version: AppsAPIVersion, Resource: ResourceClusterDefs} 249 } 250 251 func ClusterVersionGVR() schema.GroupVersionResource { 252 return schema.GroupVersionResource{Group: AppsAPIGroup, Version: AppsAPIVersion, Resource: ResourceClusterVersions} 253 } 254 255 func OpsGVR() schema.GroupVersionResource { 256 return schema.GroupVersionResource{Group: AppsAPIGroup, Version: AppsAPIVersion, Resource: ResourceOpsRequests} 257 } 258 259 func BackupGVR() schema.GroupVersionResource { 260 return schema.GroupVersionResource{Group: DPAPIGroup, Version: DPAPIVersion, Resource: ResourceBackups} 261 } 262 263 func BackupPolicyGVR() schema.GroupVersionResource { 264 return schema.GroupVersionResource{Group: DPAPIGroup, Version: DPAPIVersion, Resource: ResourceBackupPolicies} 265 } 266 267 func BackupPolicyTemplateGVR() schema.GroupVersionResource { 268 return schema.GroupVersionResource{Group: AppsAPIGroup, Version: DPAPIVersion, Resource: ResourceBackupTemplates} 269 } 270 271 func BackupScheduleGVR() schema.GroupVersionResource { 272 return schema.GroupVersionResource{Group: DPAPIGroup, Version: DPAPIVersion, Resource: ResourceBackupSchedules} 273 } 274 275 func ActionSetGVR() schema.GroupVersionResource { 276 return schema.GroupVersionResource{Group: DPAPIGroup, Version: DPAPIVersion, Resource: ResourceActionSets} 277 } 278 279 func BackupRepoGVR() schema.GroupVersionResource { 280 return schema.GroupVersionResource{Group: DPAPIGroup, Version: DPAPIVersion, Resource: ResourceBackupRepos} 281 } 282 283 func RestoreGVR() schema.GroupVersionResource { 284 return schema.GroupVersionResource{Group: DPAPIGroup, Version: DPAPIVersion, Resource: ResourceRestores} 285 } 286 287 func AddonGVR() schema.GroupVersionResource { 288 return schema.GroupVersionResource{Group: ExtensionsAPIGroup, Version: ExtensionsAPIVersion, Resource: ResourceAddons} 289 } 290 291 func StorageProviderGVR() schema.GroupVersionResource { 292 return schema.GroupVersionResource{Group: StorageAPIGroup, Version: StorageAPIVersion, Resource: ResourceStorageProviders} 293 } 294 295 func ComponentResourceConstraintGVR() schema.GroupVersionResource { 296 return schema.GroupVersionResource{Group: AppsAPIGroup, Version: AppsAPIVersion, Resource: ResourceComponentResourceConstraint} 297 } 298 299 func ComponentClassDefinitionGVR() schema.GroupVersionResource { 300 return schema.GroupVersionResource{Group: AppsAPIGroup, Version: AppsAPIVersion, Resource: ResourceComponentClassDefinition} 301 } 302 303 func CRDGVR() schema.GroupVersionResource { 304 return schema.GroupVersionResource{ 305 Group: "apiextensions.k8s.io", 306 Version: K8sCoreAPIVersion, 307 Resource: "customresourcedefinitions", 308 } 309 } 310 311 func ConfigmapGVR() schema.GroupVersionResource { 312 return schema.GroupVersionResource{Group: corev1.GroupName, Version: K8sCoreAPIVersion, Resource: ResourceConfigmaps} 313 } 314 315 func SecretGVR() schema.GroupVersionResource { 316 return schema.GroupVersionResource{Group: corev1.GroupName, Version: K8sCoreAPIVersion, Resource: ResourceSecrets} 317 } 318 319 func StatefulSetGVR() schema.GroupVersionResource { 320 return schema.GroupVersionResource{Group: appsv1.GroupName, Version: K8sCoreAPIVersion, Resource: ResourceStatefulSets} 321 } 322 323 func RSMGVR() schema.GroupVersionResource { 324 return schema.GroupVersionResource{Group: workloads.GroupVersion.Group, Version: workloads.GroupVersion.Version, Resource: ResourceRSM} 325 } 326 327 func DaemonSetGVR() schema.GroupVersionResource { 328 return schema.GroupVersionResource{Group: appsv1.GroupName, Version: K8sCoreAPIVersion, Resource: ResourceDaemonSets} 329 } 330 331 func DeployGVR() schema.GroupVersionResource { 332 return schema.GroupVersionResource{Group: appsv1.GroupName, Version: K8sCoreAPIVersion, Resource: ResourceDeployments} 333 } 334 335 func ServiceGVR() schema.GroupVersionResource { 336 return schema.GroupVersionResource{Group: corev1.GroupName, Version: K8sCoreAPIVersion, Resource: "services"} 337 } 338 339 func PVCGVR() schema.GroupVersionResource { 340 return schema.GroupVersionResource{Group: corev1.GroupName, Version: K8sCoreAPIVersion, Resource: "persistentvolumeclaims"} 341 } 342 343 func PVGVR() schema.GroupVersionResource { 344 return schema.GroupVersionResource{Group: corev1.GroupName, Version: K8sCoreAPIVersion, Resource: "persistentvolumes"} 345 } 346 347 func ConfigConstraintGVR() schema.GroupVersionResource { 348 return schema.GroupVersionResource{Group: AppsAPIGroup, Version: AppsAPIVersion, Resource: ResourceConfigConstraintVersions} 349 } 350 351 func StorageClassGVR() schema.GroupVersionResource { 352 return schema.GroupVersionResource{ 353 Group: "storage.k8s.io", 354 Version: K8sCoreAPIVersion, 355 Resource: "storageclasses", 356 } 357 } 358 359 func VolumeSnapshotClassGVR() schema.GroupVersionResource { 360 return schema.GroupVersionResource{ 361 Group: "snapshot.storage.k8s.io", 362 Version: K8sCoreAPIVersion, 363 Resource: "volumesnapshotclasses", 364 } 365 } 366 367 func ValidatingWebhookConfigurationGVR() schema.GroupVersionResource { 368 return schema.GroupVersionResource{ 369 Group: WebhookAPIGroup, 370 Version: K8sWebhookAPIVersion, 371 Resource: ResourceValidatingWebhookConfigurations, 372 } 373 } 374 375 func MutatingWebhookConfigurationGVR() schema.GroupVersionResource { 376 return schema.GroupVersionResource{ 377 Group: WebhookAPIGroup, 378 Version: K8sWebhookAPIVersion, 379 Resource: ResourceMutatingWebhookConfigurations, 380 } 381 } 382 383 func ClusterRoleGVR() schema.GroupVersionResource { 384 return schema.GroupVersionResource{Group: RBACAPIGroup, Version: RBACAPIVersion, Resource: ClusterRoles} 385 } 386 func ClusterRoleBindingGVR() schema.GroupVersionResource { 387 return schema.GroupVersionResource{Group: RBACAPIGroup, Version: RBACAPIVersion, Resource: ClusterRoleBindings} 388 } 389 390 func RoleGVR() schema.GroupVersionResource { 391 return schema.GroupVersionResource{Group: RBACAPIGroup, Version: RBACAPIVersion, Resource: Roles} 392 } 393 394 func RoleBindingGVR() schema.GroupVersionResource { 395 return schema.GroupVersionResource{Group: RBACAPIGroup, Version: RBACAPIVersion, Resource: RoleBindings} 396 } 397 398 func ServiceAccountGVR() schema.GroupVersionResource { 399 return schema.GroupVersionResource{Group: corev1.GroupName, Version: K8sCoreAPIVersion, Resource: ServiceAccounts} 400 } 401 402 func MigrationTaskGVR() schema.GroupVersionResource { 403 return schema.GroupVersionResource{ 404 Group: MigrationAPIGroup, 405 Version: MigrationAPIVersion, 406 Resource: ResourceMigrationTasks, 407 } 408 } 409 410 func MigrationTemplateGVR() schema.GroupVersionResource { 411 return schema.GroupVersionResource{ 412 Group: MigrationAPIGroup, 413 Version: MigrationAPIVersion, 414 Resource: ResourceMigrationTemplates, 415 } 416 } 417 418 func CustomResourceDefinitionGVR() schema.GroupVersionResource { 419 return schema.GroupVersionResource{ 420 Group: CustomResourceDefinitionAPIGroup, 421 Version: CustomResourceDefinitionAPIVersion, 422 Resource: ResourceCustomResourceDefinition, 423 } 424 } 425 426 func JobGVR() schema.GroupVersionResource { 427 return schema.GroupVersionResource{Group: K8SBatchAPIGroup, Version: K8sBatchAPIVersion, Resource: ResourceJobs} 428 } 429 func CronJobGVR() schema.GroupVersionResource { 430 return schema.GroupVersionResource{Group: K8SBatchAPIGroup, Version: K8sBatchAPIVersion, Resource: ResourceCronJobs} 431 } 432 433 func PgBenchGVR() schema.GroupVersionResource { 434 return schema.GroupVersionResource{Group: KubebenchAPIGroup, Version: KubebenchAPIVersion, Resource: ResourcePgBench} 435 } 436 437 func SysbenchGVR() schema.GroupVersionResource { 438 return schema.GroupVersionResource{Group: KubebenchAPIGroup, Version: KubebenchAPIVersion, Resource: ResourceSysBench} 439 } 440 441 func YcsbGVR() schema.GroupVersionResource { 442 return schema.GroupVersionResource{Group: KubebenchAPIGroup, Version: KubebenchAPIVersion, Resource: ResourceYcsb} 443 } 444 445 func TpccGVR() schema.GroupVersionResource { 446 return schema.GroupVersionResource{Group: KubebenchAPIGroup, Version: KubebenchAPIVersion, Resource: ResourceTpcc} 447 } 448 449 func TpchGVR() schema.GroupVersionResource { 450 return schema.GroupVersionResource{Group: KubebenchAPIGroup, Version: KubebenchAPIVersion, Resource: ResourceTpch} 451 }