remove bootstrap pods from cluster, and render in hosts' context
This commit is contained in:
@ -3,12 +3,9 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"path"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"novit.tech/direktil/local-server/pkg/clustersconfig"
|
||||
)
|
||||
|
||||
@ -117,106 +114,3 @@ type namePod struct {
|
||||
Name string
|
||||
Pod map[string]interface{}
|
||||
}
|
||||
|
||||
func renderBootstrapPods(cluster *clustersconfig.Cluster) (pods []namePod) {
|
||||
if cluster.BootstrapPods == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
bootstrapPods := src.BootstrapPods[cluster.BootstrapPods]
|
||||
if bootstrapPods == nil {
|
||||
log.Fatalf("no bootstrap pods template named %q", cluster.BootstrapPods)
|
||||
}
|
||||
|
||||
// render bootstrap pods
|
||||
parts := bytes.Split(renderClusterTemplates(cluster, "bootstrap-pods", bootstrapPods), []byte("\n---\n"))
|
||||
for _, part := range parts {
|
||||
buf := bytes.NewBuffer(part)
|
||||
dec := yaml.NewDecoder(buf)
|
||||
|
||||
for n := 0; ; n++ {
|
||||
str := buf.String()
|
||||
|
||||
podMap := map[string]interface{}{}
|
||||
err := dec.Decode(podMap)
|
||||
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
log.Fatalf("bootstrap pod %d: failed to parse: %v\n%s", n, err, str)
|
||||
}
|
||||
|
||||
if len(podMap) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if podMap["metadata"] == nil {
|
||||
log.Fatalf("bootstrap pod %d: no metadata\n%s", n, buf.String())
|
||||
}
|
||||
|
||||
md := podMap["metadata"].(map[interface{}]interface{})
|
||||
|
||||
namespace := md["namespace"].(string)
|
||||
name := md["name"].(string)
|
||||
|
||||
pods = append(pods, namePod{namespace, name, podMap})
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func renderBootstrapPodsDS(cluster *clustersconfig.Cluster) string {
|
||||
buf := &bytes.Buffer{}
|
||||
enc := yaml.NewEncoder(buf)
|
||||
for _, namePod := range renderBootstrapPods(cluster) {
|
||||
pod := namePod.Pod
|
||||
|
||||
md := pod["metadata"].(map[interface{}]interface{})
|
||||
labels := md["labels"]
|
||||
|
||||
if labels == nil {
|
||||
labels = map[string]interface{}{
|
||||
"app": namePod.Name,
|
||||
}
|
||||
md["labels"] = labels
|
||||
}
|
||||
|
||||
ann := md["annotations"]
|
||||
annotations := map[interface{}]interface{}{}
|
||||
if ann != nil {
|
||||
annotations = ann.(map[interface{}]interface{})
|
||||
}
|
||||
annotations["node.kubernetes.io/bootstrap-checkpoint"] = "true"
|
||||
|
||||
md["annotations"] = annotations
|
||||
|
||||
delete(md, "name")
|
||||
delete(md, "namespace")
|
||||
|
||||
err := enc.Encode(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "DaemonSet",
|
||||
"metadata": map[string]interface{}{
|
||||
"namespace": namePod.Namespace,
|
||||
"name": namePod.Name,
|
||||
"labels": labels,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"minReadySeconds": 60,
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": labels,
|
||||
},
|
||||
"template": map[string]interface{}{
|
||||
"metadata": pod["metadata"],
|
||||
"spec": pod["spec"],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
Reference in New Issue
Block a user