diff --git a/internal/types/etcd_storage.go b/internal/types/etcd_storage.go index 92ac651..aa12737 100644 --- a/internal/types/etcd_storage.go +++ b/internal/types/etcd_storage.go @@ -1,5 +1,11 @@ package types +import ( + "fmt" + + "github.com/spf13/viper" +) + type ETCDStorageType int const ( @@ -7,10 +13,6 @@ const ( KineMySQL ) -const ( - defaultETCDStorageType = ETCD -) - var etcdStorageTypeString = map[string]ETCDStorageType{"etcd": ETCD, "kine-mysql": KineMySQL} func (s ETCDStorageType) String() string { @@ -23,6 +25,17 @@ func ParseETCDStorageType(s string) ETCDStorageType { return storageType } - // TODO: we have to decide what to do in this situation - return defaultETCDStorageType + panic(fmt.Errorf("unsupported storage type %s", s)) +} + +// ParseETCDEndpoint returns the default ETCD endpoints used to interact with the Tenant Control Plane backing storage. +func ParseETCDEndpoint(conf *viper.Viper) string { + switch ParseETCDStorageType(conf.GetString("etcd-storage-type")) { + case ETCD: + return conf.GetString("etcd-endpoints") + case KineMySQL: + return "127.0.0.1:2379" + default: + panic("unsupported storage type") + } } diff --git a/main.go b/main.go index 107cb9b..2ef07f0 100644 --- a/main.go +++ b/main.go @@ -82,7 +82,7 @@ func main() { ETCDCASecretNamespace: conf.GetString("etcd-ca-secret-namespace"), ETCDClientSecretName: conf.GetString("etcd-client-secret-name"), ETCDClientSecretNamespace: conf.GetString("etcd-client-secret-namespace"), - ETCDEndpoints: conf.GetString("etcd-endpoints"), + ETCDEndpoints: types.ParseETCDEndpoint(conf), ETCDCompactionInterval: conf.GetString("etcd-compaction-interval"), TmpBaseDirectory: conf.GetString("tmp-directory"), KineMySQLSecretName: conf.GetString("kine-mysql-secret-name"),