Skip to content

Commit

Permalink
fix: get kubeType when uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
aby913 committed Sep 26, 2024
1 parent 4b4b0ae commit 8ba56f2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmd/ctl/options/cli_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func (o *CliKubeInitializeOptions) AddFlags(cmd *cobra.Command) {
}

type CliTerminusUninstallOptions struct {
Version string
Version string
// KubeType string
MiniKube bool
BaseDir string
All bool
Expand All @@ -37,6 +38,7 @@ func NewCliTerminusUninstallOptions() *CliTerminusUninstallOptions {
}

func (o *CliTerminusUninstallOptions) AddFlags(cmd *cobra.Command) {
// cmd.Flags().StringVar(&o.KubeType, "kube", "k3s", "Set kube type, e.g., k3s or k8s")
cmd.Flags().StringVarP(&o.Version, "version", "v", "", "Set install-wizard version, e.g., 1.7.0, 1.7.0-rc.1, 1.8.0-20240813")
cmd.Flags().BoolVar(&o.MiniKube, "minikube", false, "Set minikube flag")
cmd.Flags().StringVar(&o.BaseDir, "base-dir", "", "Set uninstall package base dir , default value $HOME/.terminus")
Expand Down
20 changes: 20 additions & 0 deletions pkg/kubernetes/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ import (
"bytetrade.io/web3os/installer/pkg/utils"
)

type GetKubeType struct{}

func (g *GetKubeType) Execute() (kubeType string) {
kubeType = common.K3s
var getKubeVersion = new(GetKubeVersion)
_, kubeType, _ = getKubeVersion.Execute()

if kubeType != "" {
return
}

if util.IsExist("/etc/systemd/system/k3s.service") || util.IsExist("/usr/local/bin/k3s-uninstall.sh") {
return
} else {
kubeType = common.K8s
}

return
}

type GetKubeVersion struct{}

func (g *GetKubeVersion) Execute() (string, string, error) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/phase/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func GetTerminusVersion() (string, error) {
return terminusTask.Execute()
}

func GetKubeType() string {
var kubeTypeTask = &kubernetes.GetKubeType{}
return kubeTypeTask.Execute()
}

func GetKubeVersion() (string, string, error) {
var kubeTask = &kubernetes.GetKubeVersion{}
return kubeTask.Execute()
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipelines/uninstall_terminus.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func UninstallTerminusPipeline(opt *options.CliTerminusUninstallOptions) error {
_, kubeType, _ := phase.GetKubeVersion()
kubeType := phase.GetKubeType()
// var deleteCache, err = formatDeleteCache(opt)
// if err != nil {
// return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/terminus/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ type GenerateInstalledPhaseState struct {
}

func (t *GenerateInstalledPhaseState) Execute(runtime connector.Runtime) error {
var content = fmt.Sprintf("%s %s", t.KubeConf.Arg.TerminusVersion, t.KubeConf.Arg.Kubetype)
var phaseState = path.Join(runtime.GetBaseDir(), ".installed")
if err := util.WriteFile(phaseState, nil, cc.FileMode0644); err != nil {
if err := util.WriteFile(phaseState, []byte(content), cc.FileMode0644); err != nil {
return err
}
return nil
Expand Down

0 comments on commit 8ba56f2

Please sign in to comment.