Files
k3s/pkg/deploy/stage.go
Brad Davidson 3cb6c2dc92 Avoid use of github.com/pkg/errors functions that capture stack
We are not making use of the stack traces that these functions capture, so we should avoid using them as unnecessary overhead.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit bed1f66880)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-03-07 14:46:16 -08:00

47 lines
1.0 KiB
Go

//go:build !no_stage
package deploy
import (
"bytes"
"os"
"path/filepath"
"strings"
pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func Stage(dataDir string, templateVars map[string]string, skips map[string]bool) error {
staging:
for _, name := range AssetNames() {
nameNoExtension := strings.TrimSuffix(name, filepath.Ext(name))
if skips[name] || skips[nameNoExtension] {
continue staging
}
namePath := strings.Split(name, string(os.PathSeparator))
for i := 1; i < len(namePath); i++ {
subPath := filepath.Join(namePath[0:i]...)
if skips[subPath] {
continue staging
}
}
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)
os.MkdirAll(filepath.Dir(p), 0700)
logrus.Info("Writing manifest: ", p)
if err := os.WriteFile(p, content, 0600); err != nil {
return pkgerrors.WithMessagef(err, "failed to write to %s", name)
}
}
return nil
}