PE-5115 add cluster reset event (#95)

* add cluster reset event

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* bump go to 1.23

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* fix uninstall script name

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

---------

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>
This commit is contained in:
Nianyu Shen
2024-09-29 18:28:26 -07:00
committed by GitHub
parent 1426d16933
commit 4fcff11e7e
8 changed files with 67 additions and 132 deletions

View File

@@ -1,7 +1,6 @@
package provider
import (
"bytes"
"encoding/json"
"fmt"
@@ -16,16 +15,11 @@ import (
kyaml "sigs.k8s.io/yaml"
_ "embed"
"text/template"
"github.com/kairos-io/provider-k3s/api"
"github.com/kairos-io/provider-k3s/pkg/constants"
"github.com/kairos-io/provider-k3s/pkg/types"
)
//go:embed mount.tmpl
var mountTemplate string
const (
configurationPath = "/etc/rancher/k3s/config.d"
containerdEnvConfigPath = "/etc/default"
@@ -143,55 +137,10 @@ func parseFiles(cluster clusterplugin.Cluster, systemName string) []yip.File {
return files
}
func rootPathMountStage(rootPath string) yip.Stage {
mps := []types.MountPoint{
{
Name: "etc-rancher",
Source: filepath.Join(rootPath, "etc/rancher"),
Target: "/etc/rancher",
},
{
Name: "var-lib-rancher",
Source: filepath.Join(rootPath, "var/lib/rancher"),
Target: "/var/lib/rancher",
},
}
stage := yip.Stage{
Name: "Mount K3s data, conf directories",
}
for _, mp := range mps {
stage.Files = append(stage.Files, yip.File{
Path: filepath.Join(constants.RunSystemdSystemDir, fmt.Sprintf("%s.mount", mp.Name)),
Permissions: 0644,
Content: parseMountUnitFile(mp),
})
stage.Commands = append(stage.Commands,
fmt.Sprintf("mkdir -p %s", mp.Source),
fmt.Sprintf("mkdir -p %s", mp.Target),
fmt.Sprintf("systemctl enable --now %s.mount", mp.Name),
)
}
return stage
}
func parseMountUnitFile(mp types.MountPoint) string {
mount, _ := template.New("mount").Parse(mountTemplate)
var buf bytes.Buffer
_ = mount.Execute(&buf, mp)
return buf.String()
}
func parseStages(cluster clusterplugin.Cluster, files []yip.File, systemName string) []yip.Stage {
var stages []yip.Stage
clusterRootPath := getClusterRootPath(cluster)
if len(clusterRootPath) > 0 && clusterRootPath != "/" {
stages = append(stages, rootPathMountStage(clusterRootPath))
}
stages = append(stages, yip.Stage{
Name: constants.InstallK3sConfigFiles,
Files: files,