mirror of
https://github.com/labring/sealos.git
synced 2026-09-24 15:46:19 +08:00
fix kubeadm not found on old sealos package && fix port in exec cmd #469 && fix --service-cidr on old version && delete route cmd
This commit is contained in:
+2
-1
@@ -9,7 +9,8 @@ import (
|
||||
|
||||
// return sealos cert command
|
||||
func CertCMD(altNames []string, hostIP, hostName, serviceCIRD, DNSDomain string) string {
|
||||
cmd := "sealos cert "
|
||||
// avoid old version
|
||||
cmd := "/usr/sbin/sealos cert "
|
||||
if hostIP != "" {
|
||||
cmd += fmt.Sprintf(" --node-ip %s", hostIP)
|
||||
}
|
||||
|
||||
@@ -87,7 +87,6 @@ func init() {
|
||||
initCmd.Flags().StringVar(&install.PodCIDR, "podcidr", "100.64.0.0/10", "Specify range of IP addresses for the pod network")
|
||||
initCmd.Flags().StringVar(&install.SvcCIDR, "svccidr", "10.96.0.0/12", "Use alternative range of IP address for service VIPs")
|
||||
initCmd.Flags().StringVar(&install.Interface, "interface", "eth.*|en.*|em.*", "name of network interface")
|
||||
initCmd.Flags().StringVar(&install.Gateway, "gateway", "", "your host default route gateway when you have multi network interface")
|
||||
|
||||
initCmd.Flags().BoolVar(&install.WithoutCNI, "without-cni", false, "If true we not install cni plugin")
|
||||
initCmd.Flags().StringVar(&install.Network, "network", "calico", "cni plugin, calico..")
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/fanux/sealos/install"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// routeCmd represents the route command
|
||||
var routeCmd = &cobra.Command{
|
||||
Use: "route",
|
||||
Short: "set default route for host",
|
||||
Run: RouteCmdFunc,
|
||||
}
|
||||
|
||||
var (
|
||||
host string
|
||||
gatewayIp string
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(routeCmd)
|
||||
routeCmd.Flags().StringVar(&host, "host", "", "route host ip address for iFace")
|
||||
// manually to set gate for ip
|
||||
routeCmd.Flags().StringVar(&gatewayIp, "gateway", "", "default route gateway ip address")
|
||||
}
|
||||
|
||||
func RouteCmdFunc(cmd *cobra.Command, args []string) {
|
||||
r := install.GetRouteFlag(host, gatewayIp)
|
||||
r.SetRoute()
|
||||
}
|
||||
@@ -12,22 +12,6 @@ func SetHosts(hostip, hostName string) {
|
||||
SSHConfig.CmdAsync(hostip, cmd)
|
||||
}
|
||||
|
||||
func (s *SealosInstaller) CheckRoute() {
|
||||
var hosts []string
|
||||
hosts = append(hosts,s.Masters...)
|
||||
for _, host := range hosts {
|
||||
var cmd string
|
||||
if Gateway != "" {
|
||||
cmd = fmt.Sprintf("/usr/sbin/sealos route --host %s --gateway %s", IpFormat(host), Gateway)
|
||||
} else {
|
||||
cmd = fmt.Sprintf("/usr/sbin/sealos route --host %s ", IpFormat(host))
|
||||
}
|
||||
|
||||
SSHConfig.CmdAsync(host, cmd)
|
||||
// # check default route interface
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//CheckValid is
|
||||
func (s *SealosInstaller) CheckValid() {
|
||||
|
||||
@@ -174,4 +174,7 @@ func clean(host string) {
|
||||
//clean pki certs
|
||||
cmd = fmt.Sprint("rm -rf /etc/kubernetes/pki")
|
||||
_ = SSHConfig.CmdAsync(host, cmd)
|
||||
//clean sealos in /usr/sbin/
|
||||
cmd = fmt.Sprint("rm -rf /usr/sbin/sealos")
|
||||
_ = SSHConfig.CmdAsync(host, cmd)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/fanux/sealos/k8s"
|
||||
"github.com/wonderivan/logger"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -53,9 +54,27 @@ func GetExecFlag() *ExecFlag {
|
||||
logger.Error("get ips err: ", err)
|
||||
os.Exit(ErrorExitOSCase)
|
||||
}
|
||||
e.transToIps()
|
||||
return e
|
||||
}
|
||||
|
||||
// transToIps is trans ip to ip:port
|
||||
func (e *ExecFlag) transToIps() {
|
||||
var ips []string
|
||||
if !e.IsUseNode() {
|
||||
return
|
||||
}
|
||||
all := append(MasterIPs, NodeIPs...)
|
||||
for _, v := range all {
|
||||
for _, node := range e.ExecNode {
|
||||
if strings.Contains(v, node) {
|
||||
ips = append(ips, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
e.ExecNode = ips
|
||||
}
|
||||
|
||||
// IsUseLabeled return true when is labeled
|
||||
func (e *ExecFlag) IsUseLabeled() bool {
|
||||
return e.Label != ""
|
||||
|
||||
+1
-1
@@ -26,8 +26,8 @@ func BuildInit() {
|
||||
}
|
||||
i.CheckValid()
|
||||
i.Print()
|
||||
i.SendSealos()
|
||||
i.SendPackage()
|
||||
i.CheckRoute()
|
||||
i.Print("SendPackage")
|
||||
i.KubeadmConfigInstall()
|
||||
i.Print("SendPackage", "KubeadmConfigInstall")
|
||||
|
||||
@@ -30,6 +30,7 @@ func joinMastersFunc(joinMasters []string) {
|
||||
Nodes: nodes,
|
||||
}
|
||||
i.CheckValid()
|
||||
i.SendSealos()
|
||||
i.SendPackage()
|
||||
i.GeneratorCerts()
|
||||
i.JoinMasters(joinMasters)
|
||||
@@ -49,6 +50,7 @@ func joinNodesFunc(joinNodes []string) {
|
||||
Nodes: nodes,
|
||||
}
|
||||
i.CheckValid()
|
||||
i.SendSealos()
|
||||
i.SendPackage()
|
||||
i.GeneratorToken()
|
||||
i.JoinNodes()
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
package install
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fanux/sealos/k8s"
|
||||
"github.com/fanux/sealos/pkg/sshcmd/cmd"
|
||||
"github.com/wonderivan/logger"
|
||||
k8snet "k8s.io/apimachinery/pkg/util/net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type RouteFlags struct {
|
||||
Host string
|
||||
Gateway string
|
||||
}
|
||||
|
||||
func GetRouteFlag(host, gateway string) *RouteFlags {
|
||||
return &RouteFlags{
|
||||
Host: host,
|
||||
Gateway: gateway,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (r *RouteFlags) useHostSetRoute() bool {
|
||||
return k8s.IsIpv4(r.Host)
|
||||
}
|
||||
|
||||
func (r *RouteFlags) useGatewaySetRoute() bool {
|
||||
return k8s.IsIpv4(r.Gateway)
|
||||
}
|
||||
|
||||
func (r *RouteFlags) SetRoute() {
|
||||
if r.useGatewaySetRoute() {
|
||||
if isDefaultGateway(r.Gateway) {
|
||||
logger.Alert("%s is default route gateway, return", r.Gateway)
|
||||
return
|
||||
}
|
||||
setDefaultGateway(r.Gateway)
|
||||
logger.Alert("set default route gateway %s", r.Gateway)
|
||||
return
|
||||
}
|
||||
|
||||
if r.useHostSetRoute() {
|
||||
if isDefaultRoute(r.Host) {
|
||||
logger.Alert("%s is default route host, return", r.Host)
|
||||
return
|
||||
} else {
|
||||
changeDefaultByHost(r.Host)
|
||||
logger.Alert("set default route gateway by host %s", r.Host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// isDefaultGateway return true when ip is equal default route gateway
|
||||
func isDefaultGateway(ip string) bool {
|
||||
host, err := getDefaultRouteIp()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return ip == gateway(host)
|
||||
}
|
||||
|
||||
// setDefaultGateway by gateway
|
||||
func setDefaultGateway(ip string) {
|
||||
route := fmt.Sprintf("ip route del default && ip route add default via %s", ip)
|
||||
fmt.Println(route)
|
||||
cmd.Cmd("/bin/sh", "-c", route)
|
||||
}
|
||||
|
||||
// getDefaultRouteIp is get host ip by ChooseHostInterface() .
|
||||
func getDefaultRouteIp() (ip string, err error) {
|
||||
netIp, err := k8snet.ChooseHostInterface()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return netIp.String(), nil
|
||||
}
|
||||
|
||||
// isDefaultRoute return true if host equal default route ip host.
|
||||
func isDefaultRoute(host string) bool {
|
||||
ip, _ := getDefaultRouteIp()
|
||||
fmt.Printf("%s is default route ip\n", ip)
|
||||
return ip == host
|
||||
}
|
||||
|
||||
// changeDefaultByHost is set default route by host ip
|
||||
func changeDefaultByHost(host string) {
|
||||
ip := gateway(host)
|
||||
route := fmt.Sprintf("ip route del default && ip route add default via %s", ip)
|
||||
fmt.Println(route)
|
||||
cmd.Cmd("/bin/sh", "-c", route)
|
||||
}
|
||||
|
||||
// gateway return ipv4 gateway by Split ipv4.
|
||||
func gateway(host string) string {
|
||||
a := strings.Split(host, ".")
|
||||
return fmt.Sprintf("%s.%s.%s.1", a[0], a[1], a[2])
|
||||
}
|
||||
+7
-2
@@ -14,9 +14,14 @@ func (s *SealosInstaller) SendPackage() {
|
||||
kubeHook = kubeHook + " && " + deletekubectl + " && " + completion
|
||||
PkgUrl = SendPackage(PkgUrl, s.Hosts, "/root", nil, &kubeHook)
|
||||
|
||||
//send sealos
|
||||
|
||||
}
|
||||
|
||||
// SendSealos is send the exec sealos to /usr/sbin/sealos
|
||||
func (s *SealosInstaller) SendSealos() {
|
||||
// send sealos first to avoid old version
|
||||
sealos := FetchSealosAbsPath()
|
||||
beforeHook := "ps -ef |grep -v 'grep'|grep sealos >/dev/null || rm -rf /usr/bin/sealos"
|
||||
afterHook := "chmod a+x /usr/sbin/sealos"
|
||||
SendPackage(sealos, s.Hosts, "/usr/sbin", &beforeHook, &afterHook)
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,6 @@ var (
|
||||
WithoutCNI bool
|
||||
//network interface name, like "eth.*|en.*"
|
||||
Interface string
|
||||
Gateway string
|
||||
// the ipip mode of the calico
|
||||
IPIP bool
|
||||
// mtu size
|
||||
|
||||
Reference in New Issue
Block a user