dev-v2.0.0: fix binary file's name are different from their origin name

Signed-off-by: 24sama <leo@kubesphere.io>
This commit is contained in:
24sama 2021-11-24 16:44:03 +08:00
parent 5e1993d536
commit efd7e28bb6
4 changed files with 19 additions and 8 deletions

View File

@ -23,6 +23,7 @@ import (
"github.com/kubesphere/kubekey/pkg/files"
"github.com/kubesphere/kubekey/pkg/utils"
"github.com/pkg/errors"
"path"
"path/filepath"
)
@ -45,7 +46,9 @@ func (s *SyncCrictlBinaries) Execute(runtime connector.Runtime) error {
if !ok {
return errors.New("get KubeBinary key crictl by pipeline cache failed")
}
dst := filepath.Join(common.TmpDir, crictl.Name)
fileName := path.Base(crictl.Path)
dst := filepath.Join(common.TmpDir, fileName)
if err := runtime.GetRunner().SudoScp(crictl.Path, dst); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("sync crictl binaries failed"))

View File

@ -23,6 +23,7 @@ import (
"github.com/kubesphere/kubekey/pkg/files"
"github.com/kubesphere/kubekey/pkg/utils"
"github.com/pkg/errors"
"path"
"path/filepath"
)
@ -45,7 +46,9 @@ func (s *SyncDockerBinaries) Execute(runtime connector.Runtime) error {
if !ok {
return errors.New("get KubeBinary key docker by pipeline cache failed")
}
dst := filepath.Join(common.TmpDir, docker.Name)
fileName := path.Base(docker.Path)
dst := filepath.Join(common.TmpDir, fileName)
if err := runtime.GetRunner().Scp(docker.Path, dst); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("sync docker binaries failed"))

View File

@ -34,6 +34,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kube "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"path"
"path/filepath"
"strings"
)
@ -112,17 +113,18 @@ func SyncKubeBinaries(runtime connector.Runtime, binariesMap map[string]files.Ku
return fmt.Errorf("get kube binary %s info failed: no such key", name)
}
fileName := path.Base(binary.Path)
switch name {
case "kubecni":
dst := filepath.Join("/opt/cni/bin", binary.Name)
if err := runtime.GetRunner().SudoScp(binary.Path, dst); err != nil {
dst := filepath.Join(common.TmpDir, fileName)
if err := runtime.GetRunner().Scp(binary.Path, dst); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("sync kube binaries failed"))
}
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("tar -zxf %s -C /opt/cni/bin", dst), false); err != nil {
return err
}
default:
dst := filepath.Join(common.BinDir, binary.Name)
dst := filepath.Join(common.BinDir, fileName)
if err := runtime.GetRunner().SudoScp(binary.Path, dst); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("sync kube binaries failed"))
}

View File

@ -42,6 +42,7 @@ import (
kube "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"os"
"path"
"path/filepath"
"sort"
"strings"
@ -122,21 +123,23 @@ func SyncKubeBinaries(runtime connector.Runtime, binariesMap map[string]files.Ku
if !ok {
return fmt.Errorf("get kube binary %s info failed: no such key", name)
}
fileName := path.Base(binary.Path)
switch name {
//case "kubelet":
// if err := runtime.GetRunner().Scp(binary.Path, fmt.Sprintf("%s/%s", common.TmpDir, binary.Name)); err != nil {
// return errors.Wrap(errors.WithStack(err), fmt.Sprintf("sync kube binaries failed"))
// }
case "kubecni":
dst := filepath.Join("/opt/cni/bin", binary.Name)
if err := runtime.GetRunner().SudoScp(binary.Path, dst); err != nil {
dst := filepath.Join(common.TmpDir, fileName)
if err := runtime.GetRunner().Scp(binary.Path, dst); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("sync kube binaries failed"))
}
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("tar -zxf %s -C /opt/cni/bin", dst), false); err != nil {
return err
}
default:
dst := filepath.Join(common.BinDir, binary.Name)
dst := filepath.Join(common.BinDir, fileName)
if err := runtime.GetRunner().SudoScp(binary.Path, dst); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("sync kube binaries failed"))
}