Skip to content

Commit

Permalink
fix: wsl update not responding (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
aby913 authored Jan 21, 2025
1 parent 28bc5dc commit f5b2408
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 95 deletions.
93 changes: 47 additions & 46 deletions apis/kubekey/v1alpha2/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,53 @@ import (
)

const (
DefaultPreDir = "kubekey"
DefaultTmpDir = "/tmp/kubekey"
DefaultSSHPort = 22
DefaultLBPort = 6443
DefaultApiserverPort = 6443
DefaultLBDomain = "lb.kubesphere.local"
DefaultNetworkPlugin = "calico"
DefaultPodsCIDR = "10.233.64.0/18"
DefaultServiceCIDR = "10.233.0.0/18"
DefaultKubeImageNamespace = "kubesphere"
DefaultClusterName = "cluster.local"
DefaultDNSDomain = "cluster.local"
DefaultArch = "amd64"
DefaultSSHTimeout = 30
DefaultEtcdVersion = "v3.4.13"
DefaultEtcdPort = "2379"
DefaultDockerVersion = "20.10.8"
DefaultContainerdVersion = "1.6.4"
DefaultRuncVersion = "v1.1.1"
DefaultRuncVersion_v_1_1_4 = "v1.1.4"
DefaultCrictlVersion = "v1.24.0"
DefaultKubeVersion = "v1.23.10"
DefaultCalicoVersion = "v3.23.2"
DefaultFlannelVersion = "v0.12.0"
DefaultCniVersion = "v0.9.1"
DefaultCniVersion_v_1_1_1 = "v1.1.1"
DefaultCiliumVersion = "v1.11.6"
DefaultKubeovnVersion = "v1.10.6"
DefalutMultusVersion = "v3.8"
DefaultHelmVersion = "v3.9.0"
DefaultDockerComposeVersion = "v2.2.2"
DefaultRegistryVersion = "2"
DefaultHarborVersion = "v2.5.3"
DefaultUbuntu24AppArmonVersion = "4.0.1"
DefaultSocatVersion = "1.7.3.4"
DefaultFlexVersion = "2.6.4"
DefaultConntrackVersion = "1.4.1"
DefaultOssUtilVersion = "v1.7.18"
DefaultCosUtilVersion = "v1.0.2"
DefaultMinioVersion = "RELEASE.2023-05-04T21-44-30Z"
DefaultMinioOperatorVersion = "0.0.1"
DefaultRedisVersion = "5.0.14"
DefaultJuiceFsVersion = "v11.1.0"
CudaKeyringVersion1_0 = "1.0"
CudaKeyringVersion1_1 = "1.1"
DefaultVeleroVersion = "v1.11.3"
DefaultPreDir = "kubekey"
DefaultTmpDir = "/tmp/kubekey"
DefaultSSHPort = 22
DefaultLBPort = 6443
DefaultApiserverPort = 6443
DefaultLBDomain = "lb.kubesphere.local"
DefaultNetworkPlugin = "calico"
DefaultPodsCIDR = "10.233.64.0/18"
DefaultServiceCIDR = "10.233.0.0/18"
DefaultKubeImageNamespace = "kubesphere"
DefaultClusterName = "cluster.local"
DefaultDNSDomain = "cluster.local"
DefaultArch = "amd64"
DefaultSSHTimeout = 30
DefaultEtcdVersion = "v3.4.13"
DefaultEtcdPort = "2379"
DefaultDockerVersion = "20.10.8"
DefaultContainerdVersion = "1.6.4"
DefaultRuncVersion = "v1.1.1"
DefaultRuncVersion_v_1_1_4 = "v1.1.4"
DefaultCrictlVersion = "v1.24.0"
DefaultKubeVersion = "v1.23.10"
DefaultCalicoVersion = "v3.23.2"
DefaultFlannelVersion = "v0.12.0"
DefaultCniVersion = "v0.9.1"
DefaultCniVersion_v_1_1_1 = "v1.1.1"
DefaultCiliumVersion = "v1.11.6"
DefaultKubeovnVersion = "v1.10.6"
DefalutMultusVersion = "v3.8"
DefaultHelmVersion = "v3.9.0"
DefaultDockerComposeVersion = "v2.2.2"
DefaultRegistryVersion = "2"
DefaultHarborVersion = "v2.5.3"
DefaultUbuntu24AppArmonVersion = "4.0.1"
DefaultSocatVersion = "1.7.3.4"
DefaultFlexVersion = "2.6.4"
DefaultConntrackVersion = "1.4.1"
DefaultOssUtilVersion = "v1.7.18"
DefaultCosUtilVersion = "v1.0.2"
DefaultMinioVersion = "RELEASE.2023-05-04T21-44-30Z"
DefaultMinioOperatorVersion = "0.0.1"
DefaultRedisVersion = "5.0.14"
DefaultJuiceFsVersion = "v11.1.0"
CudaKeyringVersion1_0 = "1.0"
CudaKeyringVersion1_1 = "1.1"
DefaultVeleroVersion = "v1.11.3"
DefaultWSLInstallPackageVersion = "2.3.26.0"

DefaultMaxPods = 200
DefaultPodPidsLimit = 10000
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ require (
github.com/pelletier/go-toml v1.9.5
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.6
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d
github.com/schollz/progressbar/v3 v3.17.1
github.com/shirou/gopsutil/v4 v4.24.5
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA=
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
github.com/schollz/progressbar/v3 v3.17.1 h1:bI1MTaoQO+v5kzklBjYNRQLoVpe0zbyRZNK6DFkVC5U=
github.com/schollz/progressbar/v3 v3.17.1/go.mod h1:RzqpnsPQNjUyIgdglUjRLgD7sVnxN1wpmBMV+UiEbL4=
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
Expand Down
4 changes: 3 additions & 1 deletion pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ const (
Harbor = "harbor"
DockerCompose = "compose"

KubeBinaries = "KubeBinaries"
KubeBinaries = "KubeBinaries"
WslBinaries = "WslBinaries"
WslUbuntuBinaries = "WslUbuntuBinaries"

RootDir = "/"
TmpDir = "/tmp/kubekey"
Expand Down
25 changes: 23 additions & 2 deletions pkg/files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package files
import (
"context"
"fmt"
"github.com/schollz/progressbar/v3"
"io"
"math"
"net/http"
Expand All @@ -30,6 +29,8 @@ import (
"strings"
"time"

"github.com/schollz/progressbar/v3"

cm "bytetrade.io/web3os/installer/pkg/common"
"bytetrade.io/web3os/installer/pkg/core/common"
"bytetrade.io/web3os/installer/pkg/core/logger"
Expand Down Expand Up @@ -77,6 +78,7 @@ const (
installwizard = "install-wizard"
fullinstaller = "full-installer"
wsl = "wsl"
wslpackage = "wslpackage"
)

// KubeBinary Type field const
Expand Down Expand Up @@ -355,7 +357,18 @@ func NewKubeBinary(name, arch, osType, osVersion, osPlatformFamily, version, pre
component.Type = common.WSL
component.FileName = fmt.Sprintf("Ubuntu%s.appx", version)
component.Md5sum = FileSha256[wsl][arch][version]
component.Url = fmt.Sprintf(WslImageUrl, common.DownloadUrl, component.Md5sum)
component.Url = fmt.Sprintf(WslImageUrl, downloadMirrors, component.Md5sum)
component.BaseDir = filepath.Join(prePath)
case wslpackage:
component.Type = common.WSL
component.FileName = fmt.Sprintf("wsl.%s.%s.msi", version, arch)
component.Md5sum = FileSha256[wslpackage][arch][version]
switch arch {
case cm.Arm, cm.Arm7, cm.Armv7l, cm.Armhf, cm.Arm64:
component.Url = fmt.Sprintf("%s/arm64/%s", downloadMirrors, component.Md5sum)
default:
component.Url = fmt.Sprintf("%s/%s", downloadMirrors, component.Md5sum)
}
component.BaseDir = filepath.Join(prePath)
default:
logger.Fatalf("unsupported kube binaries %s", name)
Expand Down Expand Up @@ -1042,6 +1055,14 @@ var (
"2204": "2d4f98ae9e7f1921722da620ef72b643",
},
},
wslpackage: {
amd64: {
"2.3.26.0": "52602b40e5b2179defc8d4aaced3d3ab",
},
arm64: {
"2.3.26.0": "ba7ca1bf304c5940de93b6202425c511",
},
},
}
)

Expand Down
90 changes: 90 additions & 0 deletions pkg/utils/charset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package utils

import (
"bytes"
"io/ioutil"

"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
)

const (
CharsetWindows1252 = "windows-1252"
CharsetISO88591 = "ISO-8859-1"
CharsetGB18030 = "GB-18030"
)

type GB18030 struct {
data []byte
}

func (c *GB18030) Utf8() (string, error) {
decoder := simplifiedchinese.GB18030.NewDecoder()
unicodeData, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(c.data), decoder))
if err != nil {
return string(c.data), err
}

return string(unicodeData), nil
}

type Windows1252 struct {
data []byte
}

func (c *Windows1252) Utf8() (string, error) {
decoder := unicode.UTF16(unicode.LittleEndian, unicode.UseBOM).NewDecoder()
unicodeData, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(c.data), decoder))
if err != nil {
return string(c.data), err
}

return string(unicodeData), nil
}

