github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cluster/builtin_charts.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 cluster 21 22 import ( 23 "embed" 24 "fmt" 25 "io" 26 ) 27 28 // embedConfig is the interface for the go embed chart 29 type embedConfig struct { 30 chartFS embed.FS 31 // chart file name, include the extension 32 name string 33 // chart alias, this alias will be used as the command alias 34 alias string 35 } 36 37 var _ chartLoader = &embedConfig{} 38 39 func (e *embedConfig) register(subcmd ClusterType) error { 40 if _, ok := ClusterTypeCharts[subcmd]; ok { 41 return fmt.Errorf("cluster type %s already registered", subcmd) 42 } 43 ClusterTypeCharts[subcmd] = e 44 return nil 45 } 46 47 func (e *embedConfig) getAlias() string { 48 return e.alias 49 } 50 51 func (e *embedConfig) loadChart() (io.ReadCloser, error) { 52 return e.chartFS.Open(fmt.Sprintf("charts/%s", e.name)) 53 } 54 55 func (e *embedConfig) getChartFileName() string { 56 return e.name 57 } 58 59 var ( 60 // run `make generate` to generate this embed file 61 //go:embed charts/apecloud-mysql-cluster.tgz 62 mysqlChart embed.FS 63 //go:embed charts/postgresql-cluster.tgz 64 postgresqlChart embed.FS 65 //go:embed charts/kafka-cluster.tgz 66 kafkaChart embed.FS 67 //go:embed charts/redis-cluster.tgz 68 redisChart embed.FS 69 //go:embed charts/mongodb-cluster.tgz 70 mongodbChart embed.FS 71 //go:embed charts/llm-cluster.tgz 72 llmChart embed.FS 73 ) 74 75 func IsbuiltinCharts(chart string) bool { 76 return chart == "mysql" || chart == "postgresql" || chart == "kafka" || chart == "redis" || chart == "mongodb" || chart == "llm" 77 } 78 79 // internal_chart registers embed chart 80 81 func init() { 82 83 mysql := &embedConfig{ 84 chartFS: mysqlChart, 85 name: "apecloud-mysql-cluster.tgz", 86 alias: "", 87 } 88 if err := mysql.register("mysql"); err != nil { 89 fmt.Println(err.Error()) 90 } 91 92 postgresql := &embedConfig{ 93 chartFS: postgresqlChart, 94 name: "postgresql-cluster.tgz", 95 alias: "", 96 } 97 if err := postgresql.register("postgresql"); err != nil { 98 fmt.Println(err.Error()) 99 } 100 101 kafka := &embedConfig{ 102 chartFS: kafkaChart, 103 name: "kafka-cluster.tgz", 104 alias: "", 105 } 106 if err := kafka.register("kafka"); err != nil { 107 fmt.Println(err.Error()) 108 } 109 110 redis := &embedConfig{ 111 chartFS: redisChart, 112 name: "redis-cluster.tgz", 113 alias: "", 114 } 115 if err := redis.register("redis"); err != nil { 116 fmt.Println(err.Error()) 117 } 118 119 mongodb := &embedConfig{ 120 chartFS: mongodbChart, 121 name: "mongodb-cluster.tgz", 122 alias: "", 123 } 124 if err := mongodb.register("mongodb"); err != nil { 125 fmt.Println(err.Error()) 126 } 127 128 llm := &embedConfig{ 129 chartFS: llmChart, 130 name: "llm-cluster.tgz", 131 alias: "", 132 } 133 if err := llm.register("llm"); err != nil { 134 fmt.Println(err.Error()) 135 } 136 137 }