mirror of
https://git.vectorsigma.ru/public/k3s.git
synced 2026-08-03 08:29:39 +00:00
Instead of skipping the manifest when listing the directory, we now skip creating it in the first place. This allows users to deploy manifests that replaces the ones bundled, without having to come up with a new name. Fixes #230.
40 lines
785 B
Go
40 lines
785 B
Go
package deploy
|
|
|
|
import (
|
|
"bytes"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func Stage(dataDir string, templateVars map[string]string, skipList []string) error {
|
|
os.MkdirAll(dataDir, 0700)
|
|
|
|
skips := map[string]bool{}
|
|
for _, skip := range skipList {
|
|
skips[skip] = true
|
|
}
|
|
|
|
for _, name := range AssetNames() {
|
|
if skips[name] {
|
|
continue
|
|
}
|
|
content, err := Asset(name)
|
|
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 {
|
|
return errors.Wrapf(err, "failed to write to %s", name)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|