mirror of
https://github.com/labring/sealos.git
synced 2026-10-24 01:38:59 +08:00
修复echo yaml str的时候未知命令
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// return sealos cert command
|
||||
func CertCMD(altNames []string, hostIP, hostName, serviceCIRD , DNSDomain string) string {
|
||||
func CertCMD(altNames []string, hostIP, hostName, serviceCIRD, DNSDomain string) string {
|
||||
cmd := fmt.Sprintf("sealos cert --node-ip %s --node-name %s --service-cird %s --dns-domain %s", hostIP, hostName, serviceCIRD, DNSDomain)
|
||||
for _, name := range altNames {
|
||||
cmd += fmt.Sprintf(" --alt-names %s", name)
|
||||
|
||||
+2
-2
@@ -164,7 +164,7 @@ const (
|
||||
)
|
||||
|
||||
// apiServerIPAndDomains = MasterIP + VIP + CertSANS 暂时只有apiserver, 记得把cluster.local后缀加到apiServerIPAndDOmas里先
|
||||
func NewSealosCertMetaData(certPATH, certEtcdPATH string, apiServerIPAndDomains []string, SvcCIDR, nodeName, nodeIP,DNSDomain string) (*SealosCertMetaData, error) {
|
||||
func NewSealosCertMetaData(certPATH, certEtcdPATH string, apiServerIPAndDomains []string, SvcCIDR, nodeName, nodeIP, DNSDomain string) (*SealosCertMetaData, error) {
|
||||
data := &SealosCertMetaData{}
|
||||
data.CertPath = certPATH
|
||||
data.CertEtcdPath = certEtcdPATH
|
||||
@@ -194,7 +194,7 @@ func (meta *SealosCertMetaData) apiServerAltName(certList *[]Config) {
|
||||
(*certList)[APIserverCert].AltNames.DNSNames = append((*certList)[APIserverCert].AltNames.DNSNames,
|
||||
meta.APIServer.DNSNames...)
|
||||
(*certList)[APIserverCert].AltNames.DNSNames = append((*certList)[APIserverCert].AltNames.DNSNames,
|
||||
meta.NodeName, fmt.Sprintf("kubernetes.default.svc.%s",meta.DNSDomain))
|
||||
meta.NodeName, fmt.Sprintf("kubernetes.default.svc.%s", meta.DNSDomain))
|
||||
(*certList)[APIserverCert].AltNames.IPs = append((*certList)[APIserverCert].AltNames.IPs,
|
||||
meta.APIServer.IPs...)
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ var certCmd = &cobra.Command{
|
||||
Short: "generate certs",
|
||||
Long: `you can specify expire time`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cert.GenerateCert(config.CertPath, config.CertEtcdPath, config.AltNames, config.NodeIP, config.NodeName, config.ServiceCIRD,config.DNSDomain)
|
||||
cert.GenerateCert(config.CertPath, config.CertEtcdPath, config.AltNames, config.NodeIP, config.NodeName, config.ServiceCIRD, config.DNSDomain)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -74,8 +74,8 @@ func (s *SealosInstaller) KubeadmConfigInstall() {
|
||||
}
|
||||
|
||||
func getDefaultSANs() []string {
|
||||
var sans=[]string{"127.0.0.1","apiserver.cluster.local",VIP}
|
||||
for _,master := range MasterIPs {
|
||||
var sans = []string{"127.0.0.1", "apiserver.cluster.local", VIP}
|
||||
for _, master := range MasterIPs {
|
||||
sans = append(sans, IpFormat(master))
|
||||
}
|
||||
return sans
|
||||
|
||||
+10
-8
@@ -98,7 +98,7 @@ func (s *SealosInstaller) JoinMasters(masters []string) {
|
||||
_ = SSHConfig.CmdAsync(master, cmdHosts)
|
||||
copyk8sConf := `mkdir -p /root/.kube && cp -i /etc/kubernetes/admin.conf /root/.kube/config`
|
||||
_ = SSHConfig.CmdAsync(master, copyk8sConf)
|
||||
cleaninstall := `rm -rf /root/kube`
|
||||
cleaninstall := `rm -rf /root/kube || :`
|
||||
_ = SSHConfig.CmdAsync(master, cleaninstall)
|
||||
}(master)
|
||||
}
|
||||
@@ -125,7 +125,8 @@ func (s *SealosInstaller) JoinNodes() {
|
||||
//create lvscare static pod
|
||||
yaml := ipvs.LvsStaticPodYaml(VIP, MasterIPs, "")
|
||||
_ = SSHConfig.CmdAsync(node, cmd)
|
||||
_ = SSHConfig.CmdAsync(node, fmt.Sprintf("mkdir -p /etc/kubernetes/manifests && echo '%s' > /etc/kubernetes/manifests/kube-sealyun-lvscare.yaml", yaml))
|
||||
_ = SSHConfig.Cmd(node, "mkdir -p /etc/kubernetes/manifests")
|
||||
SSHConfig.Copy(node, "/etc/kubernetes/manifests/kube-sealyun-lvscare.yaml", []byte(yaml))
|
||||
|
||||
cleaninstall := `rm -rf /root/kube`
|
||||
_ = SSHConfig.CmdAsync(node, cleaninstall)
|
||||
@@ -142,8 +143,8 @@ func (s *SealosInstaller) lvscare() {
|
||||
go func(node string) {
|
||||
defer wg.Done()
|
||||
yaml := ipvs.LvsStaticPodYaml(VIP, MasterIPs, "")
|
||||
_ = SSHConfig.CmdAsync(node, "rm -rf /etc/kubernetes/manifests/kube-sealyun-lvscare*")
|
||||
_ = SSHConfig.CmdAsync(node, fmt.Sprintf("mkdir -p /etc/kubernetes/manifests && echo '%s' > /etc/kubernetes/manifests/kube-sealyun-lvscare.yaml", yaml))
|
||||
_ = SSHConfig.Cmd(node, "rm -rf /etc/kubernetes/manifests/kube-sealyun-lvscare* || :")
|
||||
SSHConfig.Copy(node, "/etc/kubernetes/manifests/kube-sealyun-lvscare.yaml", []byte(yaml))
|
||||
}(node)
|
||||
}
|
||||
|
||||
@@ -156,14 +157,15 @@ func (s *SealosInstaller) sendCaAndKey(hosts []string) {
|
||||
SendPackage(CertPath+"/sa.key", hosts, cert.KubeDefaultCertPath, nil, nil)
|
||||
SendPackage(CertPath+"/sa.pub", hosts, cert.KubeDefaultCertPath, nil, nil)
|
||||
for _, ca := range caConfigs {
|
||||
SendPackage(path.Join(ca.Path,ca.BaseName+".key"), hosts, ca.DefaultPath, nil, nil)
|
||||
SendPackage(path.Join(ca.Path,ca.BaseName+".crt"), hosts, ca.DefaultPath, nil, nil)
|
||||
SendPackage(path.Join(ca.Path, ca.BaseName+".key"), hosts, ca.DefaultPath, nil, nil)
|
||||
SendPackage(path.Join(ca.Path, ca.BaseName+".crt"), hosts, ca.DefaultPath, nil, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SealosInstaller) sendCerts(hosts []string) {
|
||||
certConfigs := cert.CertList(CertPath, CertEtcdPath)
|
||||
for _, cert := range certConfigs {
|
||||
SendPackage(path.Join(cert.Path,cert.BaseName+".key"), hosts, cert.DefaultPath, nil, nil)
|
||||
SendPackage(path.Join(cert.Path,cert.BaseName+".crt"), hosts, cert.DefaultPath, nil, nil)
|
||||
SendPackage(path.Join(cert.Path, cert.BaseName+".key"), hosts, cert.DefaultPath, nil, nil)
|
||||
SendPackage(path.Join(cert.Path, cert.BaseName+".crt"), hosts, cert.DefaultPath, nil, nil)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -91,27 +91,27 @@ func TestDecodeIPs(t *testing.T) {
|
||||
{
|
||||
"test decode ips",
|
||||
args{[]string{"192.168.0.1-192.168.0.3"}},
|
||||
[]string{"192.168.0.1:22","192.168.0.2:22","192.168.0.3:22"},
|
||||
[]string{"192.168.0.1:22", "192.168.0.2:22", "192.168.0.3:22"},
|
||||
},
|
||||
{
|
||||
"test decode ips",
|
||||
args{[]string{"192.168.0.1","192.168.0.3:23"}},
|
||||
[]string{"192.168.0.1:22","192.168.0.3:23"},
|
||||
args{[]string{"192.168.0.1", "192.168.0.3:23"}},
|
||||
[]string{"192.168.0.1:22", "192.168.0.3:23"},
|
||||
},
|
||||
{
|
||||
"test decode ips",
|
||||
args{[]string{"192.168.0.1-192.168.0.3:23","192.168.0.5"}},
|
||||
[]string{"192.168.0.1:23","192.168.0.2:23","192.168.0.3:23","192.168.0.5:22"},
|
||||
args{[]string{"192.168.0.1-192.168.0.3:23", "192.168.0.5"}},
|
||||
[]string{"192.168.0.1:23", "192.168.0.2:23", "192.168.0.3:23", "192.168.0.5:22"},
|
||||
},
|
||||
{
|
||||
"test decode ips",
|
||||
args{[]string{"192.168.0.1:24","192.168.0.3"}},
|
||||
[]string{"192.168.0.1:24","192.168.0.3:22"},
|
||||
args{[]string{"192.168.0.1:24", "192.168.0.3"}},
|
||||
[]string{"192.168.0.1:24", "192.168.0.3:22"},
|
||||
},
|
||||
{
|
||||
"test decode ips",
|
||||
args{[]string{"192.168.0.1-192.168.0.3","192.168.0.4-192.168.0.6:25", "192.168.0.7:25","192.168.0.8"}},
|
||||
[]string{"192.168.0.1:22","192.168.0.2:22","192.168.0.3:22","192.168.0.4:25","192.168.0.5:25","192.168.0.6:25","192.168.0.7:25","192.168.0.8:22"},
|
||||
args{[]string{"192.168.0.1-192.168.0.3", "192.168.0.4-192.168.0.6:25", "192.168.0.7:25", "192.168.0.8"}},
|
||||
[]string{"192.168.0.1:22", "192.168.0.2:22", "192.168.0.3:22", "192.168.0.4:25", "192.168.0.5:25", "192.168.0.6:25", "192.168.0.7:25", "192.168.0.8:22"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -121,4 +121,4 @@ func TestDecodeIPs(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-7
@@ -6,22 +6,21 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CALICO = "calico"
|
||||
FLANNEL = "flannel"
|
||||
CALICO = "calico"
|
||||
FLANNEL = "flannel"
|
||||
defaultInterface = "eth.*|en.*"
|
||||
defaultCIDR = "100.64.0.0/10"
|
||||
defaultCIDR = "100.64.0.0/10"
|
||||
)
|
||||
|
||||
type MetaData struct {
|
||||
Interface string
|
||||
CIDR string
|
||||
// ipip mode for calico.yml
|
||||
IPIP bool
|
||||
IPIP bool
|
||||
// MTU size
|
||||
MTU string
|
||||
}
|
||||
|
||||
|
||||
// Net is CNI interface
|
||||
type Net interface {
|
||||
// if template is "" using default template
|
||||
@@ -30,7 +29,6 @@ type Net interface {
|
||||
Template() string
|
||||
}
|
||||
|
||||
|
||||
func NewNetwork(t string, metadata MetaData) Net {
|
||||
switch t {
|
||||
case CALICO:
|
||||
@@ -45,6 +43,6 @@ func NewNetwork(t string, metadata MetaData) Net {
|
||||
func render(data MetaData, temp string) string {
|
||||
var b bytes.Buffer
|
||||
t := template.Must(template.New("net").Parse(temp))
|
||||
t.Execute(&b,&data)
|
||||
t.Execute(&b, &data)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
+4
-4
@@ -7,10 +7,10 @@ import (
|
||||
|
||||
func TestNewNetwork(t *testing.T) {
|
||||
netyaml := NewNetwork("calico", MetaData{
|
||||
Interface:"en.*|eth.*",
|
||||
CIDR:"10.1.1.1/24",
|
||||
IPIP: true,
|
||||
MTU: "1440",
|
||||
Interface: "en.*|eth.*",
|
||||
CIDR: "10.1.1.1/24",
|
||||
IPIP: true,
|
||||
MTU: "1440",
|
||||
}).Manifests("")
|
||||
fmt.Println(netyaml)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
/**
|
||||
这里主要是做连接ssh操作的
|
||||
*/
|
||||
func (ss *SSH) Connect(host string) (*ssh.Session, error) {
|
||||
func (ss *SSH) connect(host string) (*ssh.Client, error) {
|
||||
auth := []ssh.AuthMethod{ss.sshAuthMethod(ss.Password, ss.PkFile)}
|
||||
config := ssh.Config{
|
||||
Ciphers: []string{"aes128-ctr", "aes192-ctr", "aes256-ctr", "aes128-gcm@openssh.com", "arcfour256", "arcfour128", "aes128-cbc", "3des-cbc", "aes192-cbc", "aes256-cbc"},
|
||||
@@ -34,7 +34,11 @@ func (ss *SSH) Connect(host string) (*ssh.Session, error) {
|
||||
}
|
||||
|
||||
addr := ss.addrReformat(host)
|
||||
client, err := ssh.Dial("tcp", addr, clientConfig)
|
||||
return ssh.Dial("tcp", addr, clientConfig)
|
||||
}
|
||||
|
||||
func (ss *SSH) Connect(host string) (*ssh.Session, error) {
|
||||
client, err := ss.connect(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+25
-10
@@ -1,11 +1,13 @@
|
||||
package sshutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/fanux/sealos/pkg/sshcmd/md5sum"
|
||||
"github.com/pkg/sftp"
|
||||
"github.com/wonderivan/logger"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -32,6 +34,7 @@ func (ss *SSH) CopyForMD5(host, localFilePath, remoteFilePath, md5 string) bool
|
||||
logger.Error("[ssh]md5 validate false")
|
||||
return false
|
||||
}
|
||||
|
||||
func (ss *SSH) Md5Sum(host, remoteFilePath string) string {
|
||||
cmd := fmt.Sprintf("md5sum %s | cut -d\" \" -f1", remoteFilePath)
|
||||
remoteMD5 := ss.CmdToString(host, cmd, "")
|
||||
@@ -39,7 +42,10 @@ func (ss *SSH) Md5Sum(host, remoteFilePath string) string {
|
||||
}
|
||||
|
||||
//Copy is
|
||||
func (ss *SSH) Copy(host, localFilePath, remoteFilePath string) {
|
||||
func (ss *SSH) Copy(host, remoteFilePath string, localFilePathOrBytes interface{}) {
|
||||
var (
|
||||
data io.Reader
|
||||
)
|
||||
sftpClient, err := ss.sftpConnect(host)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -50,16 +56,25 @@ func (ss *SSH) Copy(host, localFilePath, remoteFilePath string) {
|
||||
panic(1)
|
||||
}
|
||||
defer sftpClient.Close()
|
||||
srcFile, err := os.Open(localFilePath)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
logger.Error("[ssh][%s]scpCopy: %s", host, err)
|
||||
|
||||
switch v := localFilePathOrBytes.(type) {
|
||||
case string:
|
||||
srcFile, err := os.Open(v)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
logger.Error("[ssh][%s]scpCopy: %s", host, err)
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
panic(1)
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
panic(1)
|
||||
defer srcFile.Close()
|
||||
data = srcFile
|
||||
case []byte:
|
||||
data = bytes.NewReader(v)
|
||||
default:
|
||||
panic("must use path or []bytes")
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
dstFile, err := sftpClient.Create(remoteFilePath)
|
||||
defer func() {
|
||||
@@ -74,7 +89,7 @@ func (ss *SSH) Copy(host, localFilePath, remoteFilePath string) {
|
||||
buf := make([]byte, 100*oneMBByte) //100mb
|
||||
totalMB := 0
|
||||
for {
|
||||
n, _ := srcFile.Read(buf)
|
||||
n, _ := data.Read(buf)
|
||||
if n == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
+4
-4
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
Version = "latest"
|
||||
Build = ""
|
||||
VersionStr = fmt.Sprintf("sealos version %v, build %v %v", Version, Build, runtime.Version())
|
||||
)
|
||||
Version = "latest"
|
||||
Build = ""
|
||||
VersionStr = fmt.Sprintf("sealos version %v, build %v %v", Version, Build, runtime.Version())
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user