boostrap pods -> static pods

This commit is contained in:
Mikaël Cluseau 2023-05-15 16:22:04 +02:00
parent 50bb60823f
commit b1cdb30622
4 changed files with 23 additions and 24 deletions

View File

@ -156,8 +156,8 @@ func (ctx *renderContext) renderConfigTo(buf io.Writer, configTemplate *clusters
extraFuncs := ctx.templateFuncs(ctxMap) extraFuncs := ctx.templateFuncs(ctxMap)
extraFuncs["bootstrap_pods_files"] = func(dir string) (string, error) { extraFuncs["static_pods_files"] = func(dir string) (string, error) {
namePods := ctx.renderBootstrapPods() namePods := ctx.renderStaticPods()
defs := make([]config.FileDef, 0) defs := make([]config.FileDef, 0)

View File

@ -10,18 +10,18 @@ import (
"novit.tech/direktil/local-server/pkg/clustersconfig" "novit.tech/direktil/local-server/pkg/clustersconfig"
) )
func (ctx *renderContext) renderBootstrapPods() (pods []namePod) { func (ctx *renderContext) renderStaticPods() (pods []namePod) {
if ctx.Host.BootstrapPods == "" { if ctx.Host.StaticPods == "" {
return return
} }
bootstrapPods, ok := src.BootstrapPods[ctx.Host.BootstrapPods] staticPods, ok := src.StaticPods[ctx.Host.StaticPods]
if !ok { if !ok {
log.Fatalf("no bootstrap pods template named %q", ctx.Host.BootstrapPods) log.Fatalf("no static pods template named %q", ctx.Host.StaticPods)
} }
// render bootstrap pods // render static pods
parts := bytes.Split(ctx.renderHostTemplates("bootstrap-pods", bootstrapPods), []byte("\n---\n")) parts := bytes.Split(ctx.renderHostTemplates("static-pods", staticPods), []byte("\n---\n"))
for _, part := range parts { for _, part := range parts {
buf := bytes.NewBuffer(part) buf := bytes.NewBuffer(part)
dec := yaml.NewDecoder(buf) dec := yaml.NewDecoder(buf)
@ -35,7 +35,7 @@ func (ctx *renderContext) renderBootstrapPods() (pods []namePod) {
if err == io.EOF { if err == io.EOF {
break break
} else if err != nil { } else if err != nil {
log.Fatalf("bootstrap pod %d: failed to parse: %v\n%s", n, err, str) log.Fatalf("static pod %d: failed to parse: %v\n%s", n, err, str)
} }
if len(podMap) == 0 { if len(podMap) == 0 {
@ -43,7 +43,7 @@ func (ctx *renderContext) renderBootstrapPods() (pods []namePod) {
} }
if podMap["metadata"] == nil { if podMap["metadata"] == nil {
log.Fatalf("bootstrap pod %d: no metadata\n%s", n, buf.String()) log.Fatalf("static pod %d: no metadata\n%s", n, buf.String())
} }
md := podMap["metadata"].(map[interface{}]interface{}) md := podMap["metadata"].(map[interface{}]interface{})

View File

@ -24,14 +24,13 @@ var (
) )
type Config struct { type Config struct {
Hosts []*Host Hosts []*Host
Clusters []*Cluster Clusters []*Cluster
Configs []*Template Configs []*Template
StaticPods []*Template `yaml:"static_pods"` StaticPods map[string][]*Template `yaml:"static_pods"`
BootstrapPods map[string][]*Template `yaml:"bootstrap_pods"` Addons map[string][]*Template
Addons map[string][]*Template SSLConfig string `yaml:"ssl_config"`
SSLConfig string `yaml:"ssl_config"` CertRequests []*CertRequest `yaml:"cert_requests"`
CertRequests []*CertRequest `yaml:"cert_requests"`
} }
func FromBytes(data []byte) (*Config, error) { func FromBytes(data []byte) (*Config, error) {
@ -209,7 +208,7 @@ type Host struct {
Config string Config string
Versions map[string]string Versions map[string]string
BootstrapPods string `yaml:"bootstrap_pods"` StaticPods string `yaml:"static_pods"`
Vars Vars Vars Vars
} }

View File

@ -34,8 +34,8 @@ func FromDir(
} }
config := &Config{ config := &Config{
Addons: make(map[string][]*Template), Addons: make(map[string][]*Template),
BootstrapPods: make(map[string][]*Template), StaticPods: make(map[string][]*Template),
} }
// load clusters // load clusters
@ -123,12 +123,12 @@ func FromDir(
// cluster bootstrap pods // cluster bootstrap pods
for _, host := range config.Hosts { for _, host := range config.Hosts {
bpSet := host.BootstrapPods bpSet := host.StaticPods
if bpSet == "" { if bpSet == "" {
continue continue
} }
if _, ok := config.BootstrapPods[bpSet]; ok { if _, ok := config.StaticPods[bpSet]; ok {
continue continue
} }
@ -137,7 +137,7 @@ func FromDir(
return nil, err return nil, err
} }
config.BootstrapPods[bpSet] = templates config.StaticPods[bpSet] = templates
} }
// load SSL configuration // load SSL configuration