mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
kubeadm: Move the method used only in the test to postupgrade_test.go
Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
parent
f563910656
commit
1eb6282016
@ -296,26 +296,3 @@ func GetKubeletDir(dryRun bool) (string, error) {
|
||||
}
|
||||
return kubeadmconstants.KubeletRunDirectory, nil
|
||||
}
|
||||
|
||||
// moveFiles moves files from one directory to another.
|
||||
func moveFiles(files map[string]string) error {
|
||||
filesToRecover := make(map[string]string, len(files))
|
||||
for from, to := range files {
|
||||
if err := os.Rename(from, to); err != nil {
|
||||
return rollbackFiles(filesToRecover, err)
|
||||
}
|
||||
filesToRecover[to] = from
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// rollbackFiles moves the files back to the original directory.
|
||||
func rollbackFiles(files map[string]string, originalErr error) error {
|
||||
errs := []error{originalErr}
|
||||
for from, to := range files {
|
||||
if err := os.Rename(from, to); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
return errors.Errorf("couldn't move these files: %v. Got errors: %v", files, errorsutil.NewAggregate(errs))
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
errorsutil "k8s.io/apimachinery/pkg/util/errors"
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
@ -206,3 +207,26 @@ func (cc *componentConfig) IsUserSupplied() bool {
|
||||
func (cc *componentConfig) SetUserSupplied(userSupplied bool) {
|
||||
cc.userSupplied = userSupplied
|
||||
}
|
||||
|
||||
// moveFiles moves files from one directory to another.
|
||||
func moveFiles(files map[string]string) error {
|
||||
filesToRecover := make(map[string]string, len(files))
|
||||
for from, to := range files {
|
||||
if err := os.Rename(from, to); err != nil {
|
||||
return rollbackFiles(filesToRecover, err)
|
||||
}
|
||||
filesToRecover[to] = from
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// rollbackFiles moves the files back to the original directory.
|
||||
func rollbackFiles(files map[string]string, originalErr error) error {
|
||||
errs := []error{originalErr}
|
||||
for from, to := range files {
|
||||
if err := os.Rename(from, to); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
return errors.Errorf("couldn't move these files: %v. Got errors: %v", files, errorsutil.NewAggregate(errs))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user