mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-28 20:22:45 +00:00
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
/*
|
|
Copyright 2022 The KubeSphere Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package os
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kubesphere/kubekey/cmd/kk/pkg/bootstrap/os/repository"
|
|
"github.com/kubesphere/kubekey/cmd/kk/pkg/common"
|
|
"github.com/kubesphere/kubekey/cmd/kk/pkg/core/connector"
|
|
"github.com/kubesphere/kubekey/cmd/kk/pkg/core/ending"
|
|
"github.com/pkg/errors"
|
|
"path/filepath"
|
|
)
|
|
|
|
type RollbackUmount struct {
|
|
common.KubeRollback
|
|
}
|
|
|
|
func (r *RollbackUmount) Execute(runtime connector.Runtime, result *ending.ActionResult) error {
|
|
mountPath := filepath.Join(common.TmpDir, "iso")
|
|
umountCmd := fmt.Sprintf("umount %s", mountPath)
|
|
if _, err := runtime.GetRunner().SudoCmd(umountCmd, false); err != nil {
|
|
return errors.Wrapf(errors.WithStack(err), "umount %s failed", mountPath)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type RecoverBackupSuccessNode struct {
|
|
common.KubeRollback
|
|
}
|
|
|
|
func (r *RecoverBackupSuccessNode) Execute(runtime connector.Runtime, result *ending.ActionResult) error {
|
|
if result.Status == ending.SUCCESS {
|
|
host := runtime.RemoteHost()
|
|
repo, ok := host.GetCache().Get("repo")
|
|
if !ok {
|
|
return errors.New("get repo failed by host cache")
|
|
}
|
|
|
|
re := repo.(repository.Interface)
|
|
if err := re.Reset(runtime); err != nil {
|
|
return errors.Wrapf(errors.WithStack(err), "reset repository failed")
|
|
}
|
|
}
|
|
|
|
mountPath := filepath.Join(common.TmpDir, "iso")
|
|
umountCmd := fmt.Sprintf("umount %s", mountPath)
|
|
if _, err := runtime.GetRunner().SudoCmd(umountCmd, false); err != nil {
|
|
return errors.Wrapf(errors.WithStack(err), "umount %s failed", mountPath)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type RecoverRepository struct {
|
|
common.KubeRollback
|
|
}
|
|
|
|
func (r *RecoverRepository) Execute(runtime connector.Runtime, result *ending.ActionResult) error {
|
|
host := runtime.RemoteHost()
|
|
repo, ok := host.GetCache().Get("repo")
|
|
if !ok {
|
|
return errors.New("get repo failed by host cache")
|
|
}
|
|
|
|
re := repo.(repository.Interface)
|
|
_ = re.Reset(runtime)
|
|
|
|
mountPath := filepath.Join(common.TmpDir, "iso")
|
|
umountCmd := fmt.Sprintf("umount %s", mountPath)
|
|
if _, err := runtime.GetRunner().SudoCmd(umountCmd, false); err != nil {
|
|
return errors.Wrapf(errors.WithStack(err), "umount %s failed", mountPath)
|
|
}
|
|
return nil
|
|
}
|