init code

This commit is contained in:
PatHoo
2020-03-23 17:34:34 +08:00
parent d5abe087c6
commit f58ba22f75
3 changed files with 30 additions and 4 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ func init() {
initCmd.Flags().StringVar(&install.VIP, "vip", "10.103.97.2", "virtual ip")
initCmd.Flags().StringSliceVar(&install.MasterIPs, "master", []string{}, "kubernetes multi-masters ex. 192.168.0.2-192.168.0.4")
initCmd.Flags().StringSliceVar(&install.NodeIPs, "node", []string{}, "kubernetes multi-nodes ex. 192.168.0.5-192.168.0.5")
initCmd.Flags().StringVar(&install.PkgUrl, "pkg-url", "", "http://store.lameleg.com/kube1.14.1.tar.gz download offline package url, or file localtion ex. /root/kube1.14.1.tar.gz")
initCmd.Flags().StringVar(&install.PkgUrl, "pkg-url", "", "http://store.lameleg.com/kube1.14.1.tar.gz download offline package url, or file location ex. /root/kube1.14.1.tar.gz")
initCmd.Flags().StringVar(&install.Version, "version", "v1.14.1", "version is kubernetes version")
initCmd.Flags().StringVar(&install.Repo, "repo", "k8s.gcr.io", "choose a container registry to pull control plane images from")
initCmd.Flags().StringVar(&install.PodCIDR, "podcidr", "100.64.0.0/10", "Specify range of IP addresses for the pod network")
+26
View File
@@ -1,9 +1,12 @@
package install
import (
"bytes"
"fmt"
"github.com/wonderivan/logger"
"golang.org/x/crypto/ssh"
"os"
"strings"
)
//CheckValid is
@@ -28,6 +31,7 @@ func (s *SealosInstaller) CheckValid() {
}
var session *ssh.Session
var errors []error
var hostname []string
for _, h := range s.Hosts {
session, err := SSHConfig.Connect(h)
if err != nil {
@@ -35,10 +39,24 @@ func (s *SealosInstaller) CheckValid() {
logger.Error("[%s] ------------ error[%s]", h, err)
errors = append(errors, err)
} else {
//check hostname
var stdOut, stdErr bytes.Buffer
session.Stdout = &stdOut
session.Stderr = &stdErr
session.Run("hostname")
ret := strings.Replace( stdOut.String(), "\n", "", -1 )
fmt.Printf("%s\n", ret)
hostname=append(hostname,ret)
logger.Crit("[%s] ------------ check ok", h)
logger.Crit("[%s] ------------ session[%p]", h, session)
}
}
fmt.Println(hostname[0])
fmt.Println(hostname[1])
fmt.Println(hostname[2])
fmt.Println(hostname[3])
defer func() {
if session != nil {
session.Close()
@@ -48,4 +66,12 @@ func (s *SealosInstaller) CheckValid() {
logger.Error("has some linux server is connection ssh is failed")
os.Exit(1)
}
os.Exit(1)
}
func InSlice (arr []string, val string) bool{
for _, v := range arr {
if v == val { return true }
}
return false
}
+3 -3
View File
@@ -92,7 +92,7 @@ func (c *SealConfig) Load(path string) {
err = yaml.Unmarshal(y, c)
if err != nil {
logger.Error("unmarsha config file failed: %s", err)
logger.Error("unmarshal config file failed: %s", err)
}
MasterIPs = c.Masters
@@ -118,7 +118,7 @@ func Load(path string, content interface{}) error {
err = yaml.Unmarshal(y, content)
if err != nil {
logger.Error("unmarsha config file failed: %s", err)
logger.Error("unmarshal config file failed: %s", err)
}
return nil
}
@@ -139,7 +139,7 @@ func (c *SealConfig) showDefaultConfig() {
y, err := yaml.Marshal(c)
if err != nil {
logger.Error("marsha config file failed: %s", err)
logger.Error("marshal config file failed: %s", err)
}
logger.Info("\n\n%s\n\n", string(y))