-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
8 changed files
with
67 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
module github.com/kairos-io/provider-k3s | ||
|
||
go 1.22.5 | ||
go 1.23.1 | ||
|
||
require ( | ||
github.com/kairos-io/kairos-sdk v0.4.2 | ||
github.com/mudler/yip v1.9.4 | ||
github.com/onsi/gomega v1.34.2 | ||
github.com/kairos-io/kairos-sdk v0.5.0 | ||
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5 | ||
github.com/mudler/yip v1.10.0 | ||
github.com/sirupsen/logrus v1.9.3 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
sigs.k8s.io/yaml v1.4.0 | ||
) | ||
|
||
require ( | ||
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 // indirect | ||
github.com/google/go-cmp v0.6.0 // indirect | ||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect | ||
github.com/hashicorp/errwrap v1.1.0 // indirect | ||
github.com/hashicorp/go-multierror v1.1.1 // indirect | ||
github.com/itchyny/gojq v0.12.16 // indirect | ||
github.com/itchyny/timefmt-go v0.1.6 // indirect | ||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5 // indirect | ||
github.com/nxadm/tail v1.4.11 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/rogpeppe/go-internal v1.11.0 // indirect | ||
github.com/stretchr/testify v1.9.0 // indirect | ||
github.com/twpayne/go-vfs/v4 v4.3.0 // indirect | ||
golang.org/x/net v0.28.0 // indirect | ||
golang.org/x/sys v0.24.0 // indirect | ||
golang.org/x/text v0.17.0 // indirect | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect | ||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package provider | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/kairos-io/kairos-sdk/bus" | ||
"github.com/kairos-io/kairos-sdk/clusterplugin" | ||
"github.com/mudler/go-pluggable" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func HandleClusterReset(event *pluggable.Event) pluggable.EventResponse { | ||
var payload bus.EventPayload | ||
var config clusterplugin.Config | ||
var response pluggable.EventResponse | ||
|
||
// parse the boot payload | ||
if err := json.Unmarshal([]byte(event.Data), &payload); err != nil { | ||
response.Error = fmt.Sprintf("failed to parse boot event: %s", err.Error()) | ||
return response | ||
} | ||
|
||
// parse config from boot payload | ||
if err := yaml.Unmarshal([]byte(payload.Config), &config); err != nil { | ||
response.Error = fmt.Sprintf("failed to parse config from boot event: %s", err.Error()) | ||
return response | ||
} | ||
|
||
if config.Cluster == nil { | ||
return response | ||
} | ||
|
||
clusterRootPath := getClusterRootPath(*config.Cluster) | ||
|
||
var uninstallScript string | ||
if config.Cluster.Role == clusterplugin.RoleWorker { | ||
uninstallScript = "k3s-agent-uninstall.sh" | ||
} else { | ||
uninstallScript = "k3s-uninstall.sh" | ||
} | ||
|
||
cmd := exec.Command("/bin/sh", "-c", filepath.Join(clusterRootPath, "/opt/k3s/scripts", uninstallScript)) | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
response.Error = fmt.Sprintf("failed to reset cluster: %s", string(output)) | ||
} | ||
|
||
return response | ||
} |