k3s/pkg/deploy/stage.go

41 lines
786 B
Go
Raw Normal View History

2019-01-22 21:14:58 +00:00
package deploy
import (
"bytes"
2019-01-22 21:14:58 +00:00
"io/ioutil"
"os"
"path/filepath"
2019-03-25 04:54:52 +00:00
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
2019-01-22 21:14:58 +00:00
)
func Stage(dataDir string, templateVars map[string]string, skipList []string) error {
2019-01-22 21:14:58 +00:00
os.MkdirAll(dataDir, 0700)
skips := map[string]bool{}
for _, skip := range skipList {
skips[skip] = true
}
2019-01-22 21:14:58 +00:00
for _, name := range AssetNames() {
if skips[name] {
continue
}
2019-01-22 21:14:58 +00:00
content, err := Asset(name)
if err != nil {
return err
}
for k, v := range templateVars {
content = bytes.Replace(content, []byte(k), []byte(v), -1)
}
2019-01-22 21:14:58 +00:00
p := filepath.Join(dataDir, name)
logrus.Info("Writing manifest: ", p)
if err := ioutil.WriteFile(p, content, 0600); err != nil {
return errors.Wrapf(err, "failed to write to %s", name)
}
}
return nil
}