diff --git a/.drone.yml b/.drone.yml index c7451a1826a..24dac2e6387 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,7 +10,7 @@ workspace: steps: - name: build - image: golang:1.11.3 + image: golang:1.12 commands: - go build -o sealos diff --git a/go.sum b/go.sum index fc63cb2937b..8e415a347a3 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,11 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -25,6 +27,7 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.0 h1:DGA1KlA9esU6WcicH+P8PxFZOl15O6GYtab1cIJdOlE= github.com/pkg/sftp v1.10.0/go.mod h1:NxmoDg/QLVWluQDUYG7XBZTLUpKeFa8e3aMf1BfjyHk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= @@ -39,6 +42,7 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/wonderivan/logger v1.0.0 h1:Z6Nz+3SNcizolx3ARH11axdD4DXjFpb2J+ziGUVlv/U= @@ -55,6 +59,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/install/init.go b/install/init.go index af4c0c2570a..474a67ccb67 100644 --- a/install/init.go +++ b/install/init.go @@ -56,7 +56,7 @@ func (s *SealosInstaller) InstallMaster0() { cmd := fmt.Sprintf("echo %s apiserver.cluster.local >> /etc/hosts", IpFormat(Masters[0])) Cmd(Masters[0], cmd) - cmd = `kubeadm init --config=/root/kubeadm-config.yaml --experimental-upload-certs` + cmd = s.Command(Version, InitMaster) output := Cmd(Masters[0], cmd) decodeOutput(output) diff --git a/install/join.go b/install/join.go index 56a83196b1d..f4dceb49913 100644 --- a/install/join.go +++ b/install/join.go @@ -25,8 +25,7 @@ func (s *SealosInstaller) GeneratorToken() { //JoinMasters is func (s *SealosInstaller) JoinMasters() { - cmd := fmt.Sprintf("kubeadm join %s:6443 --token %s --discovery-token-ca-cert-hash %s --experimental-control-plane --certificate-key %s", IpFormat(Masters[0]), JoinToken, TokenCaCertHash, CertificateKey) - + cmd := s.Command(Version, JoinMaster) for _, master := range Masters[1:] { cmdHosts := fmt.Sprintf("echo %s apiserver.cluster.local >> /etc/hosts", IpFormat(Masters[0])) Cmd(master, cmdHosts) @@ -50,7 +49,7 @@ func (s *SealosInstaller) JoinNodes() { defer wg.Done() cmdHosts := fmt.Sprintf("echo %s apiserver.cluster.local >> /etc/hosts", VIP) Cmd(node, cmdHosts) - cmd := fmt.Sprintf("kubeadm join %s:6443 --token %s --discovery-token-ca-cert-hash %s", VIP, JoinToken, TokenCaCertHash) + cmd := s.Command(Version, JoinNode) cmd += masters Cmd(node, cmd) }(node) diff --git a/install/sealos.go b/install/sealos.go index f464a80c673..baac02fdf15 100644 --- a/install/sealos.go +++ b/install/sealos.go @@ -42,25 +42,26 @@ type SealosInstaller struct { Hosts []string } -const ( - initMaster0 = "init-master0" - initMasters = "init-masters" -) +type CommandType string -//getCommand("init-master0") -//getCommand("masters") -//getCommand("join") -//get command by versions -func (s *SealosInstaller) getCommand(name string) (cmd string) { - cmds := make(map[string]string) - cmds = map[string]string{ - initMaster0: `kubeadm init --config=/root/kubeadm-config.yaml --experimental-upload-certs`, - initMasters: fmt.Sprintf("kubeadm join %s:6443 --token %s --discovery-token-ca-cert-hash %s --experimental-control-plane --certificate-key %s", IpFormat(Masters[0]), JoinToken, TokenCaCertHash, CertificateKey), - } +//command type +const InitMaster CommandType = "initMaster" +const JoinMaster CommandType = "joinMaster" +const JoinNode CommandType = "joinNode" - if strings.HasPrefix(Version, "v1.15") { - cmds[initMaster0] = `kubeadm init --config=/root/kubeadm-config.yaml --upload-certs` +func (s *SealosInstaller) Command(version string, name CommandType) (cmd string) { + cmds := make(map[CommandType]string) + cmds = map[CommandType]string{ + InitMaster: `kubeadm init --config=/root/kubeadm-config.yaml --experimental-upload-certs`, + JoinMaster: fmt.Sprintf("kubeadm join %s:6443 --token %s --discovery-token-ca-cert-hash %s --experimental-control-plane --certificate-key %s", IpFormat(Masters[0]), JoinToken, TokenCaCertHash, CertificateKey), + JoinNode: fmt.Sprintf("kubeadm join %s:6443 --token %s --discovery-token-ca-cert-hash %s", VIP, JoinToken, TokenCaCertHash), } + //other version + //todo + if VersionToInt(version) >= 115 { + cmds[InitMaster] = `kubeadm init --config=/root/kubeadm-config.yaml --upload-certs` + } + v, ok := cmds[name] defer func() { if r := recover(); r != nil { diff --git a/install/utils.go b/install/utils.go index 528bea7ce83..fd792dba9e2 100644 --- a/install/utils.go +++ b/install/utils.go @@ -21,6 +21,20 @@ import ( const oneMBByte = 1024 * 1024 +// v1.15.6 => 115 +func VersionToInt(version string) int { + // v1.15.6 => 1.15.6 + version = strings.Replace(version, "v", "", -1) + versionArr := strings.Split(version, ".") + if len(versionArr) >= 2 { + versionStr := versionArr[0] + versionArr[1] + if i, err := strconv.Atoi(versionStr); err == nil { + return i + } + } + return 0 +} + func IpFormat(host string) string { ipAndPort := strings.Split(host, ":") return ipAndPort[0] diff --git a/install/utils_test.go b/install/utils_test.go index bd18a01f86f..24560b58c4c 100644 --- a/install/utils_test.go +++ b/install/utils_test.go @@ -70,3 +70,7 @@ func TestPrint(t *testing.T) { func TestGetFileSize(t *testing.T) { GetFileSize("httfp://www.affa.com") } + +func TestVersionToInt(t *testing.T) { + t.Log(VersionToInt("v1.15.6")) +}