drone_plugin/config/kube.go

59 lines
1.3 KiB
Go
Raw Permalink Normal View History

2022-01-10 17:51:52 +08:00
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 {
2022-01-10 23:55:12 +08:00
return config.Kube[namespace].Test
2022-01-10 17:51:52 +08:00
}
// GetRegistryConfig 获取镜像仓库配置
func GetRegistryConfig() Registry {
return config.Reg
}