Commit 392cfb12 authored by Vladimir Zorin's avatar Vladimir Zorin

Add basic templating support for manifests

parent 44cce9a7
...@@ -162,7 +162,7 @@ metadata: ...@@ -162,7 +162,7 @@ metadata:
spec: spec:
selector: selector:
k8s-app: kube-dns k8s-app: kube-dns
clusterIP: 10.43.0.10 clusterIP: %{CLUSTER_DNS}%
ports: ports:
- name: dns - name: dns
port: 53 port: 53
......
package deploy package deploy
import ( import (
"bytes"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
) )
func Stage(dataDir string) error { func Stage(dataDir string, templateVars map[string]string) error {
os.MkdirAll(dataDir, 0700) os.MkdirAll(dataDir, 0700)
for _, name := range AssetNames() { for _, name := range AssetNames() {
...@@ -17,7 +17,9 @@ func Stage(dataDir string) error { ...@@ -17,7 +17,9 @@ func Stage(dataDir string) error {
if err != nil { if err != nil {
return err return err
} }
for k, v := range templateVars {
content = bytes.Replace(content, []byte(k), []byte(v), -1)
}
p := filepath.Join(dataDir, name) p := filepath.Join(dataDir, name)
logrus.Info("Writing manifest: ", p) logrus.Info("Writing manifest: ", p)
if err := ioutil.WriteFile(p, content, 0600); err != nil { if err := ioutil.WriteFile(p, content, 0600); err != nil {
......
...@@ -120,7 +120,8 @@ func startNorman(ctx context.Context, config *Config) (string, error) { ...@@ -120,7 +120,8 @@ func startNorman(ctx context.Context, config *Config) (string, error) {
}, },
func(ctx context.Context) error { func(ctx context.Context) error {
dataDir := filepath.Join(controlConfig.DataDir, "manifests") dataDir := filepath.Join(controlConfig.DataDir, "manifests")
if err := deploy.Stage(dataDir); err != nil { templateVars := map[string]string{"%{CLUSTER_DNS}%": controlConfig.ClusterDNS.String()}
if err := deploy.Stage(dataDir, templateVars); err != nil {
return err return err
} }
if err := deploy.WatchFiles(ctx, controlConfig.Skips, dataDir); err != nil { if err := deploy.WatchFiles(ctx, controlConfig.Skips, dataDir); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment