Skip to content

Commit 90ff2a0

Browse files
committed
feat(distros): add rke2/k3s setup; call setup func in install
Signed-off-by: Vaughn Dice <[email protected]>
1 parent 9e6b013 commit 90ff2a0

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

cmd/node-installer/install.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ var installCmd = &cobra.Command{
4545
}
4646

4747
config.Runtime.ConfigPath = distro.ConfigPath
48+
env := preset.Env{ConfigPath: distro.ConfigPath, HostFs: hostFs}
4849

49-
if err := RunInstall(config, rootFs, hostFs, distro.Restarter(preset.Env{ConfigPath: distro.ConfigPath, HostFs: hostFs})); err != nil {
50+
if err = distro.Setup(env); err != nil {
51+
slog.Error("failed to run distro setup", "error", err)
52+
os.Exit(1)
53+
}
54+
55+
if err := RunInstall(config, rootFs, hostFs, distro.Restarter(env)); err != nil {
5056
slog.Error("failed to install", "error", err)
5157
os.Exit(1)
5258
}

internal/preset/preset.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package preset
22

33
import (
44
"errors"
5+
"io"
56
"os"
7+
"strings"
68

79
"github.com/spf13/afero"
810
"github.com/spinkube/runtime-class-manager/internal/containerd"
@@ -45,7 +47,28 @@ var RKE2 = Default.WithConfigPath("/var/lib/rancher/rke2/agent/etc/containerd/co
4547
}
4648

4749
if errors.Is(err, os.ErrNotExist) {
48-
// TODO: Copy file from original file to new config file
50+
// Copy base config into .tmpl version
51+
src, _ := strings.CutSuffix(env.ConfigPath, ".tmpl")
52+
in, err := env.HostFs.Open(src)
53+
if err != nil {
54+
return err
55+
}
56+
defer in.Close()
57+
out, err := env.HostFs.Create(env.ConfigPath)
58+
if err != nil {
59+
return err
60+
}
61+
defer func() {
62+
cerr := out.Close()
63+
if err == nil {
64+
err = cerr
65+
}
66+
}()
67+
if _, err = io.Copy(out, in); err != nil {
68+
return err
69+
}
70+
err = out.Sync()
71+
4972
return nil
5073
}
5174

0 commit comments

Comments
 (0)