fixed to add cni config to show default yaml, add metadate to clare cni version

Signed-off-by: oldthreefeng <louisehong4168@gmail.com>
This commit is contained in:
oldthreefeng
2021-06-29 00:07:22 +08:00
parent 1fbc4a7766
commit 55381a33a8
5 changed files with 35 additions and 6 deletions
+2 -2
View File
@@ -49,7 +49,7 @@ to quickly create a Cobra application.`,
Interface: "interface=eth.*|en.*|em.*",
IPIP: true,
MTU: "1440",
K8sVersion: version,
Version: version,
}).Manifests("")
fmt.Println(yaml)
},
@@ -59,7 +59,7 @@ func init() {
rootCmd.AddCommand(cniCmd)
cniCmd.Flags().StringVarP(&cniType,"cni-type", "t", "calico", "print cni yaml")
cniCmd.Flags().StringVarP(&version,"version", "v", "", "k8s version to adpat the cni version like v1.21.0")
cniCmd.Flags().StringVarP(&version,"version", "v", "", "calico version")
// Here you will define your flags and configuration settings.
+18 -1
View File
@@ -2,6 +2,7 @@ package install
import (
"bufio"
"encoding/json"
"fmt"
"io"
"io/ioutil"
@@ -191,6 +192,22 @@ func (s *SealosInstaller) InstallMaster0() {
Interface = "interface=" + Interface
}
var cniVersion string
if SSHConfig.IsFileExist(s.Masters[0], "/root/kube/Metadata") {
var metajson []byte
var tmpdata metadata
SSHConfig.CopyConfigFile(s.Masters[0], "/root/kube/Metadata", metajson)
err := json.Unmarshal(metajson, &tmpdata)
if err != nil {
logger.Warn("get metadata version err: ", err)
} else {
cniVersion = tmpdata.CniVersion
Network = tmpdata.CniName
}
}
netyaml := net.NewNetwork(Network, net.MetaData{
Interface: Interface,
CIDR: PodCIDR,
@@ -198,7 +215,7 @@ func (s *SealosInstaller) InstallMaster0() {
MTU: MTU,
CniRepo: Repo,
K8sServiceHost: s.ApiServer,
K8sVersion: Version,
Version: cniVersion,
}).Manifests("")
cmd = fmt.Sprintf(`echo '%s' | kubectl apply -f -`, netyaml)
+6
View File
@@ -83,3 +83,9 @@ func vlogToStr() string {
str := strconv.Itoa(Vlog)
return " -v " + str
}
type metadata struct {
K8sVersion string `json:"k8sVersion"`
CniVersion string `json:"cniVersion"`
CniName string `json:"cniName"`
}
+8 -2
View File
@@ -19,14 +19,20 @@ func (c Calico) Manifests(template string) string {
c.metadata.CniRepo = "calico"
}
if c.metadata.Version == "" {
c.metadata.Version = "v3.8.2"
}
return render(c.metadata, template)
}
func (c Calico) Template() string {
if For121(c.metadata.K8sVersion) {
if c.metadata.Version == "v3.19.1" {
return CalicoV3191Manifests
} else if c.metadata.Version == "v3.8.2" {
return CalicoManifests
}
return CalicoManifests
return ""
}
const CalicoManifests = `
+1 -1
View File
@@ -29,7 +29,7 @@ type MetaData struct {
CniRepo string
K8sServiceHost string
K8sServicePort string
K8sVersion string
Version string
}
// Net is CNI interface