func (c *Windows1252) Gb2312() (string, error) {
decoder := charmap.Windows1252.NewDecoder()
unicodeData, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(c.data), decoder))

encoder := simplifiedchinese.GB18030.NewEncoder()
gb2312Data, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(unicodeData), encoder))
if err != nil {
return string(c.data), err
}

return string(gb2312Data), nil
}

type ISO8859 struct {
data []byte
}

func (c *ISO8859) Utf8() (string, error) {
decoder := charmap.ISO8859_1.NewDecoder()
utf8Data, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(c.data), decoder))
if err != nil {
return string(c.data), err
}

return string(utf8Data), nil
}

func CharsetConverts(charset string, data []byte, c Charset) (string, error) {
switch {
case c == DEFAULT:
switch charset {
case CharsetWindows1252, CharsetISO88591:
return (&Windows1252{data: data}).Utf8()
// case CharsetISO88591:
// return (&ISO8859{data: data}).Utf8()
case CharsetGB18030:
return (&GB18030{data: data}).Utf8()
default:
return string(data), nil
}
default:
return string(data), nil
}
}
17 changes: 7 additions & 10 deletions pkg/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"bytetrade.io/web3os/installer/pkg/core/logger"
"github.com/pkg/errors"
"github.com/saintfish/chardet"
utilexec "k8s.io/utils/exec"
)

