59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
_ "embed"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
//go:embed "config.yaml"
|
|
var configData []byte
|
|
|
|
type Config struct {
|
|
Reg Registry `json:"reg" yaml:"reg"`
|
|
Kube map[string]Kube `json:"kube" yaml:"kube"`
|
|
}
|
|
|
|
// Registry 镜像仓库信息
|
|
type Registry struct {
|
|
Registry string `json:"registry" yaml:"registry"`
|
|
Username string `json:"username" yaml:"username"`
|
|
Password string `json:"password" yaml:"password"`
|
|
}
|
|
|
|
// Kube kube信息
|
|
type Kube struct {
|
|
Onl KubeConfig `json:"onl" yaml:"onl"`
|
|
Test KubeConfig `json:"test" yaml:"test"`
|
|
}
|
|
|
|
type KubeConfig struct {
|
|
KubeApiServer string `json:"kube_api_server" yaml:"kube_api_server"`
|
|
KubeCertificate string `json:"kube_certificate" yaml:"kube_certificate"`
|
|
KubeToken string `json:"kube_token" yaml:"kube_token"`
|
|
}
|
|
|
|
var config Config
|
|
|
|
func init() {
|
|
err := yaml.Unmarshal(configData, &config)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// GetOnlKubeConfigByNamespace 获取namespace的线上kube配置
|
|
func GetOnlKubeConfigByNamespace(namespace string) KubeConfig {
|
|
return config.Kube[namespace].Onl
|
|
}
|
|
|
|
// GetTestKubeConfigByNamespace 获取namespace的测试kube配置
|
|
func GetTestKubeConfigByNamespace(namespace string) KubeConfig {
|
|
return config.Kube[namespace].Onl
|
|
}
|
|
|
|
// GetRegistryConfig 获取镜像仓库配置
|
|
func GetRegistryConfig() Registry {
|
|
return config.Reg
|
|
}
|