From 392cfb1231deeff12c17f299ed5473299cddd115 Mon Sep 17 00:00:00 2001 From: Vladimir Zorin Date: Thu, 7 Mar 2019 01:22:55 +0200 Subject: [PATCH] Add basic templating support for manifests --- manifests/coredns.yaml | 2 +- pkg/deploy/stage.go | 12 +++++++----- pkg/deploy/zz_generated_bindata.go | 4 ++-- pkg/server/server.go | 3 ++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/manifests/coredns.yaml b/manifests/coredns.yaml index 8d8637b544..3b074027dc 100644 --- a/manifests/coredns.yaml +++ b/manifests/coredns.yaml @@ -162,7 +162,7 @@ metadata: spec: selector: k8s-app: kube-dns - clusterIP: 10.43.0.10 + clusterIP: %{CLUSTER_DNS}% ports: - name: dns port: 53 diff --git a/pkg/deploy/stage.go b/pkg/deploy/stage.go index 7cfd57395d..3feb1a9428 100644 --- a/pkg/deploy/stage.go +++ b/pkg/deploy/stage.go @@ -1,15 +1,15 @@ package deploy import ( + "bytes" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" "io/ioutil" "os" "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) for _, name := range AssetNames() { @@ -17,7 +17,9 @@ func Stage(dataDir string) error { if err != nil { return err } - + for k, v := range templateVars { + content = bytes.Replace(content, []byte(k), []byte(v), -1) + } p := filepath.Join(dataDir, name) logrus.Info("Writing manifest: ", p) if err := ioutil.WriteFile(p, content, 0600); err != nil { diff --git a/pkg/deploy/zz_generated_bindata.go b/pkg/deploy/zz_generated_bindata.go index bcd7c367ce..7bd19200f9 100644 --- a/pkg/deploy/zz_generated_bindata.go +++ b/pkg/deploy/zz_generated_bindata.go @@ -69,7 +69,7 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var _corednsYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x56\x4d\x73\xdb\x36\x13\xbe\xeb\x57\x60\xf8\x5e\x5f\xca\xd2\xb8\x49\x5d\xdc\x12\xdb\x4d\x3d\xd3\xb8\x1a\xdb\xc9\xa5\xd3\xc9\xac\xc0\x95\x88\x1a\xc4\xa2\xc0\x52\xb1\xda\xe6\xbf\x77\xc0\x2f\x83\x34\x9d\x49\x32\xa1\x0e\x02\xb0\xd8\x67\x81\xfd\x78\x16\xe0\xf4\x7b\xf4\x41\x93\x95\xe2\xb0\x5e\xdc\x6b\x5b\x48\x71\x8b\xfe\xa0\x15\xbe\x52\x8a\x6a\xcb\x8b\x0a\x19\x0a\x60\x90\x0b\x21\x2c\x54\x28\x85\x22\x8f\x85\x0d\xdd\x3c\x38\x50\x28\xc5\x7d\xbd\xc5\x3c\x1c\x03\x63\xb5\xc8\xf3\x7c\x91\x42\xfb\x2d\xa8\x25\xd4\x5c\x92\xd7\x7f\x03\x6b\xb2\xcb\xfb\xb3\xb0\xd4\x74\x72\x58\x6f\x91\xa1\xb7\x7c\x6e\xea\xc0\xe8\x6f\xc8\xe0\xc8\xac\x81\x2d\x9a\x10\x47\xa2\xb1\xe3\x2d\x32\x36\xfa\x5b\x22\x0e\xec\xc1\x39\x6d\xf7\xad\xa1\xbc\xc0\x1d\xd4\x86\xc3\x70\xde\xf6\x54\xb2\x3f\xb6\xaf\x0d\x06\xb9\xc8\x05\x38\xfd\xc6\x53\xed\x1a\xe4\x5c\x64\xd9\x42\x08\x8f\x81\x6a\xaf\xb0\x5b\x43\x5b\x38\xd2\xb6\x01\xcb\x45\x68\x3d\xd3\x4e\x1c\x15\xed\x60\x70\x42\x9c\x1e\xd0\x6f\x3b\x5d\xa3\x03\x37\x83\x8f\xc0\xaa\xfc\x32\x7b\x96\x8a\x29\xcc\x1e\xf9\x7b\x38\xf4\xb5\xb6\x85\xb6\xfb\x91\x5f\xc1\x5a\xe2\x46\xbd\x73\xee\x1c\xee\xc8\xdf\x50\x33\xd5\xae\x00\x46\x29\x32\xf6\x35\x66\xdf\x3f\x3c\x64\xf0\x06\x77\xcd\xf9\x3a\x87\x7d\xe6\xc2\x0b\x21\x9e\xe6\xce\x33\xc8\xa1\xde\xfe\x89\x8a\x9b\xd8\xcf\xa6\xfa\x37\x27\xf8\x50\x3b\xe7\x64\x77\x7a\xff\x16\xdc\xb7\x94\x4d\xbf\xfd\x9c\x3c\xee\xb4\x41\x29\xfe\x6d\x7c\xba\x94\x2f\x4e\xc5\x3f\xcd\x30\x7e\xe8\x3d\xf9\x30\x4c\x4b\x04\xc3\xe5\x30\x7d\x0c\x80\x50\xad\x4b\x96\x86\x14\x18\xa1\x6d\x0e\x45\xe1\x97\xe0\x1d\x08\xed\x5e\xb6\x83\x47\x58\xd1\x64\xb4\xd0\x36\xa0\xaa\x3d\x26\xeb\xb5\x0b\xec\x11\xaa\x64\x69\x07\xc6\x70\xe9\xa9\xde\x97\xf3\xc0\xc3\xde\x4f\xc3\xc8\x79\xaa\x90\x4b\xac\x83\x90\x3f\xad\x5f\x9c\xa6\x82\x87\xa3\x58\x8a\xf5\xb2\xf9\x0d\xeb\x0a\x54\x89\xe2\x74\x35\x2c\x18\x22\x37\x4c\x3c\x1a\x82\x22\x91\x41\xb1\x05\x03\x56\xb5\x47\xff\xf4\x24\x48\xf8\xc0\x68\xe3\x30\x4c\xaa\xe4\x02\x9d\xa1\x63\x85\xdf\x46\x76\x93\xfc\x3f\x0b\x39\x38\xd7\x6d\x69\x15\xa7\x55\xd1\x02\x67\x31\xcc\x17\xd7\xb7\xd9\x22\x38\x54\x51\xfb\x7f\x1e\x9d\xd1\x0a\x82\x14\xd1\x09\xb1\x70\x18\xf7\xc7\x16\x98\x8f\x0e\xa5\xb8\x21\x63\xb4\xdd\xbf\x6b\x4a\xb0\x2d\xd9\x74\x45\x76\xee\xa8\xe0\xe1\x9d\x85\x03\x68\x03\xdb\x98\x47\x0d\x1c\x1a\x54\x4c\xbe\xdd\x53\x45\x4e\xfa\x35\x39\xf8\xfc\xd1\x19\x2b\x67\x06\xe0\xd4\x3b\x8d\xcf\x47\xfa\xcf\x5d\xbe\xbf\x5e\x33\x1e\x15\xdc\xf5\xc4\xc3\xcd\x3d\xc9\xa0\x4f\x39\x29\x7e\xb9\xb8\xc7\x63\x74\x99\xd7\xac\x15\x98\x57\x45\x41\x36\xfc\x66\xcd\x31\x4b\x92\x92\x5c\xd4\x24\x2f\x45\x76\xf9\xa0\x03\x87\x5e\x18\x59\xf5\x76\x74\xfd\xf8\xc5\x14\x98\xd0\x1b\x05\x29\x8c\xb6\xf5\x43\xb7\x49\x91\x65\xd0\x16\xfd\x70\x96\xfc\x49\x5a\xb4\x9f\xae\x60\xff\xb8\x7c\xd2\xfd\xcb\xf5\xf2\x74\xb9\x1a\x6f\xda\xd4\xc6\x6c\xc8\x68\x75\x94\xe2\x6a\x77\x4d\xbc\xf1\x18\xb0\x61\x9f\x3e\xb1\x93\x96\x30\xa4\xb7\xae\x34\x8f\x56\x62\x38\x2a\xf2\x47\x29\xd6\x3f\xae\xde\xea\x44\xe2\xf1\xaf\x1a\xc3\x74\xb7\x72\xb5\x14\xeb\xd5\xaa\x9a\xc5\x18\x41\x80\xdf\x07\x29\x7e\x17\x59\xae\xc8\xee\xb2\xff\x8b\xec\x04\x59\xf5\x97\x3a\xe9\xf9\x29\x13\x7f\x0c\x2a\x07\x32\x75\x85\x6f\x63\x54\x47\x71\xeb\xbd\x15\x69\x31\x6f\x37\x25\xf6\xab\xb8\x7f\x03\x5c\x4a\x91\x5a\x18\xdd\x05\x8a\x18\x67\x29\x62\xb7\x79\xa4\x0c\xf2\x63\x3b\x43\xa4\x36\xe4\x59\x8a\x84\x5d\xfa\x42\x1e\xe3\x3a\x4f\x4c\x8a\x8c\x14\xef\x2e\x36\x5f\x8b\x93\xb3\x72\xb3\x58\x77\xe7\x9f\xc1\x1a\x71\x5e\x8f\x56\x21\x7b\xad\xe6\x4f\x96\xa2\x35\xa4\xac\xf9\x78\x4e\x96\xf1\x81\xd3\xd0\x82\x31\xf4\x71\xe3\xf5\x41\x1b\xdc\xe3\x65\x50\x60\x9a\xfa\x91\x91\xa5\x43\xea\x6e\x05\x0e\xb6\xda\x68\xd6\x38\x49\x0e\x28\x8a\xf1\x42\x2e\xae\x2f\xef\x3e\xbc\xbe\xba\xbe\xf8\x70\x7b\x79\xf3\xfe\xea\xfc\x72\x24\x2e\x3c\xb9\xa9\x02\x18\x33\x13\xb8\x1b\x22\xfe\x59\x1b\xec\x7a\xf1\x38\x8c\x46\x1f\xd0\x62\x08\x1b\x4f\x5b\x4c\xf1\x4a\x66\xf7\x06\x79\x6c\xc2\xb5\x89\x32\x69\x78\xa2\x4b\x07\x29\xce\x56\x67\xab\xd1\x72\x50\x25\x46\x27\xff\x72\x77\xb7\x49\x04\xda\x6a\xd6\x60\x2e\xd0\xc0\xf1\x16\x15\xd9\x22\x48\xf1\x32\x55\x65\x5d\x21\xd5\x3c\x08\x5f\x24\xb2\x50\x2b\x85\x21\xdc\x95\x1e\x43\x49\xa6\x68\xd9\xb5\xff\x76\xa0\x4d\xed\x31\x91\xf6\xba\x85\x0d\x7d\xd9\x5f\xb4\x4f\xa0\x4e\xd0\x56\xc5\x57\x54\x8d\xea\x1f\x19\x63\xf7\xcc\x13\x53\x73\x61\xc6\x2a\x4c\xc3\xd5\x30\x6a\x5f\xca\x23\x59\xef\xe9\x41\xf8\xec\x73\xa7\x7b\x3f\xcd\xb4\xcd\xa4\x03\x3c\xdb\x37\x9f\x3c\x3f\x1f\x5f\x08\x91\x8c\xdb\xa0\x66\xb1\x6c\xb2\x19\x71\x50\x1e\xdc\xb3\xcf\xd0\x2f\x68\xc3\xdd\xf3\x28\xef\x7a\x52\x82\xf4\xa5\x0d\x7b\xdc\x52\xe7\x6c\x76\x36\xae\x36\x91\x7a\x97\x3f\x9c\x2e\x57\xcb\x75\x4c\xb4\x81\xbf\xf2\x09\x3b\xb9\x94\x76\xa6\x24\x95\xcf\x50\xd0\x33\x0a\x2d\x77\xe4\x33\x2c\xe3\xc6\x64\x34\x56\xf9\x2f\x00\x00\xff\xff\x73\x85\x8d\x7b\x11\x0e\x00\x00") +var _corednsYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x56\xdd\x6e\x1b\xb7\x12\xbe\xd7\x53\x10\x7b\x90\xbb\xb3\xb2\x04\x23\x39\x3e\xbc\x4b\x24\x37\x35\x90\xb8\x82\x65\xe7\xa6\x28\x82\x11\x77\x24\xb1\xe6\x72\x58\x72\x56\xb1\x9a\xe6\xdd\x0b\xee\x9f\xb9\xf2\x3a\x48\x82\xac\x2e\x44\x72\x38\xdf\x90\xf3\xf3\x0d\xc1\xe9\x0f\xe8\x83\x26\x2b\xc5\x61\x3e\xb9\xd7\xb6\x90\x62\x8d\xfe\xa0\x15\xbe\x56\x8a\x2a\xcb\x93\x12\x19\x0a\x60\x90\x13\x21\x2c\x94\x28\x85\x22\x8f\x85\x0d\xed\x3c\x38\x50\x28\xc5\x7d\xb5\xc1\x3c\x1c\x03\x63\x39\xc9\xf3\x7c\x92\x42\xfb\x0d\xa8\x29\x54\xbc\x27\xaf\xff\x06\xd6\x64\xa7\xf7\x17\x61\xaa\xe9\xec\x30\xdf\x20\x43\x67\x79\x61\xaa\xc0\xe8\x6f\xc8\xe0\xc0\xac\x81\x0d\x9a\x10\x47\xa2\xb6\xe3\x2d\x32\xd6\xfa\x1b\x22\x0e\xec\xc1\x39\x6d\x77\x8d\xa1\xbc\xc0\x2d\x54\x86\x43\x7f\xde\xe6\x54\xb2\x3b\xb6\xaf\x0c\x06\x39\xc9\x05\x38\xfd\xd6\x53\xe5\x6a\xe4\x5c\x64\xd9\x44\x08\x8f\x81\x2a\xaf\xb0\x5d\x43\x5b\x38\xd2\xb6\x06\xcb\x45\x68\x3c\xd3\x4c\x1c\x15\xcd\xa0\x77\x42\x9c\x1e\xd0\x6f\x5a\x5d\xa3\x03\xd7\x83\x4f\xc0\x6a\xff\x6d\xf6\x2c\x15\xa7\x30\x3b\xe4\x9f\xe1\xd0\x37\xda\x16\xda\xee\x06\x7e\x05\x6b\x89\x6b\xf5\xd6\xb9\x63\xb8\x03\x7f\x43\xc5\x54\xb9\x02\x18\xa5\xc8\xd8\x57\x98\xfd\xfc\xf0\x90\xc1\x1b\xdc\xd6\xe7\x6b\x1d\xf6\x95\x0b\x4f\x84\x78\x9a\x3b\xcf\x20\x87\x6a\xf3\x27\x2a\xae\x63\x3f\x9a\xea\x3f\x9c\xe0\x7d\xed\x2c\xc8\x6e\xf5\xee\x3d\xb8\x1f\x29\x9b\x6e\xfb\x82\x3c\x6e\xb5\x41\x29\xfe\xa9\x7d\x3a\x95\x2f\xcf\xc5\xe7\x7a\x18\x3f\xf4\x9e\x7c\xe8\xa7\x7b\x04\xc3\xfb\x7e\xfa\x18\x00\xa1\x1a\x97\x4c\x0d\x29\x30\x42\xdb\x1c\x8a\xc2\x4f\xc1\x3b\x10\xda\xbd\x6a\x06\x8f\xb0\xa2\xce\x68\xa1\x6d\x40\x55\x79\x4c\xd6\x2b\x17\xd8\x23\x94\xc9\xd2\x16\x8c\xe1\xbd\xa7\x6a\xb7\x1f\x07\xee\xf7\x7e\xe9\x47\xce\x53\x89\xbc\xc7\x2a\x08\xf9\xff\xf9\xcb\xf3\x54\xf0\x70\x14\x53\x31\x9f\xd6\xbf\x7e\x5d\x81\xda\xa3\x38\x9f\xf5\x0b\x86\xc8\xf5\x13\x8f\x86\xa0\x48\x64\x50\x6c\xc0\x80\x55\xcd\xd1\xbf\x3c\x09\x12\x3e\x30\xda\x38\x0c\x27\x55\xb2\x44\x67\xe8\x58\xe2\x8f\x91\xdd\x49\xfe\x5f\x84\x1c\x9c\x6b\xb7\x34\x8a\xa7\x55\xd1\x00\x67\x31\xcc\xcb\xeb\x75\x36\x09\x0e\x55\xd4\xfe\x8f\x47\x67\xb4\x82\x20\x45\x74\x42\x2c\x1c\xc6\xdd\xb1\x01\xe6\xa3\x43\x29\x6e\xc8\x18\x6d\x77\x77\x75\x09\x36\x25\x9b\xae\xc8\xd6\x1d\x25\x3c\xdc\x59\x38\x80\x36\xb0\x89\x79\x54\xc3\xa1\x41\xc5\xe4\x9b\x3d\x65\xe4\xa4\x77\xc9\xc1\xc7\x8f\xce\x58\x3a\xd3\x03\xa7\xde\xa9\x7d\x3e\xd0\x7f\xee\xf2\xdd\xf5\xea\xf1\xa0\xe0\xae\x4f\x3c\x5c\xdf\x93\x0c\xfa\x94\x93\xe2\x97\x8b\x7b\x3c\x46\x97\x79\xcd\x5a\x81\x79\x5d\x14\x64\xc3\x6f\xd6\x1c\xb3\x24\x29\xc9\x45\x4d\xf2\x52\x64\x97\x0f\x3a\x70\xe8\x84\x91\x55\xd7\x83\xeb\xc7\x2f\xa6\xc0\x09\xbd\x51\x90\xc2\x68\x5b\x3d\xb4\x9b\x14\x59\x06\x6d\xd1\xf7\x67\xc9\x9f\xa4\x45\xf3\xe9\x12\x76\x8f\xcb\x67\xed\xbf\x9c\x4f\xcf\xa7\xb3\xe1\xa6\x55\x65\xcc\x8a\x8c\x56\x47\x29\xae\xb6\xd7\xc4\x2b\x8f\x01\x6b\xf6\xe9\x12\x3b\x69\x09\x7d\x7a\xeb\x52\xf3\x60\x25\x86\xa3\x24\x7f\x94\x62\xfe\xbf\xd9\x7b\x9d\x48\x3c\xfe\x55\x61\x38\xdd\xad\x5c\x25\xc5\x7c\x36\x2b\x47\x31\x06\x10\xe0\x77\x41\x8a\xdf\x45\x96\x2b\xb2\xdb\xec\xbf\x22\x3b\x43\x56\xdd\xa5\xce\x3a\x7e\xca\xc4\x1f\xbd\xca\x81\x4c\x55\xe2\xfb\x18\xd5\x41\xdc\x3a\x6f\x45\x5a\xcc\x9b\x4d\x89\xfd\x32\xee\x5f\x01\xef\xa5\x48\x2d\x0c\xee\x02\x45\x8c\xb3\x14\xb1\xdb\x3c\x52\x06\xf9\xa1\x9d\x3e\x52\x2b\xf2\x2c\x45\xc2\x2e\x5d\x21\x0f\x71\x9d\x27\x26\x45\x46\x8a\xbb\xe5\xea\x7b\x71\x72\x56\x6e\x14\xeb\x76\xf1\x15\xac\x01\xe7\x75\x68\x25\xb2\xd7\x6a\xfc\x64\x29\x5a\x4d\xca\x9a\x8f\x0b\xb2\x8c\x0f\x9c\x86\x16\x8c\xa1\x4f\x2b\xaf\x0f\xda\xe0\x0e\x2f\x83\x02\x53\xd7\x8f\x8c\x2c\x1d\x52\x77\x2b\x70\xb0\xd1\x46\xb3\xc6\x93\xe4\x80\xa2\x18\x2e\xe4\xe2\xfa\xf2\xf6\xe3\x9b\xab\xeb\xe5\xc7\xf5\xe5\xcd\x87\xab\xc5\xe5\x40\x5c\x78\x72\xa7\x0a\x60\xcc\x48\xe0\x6e\x88\xf8\x17\x6d\xb0\xed\xc5\xc3\x30\x1a\x7d\x40\x8b\x21\xac\x3c\x6d\x30\xc5\xdb\x33\xbb\xb7\xc8\x43\x13\xae\x49\x94\x93\x86\x27\xda\x74\x90\xe2\x62\x76\x31\x1b\x2c\x07\xb5\xc7\xe8\xe4\x5f\x6f\x6f\x57\x89\x40\x5b\xcd\x1a\xcc\x12\x0d\x1c\xd7\xa8\xc8\x16\x41\x8a\x57\xa9\x2a\xeb\x12\xa9\xe2\x5e\xf8\x32\x91\x85\x4a\x29\x0c\xe1\x76\xef\x31\xec\xc9\x14\x0d\xbb\x76\xdf\x16\xb4\xa9\x3c\x26\xd2\x4e\xb7\xb0\xa1\x2b\xfb\x65\xf3\x04\x6a\x05\x4d\x55\x7c\x47\xd5\xa8\xee\x91\x31\x74\xcf\x38\x31\xd5\x17\x66\x2c\xc3\x69\xb8\x6a\x46\xed\x4a\x79\x20\xeb\x3c\xdd\x0b\x9f\x7d\xee\xb4\xef\xa7\x91\xb6\x99\x74\x80\x67\xfb\xe6\x93\xe7\xe7\xe3\x0b\x21\x92\x71\x13\xd4\x2c\x96\x4d\x36\x22\x0e\xca\x83\x7b\xf6\x19\xfa\x0d\x6d\xb8\x7d\x1e\xe5\x6d\x4f\x4a\x90\xbe\xb5\x61\x0f\x5b\xea\x98\xcd\xd6\xc6\xd5\x4a\x8a\x17\x9f\x17\xef\xee\xd6\xb7\x97\x37\x1f\x97\xd7\xeb\x2f\x2f\x26\x09\x89\xe5\x27\x14\xe5\x52\xee\x39\x65\xaa\x7c\x84\x87\x9e\x51\x68\x08\x24\x1f\xa1\x1a\x37\x64\xa4\xa1\xca\xbf\x01\x00\x00\xff\xff\xfd\x32\xb3\x08\x16\x0e\x00\x00") func corednsYamlBytes() ([]byte, error) { return bindataRead( @@ -204,7 +204,6 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } - var _bintree = &bintree{nil, map[string]*bintree{ "coredns.yaml": &bintree{corednsYaml, map[string]*bintree{}}, "traefik.yaml": &bintree{traefikYaml, map[string]*bintree{}}, @@ -256,3 +255,4 @@ func _filePath(dir, name string) string { cannonicalName := strings.Replace(name, "\\", "/", -1) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) } + diff --git a/pkg/server/server.go b/pkg/server/server.go index 89e7926b5e..2c4e5cff6b 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -120,7 +120,8 @@ func startNorman(ctx context.Context, config *Config) (string, error) { }, func(ctx context.Context) error { 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 } if err := deploy.WatchFiles(ctx, controlConfig.Skips, dataDir); err != nil {