Expand All @@ -18,6 +19,7 @@ type Charset string
const (
DEFAULT Charset = "DEFAULT"
GBK Charset = "GBK"
UTF8 Charset = "UTF8"
UTF16 Charset = "UTF16"
)

Expand Down Expand Up @@ -113,21 +115,16 @@ func (command *CommandExecutor) runcmd(charset Charset) (string, error) {
var exec = utilexec.New()

output, err := exec.Command(command.name, command.cmd...).Output()
switch charset {
case UTF16:
res = Utf16ToUtf8(output)
case GBK:
tmp, _ := GbkToUtf8(output)
res = string(tmp)
default:
res = string(output)
}
detector := chardet.NewTextDetector()
result, _ := detector.DetectBest(output)
res, _ = CharsetConverts(result.Charset, output, charset)

if err != nil {
logger.Debugf("[exec] CMD: %s, CHARSET: %s, OUTPUT: %s, error: %v", fmt.Sprintf("%s %v", command.name, command.cmd), result.Charset, res, err)
return res, err
}

logger.Debugf("[exec] CMD: %s, OUTPUT: %s", fmt.Sprintf("%s %v", command.name, command.cmd), res)
logger.Debugf("[exec] CMD: %s, CHARSET: %s, OUTPUT: %s", fmt.Sprintf("%s %v", command.name, command.cmd), result.Charset, res)
return res, nil
}

Expand Down
20 changes: 18 additions & 2 deletions pkg/windows/modules.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package windows

import (
"time"

"bytetrade.io/web3os/installer/pkg/common"
"bytetrade.io/web3os/installer/pkg/core/task"
)
Expand All @@ -13,8 +15,20 @@ func (u *InstallWSLModule) Init() {
u.Name = "InstallWSL"

downloadAppxPackage := &task.LocalTask{
Name: "InitAppxPackage",
Action: &AddAppxPackage{},
Name: "DownloadAppxPackage",
Action: &DownloadAppxPackage{},
}

installAppxPackage := &task.LocalTask{
Name: "InstallAppxPackage",
Action: &InstallAppxPackage{},
Retry: 2,
Delay: 5 * time.Second,
}

downloadWslPackage := &task.LocalTask{
Name: "DownloadWslInstallPackage",
Action: &DownloadWSLInstallPackage{},
}

updateWSL := &task.LocalTask{
Expand All @@ -24,6 +38,8 @@ func (u *InstallWSLModule) Init() {

u.Tasks = []task.Interface{
downloadAppxPackage,
installAppxPackage,
downloadWslPackage,
updateWSL,
}
}
Expand Down
Loading

0 comments on commit f5b2408

Please sign in to comment.