Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/download-path'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/core/action/template.go
  • Loading branch information
aby913 committed Sep 22, 2024
2 parents 31b9a02 + 99afbcf commit 1411da2
Show file tree
Hide file tree
Showing 56 changed files with 594 additions and 613 deletions.
4 changes: 2 additions & 2 deletions cmd/ctl/info/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func NewCmdInfo() *cobra.Command {
infoCmd := &cobra.Command{
Use: "info",
Short: "Terminus install, uninstall or restore",
Short: "Print system information, etc.",
}
infoCmd.AddCommand(showInfoCommand())

Expand All @@ -20,7 +20,7 @@ func NewCmdInfo() *cobra.Command {
func showInfoCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "show",
Short: "Install Terminus",
Short: "Print system information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf(`OS_TYPE=%s
OS_PLATFORM=%s
Expand Down
3 changes: 2 additions & 1 deletion cmd/ctl/options/cli_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (o *CliKubeInitializeOptions) AddFlags(cmd *cobra.Command) {

type CliTerminusUninstallOptions struct {
MiniKube bool
Version string
BaseDir string
All bool
Phase string
Expand All @@ -37,10 +38,10 @@ func NewCliTerminusUninstallOptions() *CliTerminusUninstallOptions {

func (o *CliTerminusUninstallOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(&o.MiniKube, "minikube", false, "Set minikube flag")
cmd.Flags().StringVar(&o.Version, "version", "", "Set install-wizard version, e.g., 1.7.0, 1.7.0-rc.1, 1.8.0-20240813")
cmd.Flags().StringVar(&o.BaseDir, "base-dir", "", "Set uninstall package base dir , default value $HOME/.terminus")
cmd.Flags().BoolVar(&o.All, "all", false, "Uninstall terminus")
cmd.Flags().StringVar(&o.Phase, "phase", cluster.PhaseInstall.String(), "Uninstall from a specified phase and revert to the previous one. For example, using --phase install will remove the tasks performed in the 'install' phase, effectively returning the system to the 'prepare' state.")

cmd.Flags().BoolVar(&o.Quiet, "quiet", false, "Quiet mode, default: false")
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/ctl/options/download_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
type CliDownloadWizardOptions struct {
Version string
KubeType string
Md5sum string
BaseDir string
}

Expand All @@ -17,7 +16,6 @@ func NewCliDownloadWizardOptions() *CliDownloadWizardOptions {

func (o *CliDownloadWizardOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.Version, "version", "", "Set install-wizard version, e.g., 1.7.0, 1.7.0-rc.1, 1.8.0-20240813")
cmd.Flags().StringVar(&o.Md5sum, "md5sum", "", "Set install-wizard package md5 sum")
cmd.Flags().StringVar(&o.BaseDir, "base-dir", "", "Set download package base dir , default value $HOME/.terminus")
cmd.Flags().StringVar(&o.KubeType, "kube", "k3s", "Set kube type, e.g., k3s or k8s")
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/ctl/os/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import (
func NewCmdOs() *cobra.Command {
rootOsCmd := &cobra.Command{
Use: "terminus",
Short: "Terminus install, uninstall or restore",
Short: "Operations such as installing and uninstalling Terminus can be performed using the --phase parameter, which allows for actions like downloading installation packages, downloading dependencies, and installing Terminus.",
}

_ = exec.Command("/bin/bash", "-c", "ulimit -u 65535").Run()
_ = exec.Command("/bin/bash", "-c", "ulimit -n 65535").Run()

rootOsCmd.AddCommand(NewCmdInstallOs())
rootOsCmd.AddCommand(NewCmdInitializeOs())
rootOsCmd.AddCommand(NewCmdUninstallOs())
rootOsCmd.AddCommand(NewCmdPrepare())
rootOsCmd.AddCommand(NewCmdDownloadWizard())
rootOsCmd.AddCommand(NewCmdDownload())
rootOsCmd.AddCommand(NewCmdCheckDownload())
rootOsCmd.AddCommand(NewCmdPrepare())
rootOsCmd.AddCommand(NewCmdInstallOs())
rootOsCmd.AddCommand(NewCmdUninstallOs())
return rootOsCmd
}
2 changes: 1 addition & 1 deletion pkg/binaries/prepares.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (p *Ubuntu24AppArmorCheck) PreCheck(runtime connector.Runtime) (bool, error
}

cmd := "apparmor_parser --version"
stdout, err := runtime.GetRunner().SudoCmd(cmd, false, true)
stdout, err := runtime.GetRunner().Host.SudoCmd(cmd, false, true)
if err != nil {
logger.Errorf("check apparmor version error %v", err)
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/binaries/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (t *InstallAppArmorTask) Execute(runtime connector.Runtime) error {
logger.Fatal("failed to download apparmor: %v", err)
}

if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("dpkg -i %s", fileName), false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd(fmt.Sprintf("dpkg -i %s", fileName), false, true); err != nil {
logger.Errorf("failed to install apparmor: %v", err)
return err
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/bootstrap/patch/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type EnableSSHTask struct {
}

func (t *EnableSSHTask) Execute(runtime connector.Runtime) error {
stdout, _ := runtime.GetRunner().SudoCmdExt("systemctl is-active ssh", false, false)
stdout, _ := runtime.GetRunner().Host.SudoCmd("systemctl is-active ssh", false, false)
if stdout != "active" {
if _, err := runtime.GetRunner().SudoCmdExt("systemctl enable --now ssh", false, false); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd("systemctl enable --now ssh", false, false); err != nil {
return err
}
}
Expand All @@ -48,12 +48,12 @@ func (t *PatchTask) Execute(runtime connector.Runtime) error {
switch constants.OsPlatform {
case common.Ubuntu, common.Debian, common.Raspbian:
if !t.KubeConf.Arg.IsProxmox() && !t.KubeConf.Arg.IsRaspbian() {
if _, err := runtime.GetRunner().SudoCmd("add-apt-repository universe multiverse -y", false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd("add-apt-repository universe multiverse -y", false, true); err != nil {
logger.Errorf("add os repo error %v", err)
return err
}

if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("%s update -qq", constants.PkgManager), false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd(fmt.Sprintf("%s update -qq", constants.PkgManager), false, true); err != nil {
logger.Errorf("update os error %v", err)
return err
}
Expand All @@ -66,13 +66,13 @@ func (t *PatchTask) Execute(runtime connector.Runtime) error {
// return err
// }

if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("%s install -y -qq %s", constants.PkgManager, pre_reqs), false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd(fmt.Sprintf("%s install -y -qq %s", constants.PkgManager, pre_reqs), false, true); err != nil {
logger.Errorf("install deps %s error %v", pre_reqs, err)
return err
}

var cmd = "conntrack socat apache2-utils ntpdate net-tools make gcc bison flex tree unzip"
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("%s %s install -y %s", debianFrontend, constants.PkgManager, cmd), false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd(fmt.Sprintf("%s %s install -y %s", debianFrontend, constants.PkgManager, cmd), false, true); err != nil {
logger.Errorf("install deps %s error %v", cmd, err)
return err
}
Expand All @@ -87,7 +87,7 @@ func (t *PatchTask) Execute(runtime connector.Runtime) error {
}
case common.CentOs, common.Fedora, common.RHEl:
cmd = "conntrack socat httpd-tools ntpdate net-tools make gcc openssh-server"
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("%s install -y %s", constants.PkgManager, cmd), false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd(fmt.Sprintf("%s install -y %s", constants.PkgManager, cmd), false, true); err != nil {
logger.Errorf("install deps %s error %v", cmd, err)
return err
}
Expand Down
38 changes: 19 additions & 19 deletions pkg/bootstrap/precheck/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (t *CorrectHostname) Execute(runtime connector.Runtime) error {
return nil
}
hostname := strings.ToLower(constants.HostName)
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("hostnamectl set-hostname %s", hostname), false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd(fmt.Sprintf("hostnamectl set-hostname %s", hostname), false, true); err != nil {
return err
}
constants.HostName = hostname
Expand All @@ -61,19 +61,19 @@ func (t *RaspbianCheckTask) Execute(runtime connector.Runtime) error {
// if util.IsExist(common.RaspbianCmdlineFile) || util.IsExist(common.RaspbianFirmwareFile) {
if constants.OsPlatform == common.Raspbian {
if _, err := util.GetCommand(common.CommandIptables); err != nil {
_, err = runtime.GetRunner().SudoCmd("apt install -y iptables", false, false)
_, err = runtime.GetRunner().Host.SudoCmd("apt install -y iptables", false, false)
if err != nil {
logger.Errorf("%s install iptables error %v", common.Raspbian, err)
return err
}

_, err = runtime.GetRunner().Cmd("systemctl disable --user gvfs-udisks2-volume-monitor", false, true)
_, err = runtime.GetRunner().Host.Cmd("systemctl disable --user gvfs-udisks2-volume-monitor", false, true)
if err != nil {
logger.Errorf("%s exec error %v", common.Raspbian, err)
return err
}

_, err = runtime.GetRunner().Cmd("systemctl stop --user gvfs-udisks2-volume-monitor", false, true)
_, err = runtime.GetRunner().Host.Cmd("systemctl stop --user gvfs-udisks2-volume-monitor", false, true)
if err != nil {
logger.Errorf("%s exec error %v", common.Raspbian, err)
return err
Expand All @@ -94,21 +94,21 @@ type DisableLocalDNSTask struct {
func (t *DisableLocalDNSTask) Execute(runtime connector.Runtime) error {
switch constants.OsPlatform {
case common.Ubuntu, common.Debian, common.Raspbian:
stdout, _ := runtime.GetRunner().SudoCmdExt("systemctl is-active systemd-resolved", false, false)
stdout, _ := runtime.GetRunner().Host.SudoCmd("systemctl is-active systemd-resolved", false, false)
if stdout != "active" {
_, _ = runtime.GetRunner().SudoCmdExt("systemctl stop systemd-resolved.service", false, true)
_, _ = runtime.GetRunner().SudoCmdExt("systemctl disable systemd-resolved.service", false, true)
_, _ = runtime.GetRunner().Host.SudoCmd("systemctl stop systemd-resolved.service", false, true)
_, _ = runtime.GetRunner().Host.SudoCmd("systemctl disable systemd-resolved.service", false, true)

if utils.IsExist("/usr/bin/systemd-resolve") {
_, _ = runtime.GetRunner().SudoCmd("mv /usr/bin/systemd-resolve /usr/bin/systemd-resolve.bak", false, true)
_, _ = runtime.GetRunner().Host.SudoCmd("mv /usr/bin/systemd-resolve /usr/bin/systemd-resolve.bak", false, true)
}
ok, err := utils.IsSymLink("/etc/resolv.conf")
if err != nil {
logger.Errorf("check /etc/resolv.conf error %v", err)
return err
}
if ok {
if _, err := runtime.GetRunner().SudoCmd("unlink /etc/resolv.conf && touch /etc/resolv.conf", false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd("unlink /etc/resolv.conf && touch /etc/resolv.conf", false, true); err != nil {
logger.Errorf("unlink /etc/resolv.conf error %v", err)
return err
}
Expand All @@ -119,15 +119,15 @@ func (t *DisableLocalDNSTask) Execute(runtime connector.Runtime) error {
return err
}
} else {
if _, err := runtime.GetRunner().SudoCmd("cat /etc/resolv.conf > /etc/resolv.conf.bak", false, true); err != nil {
if _, err := runtime.GetRunner().Host.SudoCmd("cat /etc/resolv.conf > /etc/resolv.conf.bak", false, true); err != nil {
logger.Errorf("backup /etc/resolv.conf error %v", err)
return err
}
}
}

if stdout, _ := runtime.GetRunner().SudoCmd("hostname -i &>/dev/null", false, true); stdout == "" {
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("echo %s %s >> /etc/hosts", constants.LocalIp, constants.HostName), false, true); err != nil {
if stdout, _ := runtime.GetRunner().Host.SudoCmd("hostname -i &>/dev/null", false, true); stdout == "" {
if _, err := runtime.GetRunner().Host.SudoCmd(fmt.Sprintf("echo %s %s >> /etc/hosts", constants.LocalIp, constants.HostName), false, true); err != nil {
return err
}
}
Expand Down Expand Up @@ -155,20 +155,20 @@ func ConfigResolvConf(runtime connector.Runtime) error {

if constants.CloudVendor == common.AliYun {
cmd = `echo "nameserver 100.100.2.136" > /etc/resolv.conf`
if _, err = runtime.GetRunner().SudoCmd(cmd, false, true); err != nil {
if _, err = runtime.GetRunner().Host.SudoCmd(cmd, false, true); err != nil {
logger.Errorf("exec %s error %v", cmd, err)
return err
}
}

cmd = `echo "nameserver 1.0.0.1" >> /etc/resolv.conf`
if _, err = runtime.GetRunner().SudoCmd(cmd, false, true); err != nil {
if _, err = runtime.GetRunner().Host.SudoCmd(cmd, false, true); err != nil {
logger.Errorf("exec %s error %v", cmd, err)
return err
}

cmd = `echo "nameserver 1.1.1.1" >> /etc/resolv.conf`
if _, err = runtime.GetRunner().SudoCmd(cmd, false, true); err != nil {
if _, err = runtime.GetRunner().Host.SudoCmd(cmd, false, true); err != nil {
logger.Errorf("exec %s error %v", cmd, err)
return err
}
Expand All @@ -188,7 +188,7 @@ func (t *GetSysInfoTask) Execute(runtime connector.Runtime) error {
logger.Infof("cpu info, model: %s, logical count: %d, physical count: %d",
constants.CpuModel, constants.CpuLogicalCount, constants.CpuPhysicalCount)
logger.Infof("disk info, total: %s, free: %s", utils.FormatBytes(int64(constants.DiskTotal)), utils.FormatBytes(int64(constants.DiskFree)))
logger.Info("fs info, fs: %s, zfsmount: %s", constants.FsType, constants.DefaultZfsPrefixName)
logger.Infof("fs info, fs: %s, zfsmount: %s", constants.FsType, constants.DefaultZfsPrefixName)
logger.Infof("mem info, total: %s, free: %s", utils.FormatBytes(int64(constants.MemTotal)), utils.FormatBytes(int64(constants.MemFree)))
logger.Infof("cgroup info, cpu: %d, mem: %d", constants.CgroupCpuEnabled, constants.CgroupMemoryEnabled)

Expand All @@ -200,7 +200,7 @@ type GreetingsTask struct {
}

func (h *GreetingsTask) Execute(runtime connector.Runtime) error {
_, err := runtime.GetRunner().CmdExt("echo 'Greetings, Terminus'", false, true)
_, err := runtime.GetRunner().Host.Cmd("echo 'Greetings, Terminus'", false, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func (n *NodePreCheck) Execute(runtime connector.Runtime) error {
cmd = connector.SudoPrefix(cmd)
}

res, err := runtime.GetRunner().CmdExt(cmd, false, false)
res, err := runtime.GetRunner().Host.CmdExt(cmd, false, false)
switch software {
case showmount:
software = nfs
Expand All @@ -258,7 +258,7 @@ func (n *NodePreCheck) Execute(runtime connector.Runtime) error {
}
}

output, err := runtime.GetRunner().CmdExt("date +\"%Z %H:%M:%S\"", false, false)
output, err := runtime.GetRunner().Host.CmdExt("date +\"%Z %H:%M:%S\"", false, false)
if err != nil {
results["time"] = ""
} else {
Expand Down
2 changes: 2 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
DefaultK3sVersion = "v1.22.16-k3s"
DefaultKubernetesVersion = ""
DefaultKubeSphereVersion = "v3.3.0"
DefaultTokenMaxAge = 1209600 // 14days
)

const (
Expand Down Expand Up @@ -235,4 +236,5 @@ const (
EnvStorageSecretKeyName = "AWS_SECRET_ACCESS_KEY_SETUP"
EnvStorageTokenName = "AWS_SESSION_TOKEN_SETUP"
EnvStorageClusterIdName = "CLUSTER_ID"
EnvTokenMaxAge = "TOKEN_MAX_AGE"
)
25 changes: 18 additions & 7 deletions pkg/common/kube_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"time"

kubekeyapiv1alpha2 "bytetrade.io/web3os/installer/apis/kubekey/v1alpha2"
kubekeyclientset "bytetrade.io/web3os/installer/clients/clientset/versioned"
Expand Down Expand Up @@ -93,7 +95,7 @@ type Argument struct {
GPU *GPU `json:"gpu"`
Cloudflare *Cloudflare `json:"cloudflare"`
Frp *Frp `json:"frp"`
TokenMaxAge int64 `json:"token_max_age"`
TokenMaxAge int64 `json:"token_max_age"` // nanosecond

Request any `json:"-"`

Expand All @@ -107,15 +109,15 @@ type Argument struct {
}

type AwsHost struct {
PublicIp string `json:"public_pi"`
Hostname string `json:"hostname"`
PublicIp string `json:"aws_public_ip"`
Hostname string `json:"aws_hostname"`
}

type User struct {
UserName string `json:"user_name"`
Password string `json:"password"`
Email string `json:"email"`
DomainName string `json:"domain_name"`
Password string `json:"user_password"`
Email string `json:"user_email"`
DomainName string `json:"user_domain_name"`
}

type Storage struct {
Expand Down Expand Up @@ -169,6 +171,15 @@ func NewArgument() *Argument {
}
}

func (a *Argument) SetTokenMaxAge() {
s := os.Getenv(EnvTokenMaxAge)
age, err := strconv.ParseInt(s, 10, 64)
if err != nil || age == 0 {
age = DefaultTokenMaxAge
}
a.TokenMaxAge = age * int64(time.Second)
}

func (a *Argument) SetGPU(enable bool, share bool) {
if a.GPU == nil {
a.GPU = new(GPU)
Expand Down Expand Up @@ -293,7 +304,7 @@ func NewKubeRuntime(flag string, arg Argument) (*KubeRuntime, error) {
return nil, err
}

base := connector.NewBaseRuntime(cluster.Name, connector.NewDialer(), arg.Debug, arg.IgnoreErr, arg.Provider, arg.BaseDir)
base := connector.NewBaseRuntime(cluster.Name, connector.NewDialer(), arg.Debug, arg.IgnoreErr, arg.Provider, arg.BaseDir, arg.TerminusVersion)

clusterSpec := &cluster.Spec
defaultCluster, roleGroups := clusterSpec.SetDefaultClusterSpec(arg.InCluster, arg.Minikube)
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/local_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewLocalRuntime(debug, ingoreErr bool) (LocalRuntime, error) {
if err != nil {
return localRuntime, err
}
base := connector.NewBaseRuntime(name, connector.NewDialer(), debug, ingoreErr, nil, "")
base := connector.NewBaseRuntime(name, connector.NewDialer(), debug, ingoreErr, nil, "", "")

host := connector.NewHost()
host.Name = name
Expand Down
Loading

0 comments on commit 1411da2

Please sign in to comment.