sanity commit
This commit is contained in:
@ -77,6 +77,12 @@ func main() {
|
||||
|
||||
dst.Hosts = append(dst.Hosts, &localconfig.Host{
|
||||
Name: host.Name,
|
||||
|
||||
ClusterName: ctx.Cluster.Name,
|
||||
|
||||
Labels: ctx.Labels,
|
||||
Annotations: ctx.Annotations,
|
||||
|
||||
MACs: macs,
|
||||
IPs: ips,
|
||||
|
||||
|
@ -77,7 +77,7 @@ func renderClusterTemplates(cluster *clustersconfig.Cluster, setName string,
|
||||
|
||||
funcs := clusterFuncs(cluster)
|
||||
|
||||
log.Print("rendering cluster templates in ", setName, " with ", clusterAsMap)
|
||||
log.Print("rendering cluster templates in ", setName)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
|
@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"path"
|
||||
@ -14,6 +16,9 @@ import (
|
||||
)
|
||||
|
||||
type renderContext struct {
|
||||
Labels map[string]string
|
||||
Annotations map[string]string
|
||||
|
||||
Host *clustersconfig.Host
|
||||
Group *clustersconfig.Group
|
||||
Cluster *clustersconfig.Cluster
|
||||
@ -47,9 +52,10 @@ func newRenderContext(host *clustersconfig.Host, cfg *clustersconfig.Config) (ct
|
||||
mapMerge(vars, oVars)
|
||||
}
|
||||
|
||||
log.Print("vars: ", vars)
|
||||
|
||||
return &renderContext{
|
||||
Labels: mergeLabels(cluster.Labels, group.Labels, host.Labels),
|
||||
Annotations: mergeLabels(cluster.Annotations, group.Annotations, host.Annotations),
|
||||
|
||||
Host: host,
|
||||
Group: group,
|
||||
Cluster: cluster,
|
||||
@ -61,6 +67,18 @@ func newRenderContext(host *clustersconfig.Host, cfg *clustersconfig.Config) (ct
|
||||
}, nil
|
||||
}
|
||||
|
||||
func mergeLabels(sources ...map[string]string) map[string]string {
|
||||
ret := map[string]string{}
|
||||
|
||||
for _, src := range sources {
|
||||
for k, v := range src {
|
||||
ret[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func mapMerge(target, source map[string]interface{}) {
|
||||
for k, v := range source {
|
||||
target[k] = genericMerge(target[k], v)
|
||||
@ -179,6 +197,11 @@ func (ctx *renderContext) Config() string {
|
||||
return string(ba), err
|
||||
}
|
||||
|
||||
extraFuncs["machine_id"] = func() string {
|
||||
ba := sha1.Sum([]byte(ctx.Cluster.Name + "/" + ctx.Host.Name)) // TODO: check semantics of machine-id
|
||||
return hex.EncodeToString(ba[:])
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 4096))
|
||||
if err := ctx.ConfigTemplate.Execute(ctxName, "config", buf, ctxMap, extraFuncs); err != nil {
|
||||
log.Fatalf("failed to render config %q for host %q: %v", ctx.Group.Config, ctx.Host.Name, err)
|
||||
|
@ -101,6 +101,23 @@ func wsClusterSetPassword(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
}
|
||||
|
||||
func wsClusterToken(req *restful.Request, resp *restful.Response) {
|
||||
cluster := wsReadCluster(req, resp)
|
||||
if cluster == nil {
|
||||
return
|
||||
}
|
||||
|
||||
name := req.PathParameter("token-name")
|
||||
|
||||
token, err := secretData.Token(cluster.Name, name)
|
||||
if err != nil {
|
||||
wsError(resp, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp.WriteEntity(token)
|
||||
}
|
||||
|
||||
func wsClusterBootstrapPods(req *restful.Request, resp *restful.Response) {
|
||||
cluster := wsReadCluster(req, resp)
|
||||
if cluster == nil {
|
||||
|
@ -27,7 +27,8 @@ func (ws *wsHost) register(rws *restful.WebService, alterRB func(*restful.RouteB
|
||||
|
||||
for _, rb := range []*restful.RouteBuilder{
|
||||
rws.GET(ws.prefix).To(ws.get).
|
||||
Doc("Get the " + ws.hostDoc + "'s details"),
|
||||
Doc("Get the "+ws.hostDoc+"'s details").
|
||||
Returns(200, "OK", localconfig.Host{}),
|
||||
|
||||
// raw configuration
|
||||
b("config").
|
||||
|
@ -48,6 +48,9 @@ func registerWS(rest *restful.Container) {
|
||||
ws.Route(ws.PUT("/clusters/{cluster-name}/passwords/{password-name}").To(wsClusterSetPassword).
|
||||
Doc("Set cluster's password"))
|
||||
|
||||
ws.Route(ws.GET("/clusters/{cluster-name}/tokens/{token-name}").To(wsClusterToken).
|
||||
Doc("Get cluster's token"))
|
||||
|
||||
ws.Route(ws.GET("/hosts").To(wsListHosts).
|
||||
Doc("List hosts"))
|
||||
|
||||
|
Reference in New Issue
Block a user