Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: install cifs-utils for mounting smb path & modified some command… #134

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/bootstrap/os/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,12 @@ func (n *NodeConfigureOS) Execute(runtime connector.Runtime) error {
}
}

_, err1 := runtime.GetRunner().SudoCmd(fmt.Sprintf("hostnamectl set-hostname %s && sed -i '/^127.0.1.1/s/.*/127.0.1.1 %s/g' /etc/hosts", host.GetName(), host.GetName()), false, false)
if err1 != nil {
return errors.Wrap(errors.WithStack(err1), "Failed to override hostname")
// if running in docker container, /etc/hosts file is bind mounting, cannot be replaced via mv command
if !n.KubeConf.Arg.IsOlaresInContainer {
_, err1 := runtime.GetRunner().SudoCmd(fmt.Sprintf("hostnamectl set-hostname %s && sed -i '/^127.0.1.1/s/.*/127.0.1.1 %s/g' /etc/hosts", host.GetName(), host.GetName()), false, false)
if err1 != nil {
return errors.Wrap(errors.WithStack(err1), "Failed to override hostname")
}
}

if runtime.GetSystemInfo().IsWsl() {
Expand Down
7 changes: 4 additions & 3 deletions pkg/bootstrap/patch/tasks.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package patch

import (
"bytetrade.io/web3os/installer/pkg/utils"
"fmt"
"github.com/pkg/errors"
"path"
"strings"

"bytetrade.io/web3os/installer/pkg/utils"
"github.com/pkg/errors"

kubekeyapiv1alpha2 "bytetrade.io/web3os/installer/apis/kubekey/v1alpha2"
"bytetrade.io/web3os/installer/pkg/binaries"
"bytetrade.io/web3os/installer/pkg/common"
Expand Down Expand Up @@ -38,7 +39,7 @@ type PatchTask struct {
func (t *PatchTask) Execute(runtime connector.Runtime) error {
var cmd string
var debianFrontend = "DEBIAN_FRONTEND=noninteractive"
var pre_reqs = "apt-transport-https ca-certificates curl"
var pre_reqs = "apt-transport-https ca-certificates curl cifs-utils"

if _, err := util.GetCommand(common.CommandGPG); err != nil {
pre_reqs = pre_reqs + " gnupg "
Expand Down
3 changes: 3 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ const (
ENV_AUTO_ADD_FIREWALL_RULES = "AUTO_ADD_FIREWALL_RULES"
ENV_TERMINUS_OS_DOMAINNAME = "TERMINUS_OS_DOMAINNAME"
ENV_DEFAULT_WSL_DISTRO_LOCATION = "DEFAULT_WSL_DISTRO_LOCATION" // If set to 1, the default WSL distro storage will be used.

ENV_CONTAINER = "container"
ENV_CONTAINER_MODE = "CONTAINER_MODE" // running in docker container
)

// TerminusGlobalEnvs holds a group of general environment variables
Expand Down
8 changes: 6 additions & 2 deletions pkg/common/kube_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package common
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"net"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/pkg/errors"
"github.com/spf13/pflag"

kubekeyapiv1alpha2 "bytetrade.io/web3os/installer/apis/kubekey/v1alpha2"
kubekeyclientset "bytetrade.io/web3os/installer/clients/clientset/versioned"
"bytetrade.io/web3os/installer/pkg/core/common"
Expand Down Expand Up @@ -120,6 +121,8 @@ type Argument struct {
HostIP string `json:"host_ip"`

CudaVersion string `json:"cuda_version"`

IsOlaresInContainer bool `json:"is_olares_in_container"`
}

type MasterHostConfig struct {
Expand Down Expand Up @@ -241,6 +244,7 @@ func NewArgument() *Argument {
}
arg.IsCloudInstance, _ = strconv.ParseBool(os.Getenv(ENV_TERMINUS_IS_CLOUD_VERSION))
arg.PublicNetworkInfo.PubliclyAccessible, _ = strconv.ParseBool(os.Getenv(ENV_PUBLICLY_ACCESSIBLE))
arg.IsOlaresInContainer = os.Getenv("CONTAINER_MODE") == "oic"
return arg
}

Expand Down
192 changes: 95 additions & 97 deletions pkg/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"
"time"

kubekeyapiv1alpha2 "bytetrade.io/web3os/installer/apis/kubekey/v1alpha2"
"bytetrade.io/web3os/installer/pkg/common"
Expand Down Expand Up @@ -130,101 +128,101 @@ func (images *Images) PullImages(runtime connector.Runtime, kubeConf *common.Kub
return nil
}

type LocalImage struct {
Filename string
}

type LocalImages []LocalImage

func (i LocalImages) LoadImages(runtime connector.Runtime, kubeConf *common.KubeConf) error {
loadCmd := "docker"
host := runtime.RemoteHost()
retry := func(f func() error, times int) (err error) {
for i := 0; i < times; i++ {
err = f()
if err == nil {
return nil
}
var dur = 5 + (i+1)*10
logger.Warnf("load image %s failed, wait for %d seconds(%d times)", err, dur, i+1)
if (i + 1) < times {
time.Sleep(time.Duration(dur) * time.Second)
}
}

return
}

for _, image := range i {
switch {
case host.IsRole(common.Master):
// logger.Debugf("%s preloading image: %s", host.GetName(), image.Filename)
start := time.Now()
fileName := filepath.Base(image.Filename)
// fileName = strings.ReplaceAll(fileName, ".gz", "")
// fmt.Println(">>> ", fileName, HasSuffixI(image.Filename, ".tar.gz", ".tgz"))
if HasSuffixI(image.Filename, ".tar.gz", ".tgz") {
switch kubeConf.Cluster.Kubernetes.ContainerManager {
case "crio":
loadCmd = "ctr" // BUG
case "containerd":
loadCmd = "ctr -n k8s.io images import -"
case "isula":
loadCmd = "isula"
default:
loadCmd = "docker load"
}

// continue if load image error
if err := retry(func() error {
logger.Infof("preloading image: %s", fileName)
if stdout, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("env PATH=$PATH gunzip -c %s | %s", image.Filename, loadCmd), false, false); err != nil {
return fmt.Errorf("%s", fileName)
} else {
logger.Infof("%s in %s\n", formatLoadImageRes(stdout, fileName), time.Since(start))
// fmt.Printf("%s in %s\n", formatLoadImageRes(stdout, fileName), time.Since(start))
}
return nil
}, 5); err != nil {
return fmt.Errorf("%s", fileName)
}
} else if HasSuffixI(image.Filename, ".tar") {
switch kubeConf.Cluster.Kubernetes.ContainerManager {
case "crio":
loadCmd = "ctr" // BUG
case "containerd":
loadCmd = "ctr -n k8s.io images import"
case "isula":
loadCmd = "isula"
default:
loadCmd = "docker load -i"
}

if err := retry(func() error {
logger.Infof("preloading image: %s", fileName)
if stdout, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("env PATH=$PATH %s %s", loadCmd, image.Filename), false, false); err != nil {
return fmt.Errorf("%s", fileName)
} else {
logger.Infof("%s in %s\n", formatLoadImageRes(stdout, fileName), time.Since(start))
// fmt.Printf("%s in %s\n", formatLoadImageRes(stdout, fileName), time.Since(start))
}

return nil
}, 5); err != nil {
return fmt.Errorf("%s", fileName)
}
} else {
logger.Warnf("invalid image file name %s, skip ...", image.Filename)
return nil
}
default:
continue
}

}
return nil

}
// type LocalImage struct {
// Filename string
// }

// type LocalImages []LocalImage

// func (i LocalImages) LoadImages(runtime connector.Runtime, kubeConf *common.KubeConf) error {
// loadCmd := "docker"
// host := runtime.RemoteHost()
// retry := func(f func() error, times int) (err error) {
// for i := 0; i < times; i++ {
// err = f()
// if err == nil {
// return nil
// }
// var dur = 5 + (i+1)*10
// logger.Warnf("load image %s failed, wait for %d seconds(%d times)", err, dur, i+1)
// if (i + 1) < times {
// time.Sleep(time.Duration(dur) * time.Second)
// }
// }

// return
// }

// for _, image := range i {
// switch {
// case host.IsRole(common.Master):
// // logger.Debugf("%s preloading image: %s", host.GetName(), image.Filename)
// start := time.Now()
// fileName := filepath.Base(image.Filename)
// // fileName = strings.ReplaceAll(fileName, ".gz", "")
// // fmt.Println(">>> ", fileName, HasSuffixI(image.Filename, ".tar.gz", ".tgz"))
// if HasSuffixI(image.Filename, ".tar.gz", ".tgz") {
// switch kubeConf.Cluster.Kubernetes.ContainerManager {
// case "crio":
// loadCmd = "ctr" // BUG
// case "containerd":
// loadCmd = "ctr -n k8s.io images import -"
// case "isula":
// loadCmd = "isula"
// default:
// loadCmd = "docker load"
// }

// // continue if load image error
// if err := retry(func() error {
// logger.Infof("preloading image: %s", fileName)
// if stdout, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("env PATH=$PATH gunzip -c %s | %s", image.Filename, loadCmd), false, false); err != nil {
// return fmt.Errorf("%s", fileName)
// } else {
// logger.Infof("%s in %s\n", formatLoadImageRes(stdout, fileName), time.Since(start))
// // fmt.Printf("%s in %s\n", formatLoadImageRes(stdout, fileName), time.Since(start))
// }
// return nil
// }, 5); err != nil {
// return fmt.Errorf("%s", fileName)
// }
// } else if HasSuffixI(image.Filename, ".tar") {
// switch kubeConf.Cluster.Kubernetes.ContainerManager {
// case "crio":
// loadCmd = "ctr" // BUG
// case "containerd":
// loadCmd = "ctr -n k8s.io images import"
// case "isula":
// loadCmd = "isula"
// default:
// loadCmd = "docker load -i"
// }

// if err := retry(func() error {
// logger.Infof("preloading image: %s", fileName)
// if stdout, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("env PATH=$PATH %s %s", loadCmd, image.Filename), false, false); err != nil {
// return fmt.Errorf("%s", fileName)
// } else {
// logger.Infof("%s in %s\n", formatLoadImageRes(stdout, fileName), time.Since(start))
// // fmt.Printf("%s in %s\n", formatLoadImageRes(stdout, fileName), time.Since(start))
// }

// return nil
// }, 5); err != nil {
// return fmt.Errorf("%s", fileName)
// }
// } else {
// logger.Warnf("invalid image file name %s, skip ...", image.Filename)
// return nil
// }
// default:
// continue
// }

// }
// return nil

// }

func formatLoadImageRes(str string, fileName string) string {
if strings.Contains(str, "(sha256:") {
Expand Down
9 changes: 7 additions & 2 deletions pkg/images/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ func (t *LoadImages) Execute(runtime connector.Runtime) (reserr error) {
var loadCmd string
var loadParm string

if runtime.GetSystemInfo().GetFsType() == "zfs" {
loadParm = "--snapshotter=zfs"
// unused
// if runtime.GetSystemInfo().GetFsType() == "zfs" {
// loadParm = "--snapshotter=zfs"
// }

if t.KubeConf.Arg.IsOlaresInContainer {
loadParm = "--no-unpack"
}

if runtime.RemoteHost().GetOs() == common.Darwin {
Expand Down
Loading
Loading