update parameters' type

Signed-off-by: pixiake <guofeng@yunify.com>
This commit is contained in:
pixiake 2020-10-13 14:48:42 +08:00
parent b15562c2aa
commit df7e503672
11 changed files with 45 additions and 47 deletions

View File

@ -104,7 +104,7 @@ type HostCfg struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Address string `yaml:"address,omitempty" json:"address,omitempty"`
InternalAddress string `yaml:"internalAddress,omitempty" json:"internalAddress,omitempty"`
Port string `yaml:"port,omitempty" json:"port,omitempty"`
Port int `yaml:"port,omitempty" json:"port,omitempty"`
User string `yaml:"user,omitempty" json:"user,omitempty"`
Password string `yaml:"password,omitempty" json:"password,omitempty"`
PrivateKey string `yaml:"privateKey,omitempty" json:"privateKey,omitempty"`
@ -134,7 +134,7 @@ type HostGroups struct {
type ControlPlaneEndpoint struct {
Domain string `yaml:"domain" json:"domain,omitempty"`
Address string `yaml:"address" json:"address,omitempty"`
Port string `yaml:"port" json:"port,omitempty"`
Port int `yaml:"port" json:"port,omitempty"`
}
type RegistryConfig struct {

View File

@ -24,8 +24,8 @@ import (
const (
DefaultPreDir = "kubekey"
DefaultSSHPort = "22"
DefaultLBPort = "6443"
DefaultSSHPort = 22
DefaultLBPort = 6443
DefaultLBDomain = "lb.kubesphere.local"
DefaultNetworkPlugin = "calico"
DefaultPodsCIDR = "10.233.64.0/18"
@ -41,11 +41,11 @@ const (
DefaultCniVersion = "v0.8.6"
DefaultCiliumVersion = "v1.8.3"
DefaultHelmVersion = "v3.2.1"
DefaultMaxPods = "110"
DefaultNodeCidrMaskSize = "24"
DefaultMaxPods = 110
DefaultNodeCidrMaskSize = 24
DefaultIPIPMode = "Always"
DefaultVXLANMode = "Never"
DefaultVethMTU = "1440"
DefaultVethMTU = 1440
DefaultBackendMode = "vxlan"
DefaultProxyMode = "ipvs"
Etcd = "etcd"
@ -53,8 +53,8 @@ const (
Worker = "worker"
K8s = "k8s"
DefaultEtcdBackupDir = "/var/backups/kube_etcd"
DefaultEtcdBackupPeriod = "30"
DefaultKeepBackNumber = "5"
DefaultEtcdBackupPeriod = 30
DefaultKeepBackNumber = 5
DefaultEtcdBackupScriptDir = "/usr/local/bin/kube-scripts"
)
@ -82,10 +82,10 @@ func (cfg *ClusterSpec) SetDefaultClusterSpec() (*ClusterSpec, *HostGroups, erro
if cfg.Kubernetes.Version == "" {
clusterCfg.Kubernetes.Version = DefaultKubeVersion
}
if cfg.Kubernetes.MaxPods == "" {
if cfg.Kubernetes.MaxPods == 0 {
clusterCfg.Kubernetes.MaxPods = DefaultMaxPods
}
if cfg.Kubernetes.NodeCidrMaskSize == "" {
if cfg.Kubernetes.NodeCidrMaskSize == 0 {
clusterCfg.Kubernetes.NodeCidrMaskSize = DefaultNodeCidrMaskSize
}
if cfg.Kubernetes.ProxyMode == "" {
@ -109,7 +109,7 @@ func SetDefaultHostsCfg(cfg *ClusterSpec) []HostCfg {
if host.User == "" {
host.User = "root"
}
if host.Port == "" {
if host.Port == 0 {
host.Port = DefaultSSHPort
}
if host.PrivateKey == "" {
@ -137,7 +137,7 @@ func SetDefaultLBCfg(cfg *ClusterSpec, masterGroup []HostCfg) ControlPlaneEndpoi
if cfg.ControlPlaneEndpoint.Domain == "" {
cfg.ControlPlaneEndpoint.Domain = DefaultLBDomain
}
if cfg.ControlPlaneEndpoint.Port == "" {
if cfg.ControlPlaneEndpoint.Port == 0 {
cfg.ControlPlaneEndpoint.Port = DefaultLBPort
}
defaultLbCfg := cfg.ControlPlaneEndpoint
@ -160,7 +160,7 @@ func SetDefaultNetworkCfg(cfg *ClusterSpec) NetworkConfig {
if cfg.Network.Calico.VXLANMode == "" {
cfg.Network.Calico.VXLANMode = DefaultVXLANMode
}
if cfg.Network.Calico.VethMTU == "" {
if cfg.Network.Calico.VethMTU == 0 {
cfg.Network.Calico.VethMTU = DefaultVethMTU
}
if cfg.Network.Flannel.BackendMode == "" {
@ -184,10 +184,10 @@ func SetDefaultClusterCfg(cfg *ClusterSpec) Kubernetes {
if cfg.Kubernetes.EtcdBackupDir == "" {
cfg.Kubernetes.EtcdBackupDir = DefaultEtcdBackupDir
}
if cfg.Kubernetes.EtcdBackupPeriod == "" {
if cfg.Kubernetes.EtcdBackupPeriod == 0 {
cfg.Kubernetes.EtcdBackupPeriod = DefaultEtcdBackupPeriod
}
if cfg.Kubernetes.KeepBackupNumber == "" {
if cfg.Kubernetes.KeepBackupNumber == 0 {
cfg.Kubernetes.KeepBackupNumber = DefaultKeepBackNumber
}
if cfg.Kubernetes.EtcdBackupScriptDir == "" {

View File

@ -21,12 +21,12 @@ type Kubernetes struct {
ImageRepo string `yaml:"imageRepo" json:"imageRepo,omitempty"`
ClusterName string `yaml:"clusterName" json:"clusterName,omitempty"`
MasqueradeAll bool `yaml:"masqueradeAll" json:"masqueradeAll,omitempty"`
MaxPods string `yaml:"maxPods" json:"maxPods,omitempty"`
NodeCidrMaskSize string `yaml:"nodeCidrMaskSize" json:"nodeCidrMaskSize,omitempty"`
MaxPods int `yaml:"maxPods" json:"maxPods,omitempty"`
NodeCidrMaskSize int `yaml:"nodeCidrMaskSize" json:"nodeCidrMaskSize,omitempty"`
ApiserverCertExtraSans []string `yaml:"apiserverCertExtraSans" json:"apiserverCertExtraSans,omitempty"`
ProxyMode string `yaml:"proxyMode" json:"proxyMode,omitempty"`
EtcdBackupDir string `yaml:"etcdBackupDir" json:"etcdBackupDir,omitempty"`
EtcdBackupPeriod string `yaml:"etcdBackupPeriod" json:"etcdBackupPeriod,omitempty"`
KeepBackupNumber string `yaml:"keepBackupNumber" json:"keepBackupNumber,omitempty"`
EtcdBackupPeriod int `yaml:"etcdBackupPeriod" json:"etcdBackupPeriod,omitempty"`
KeepBackupNumber int `yaml:"keepBackupNumber" json:"keepBackupNumber,omitempty"`
EtcdBackupScriptDir string `yaml:"etcdBackupScript" json:"etcdBackupScript,omitempty"`
}

View File

@ -27,7 +27,7 @@ type NetworkConfig struct {
type CalicoCfg struct {
IPIPMode string `yaml:"ipipMode" json:"ipipMode,omitempty"`
VXLANMode string `yaml:"vxlanMode" json:"vxlanMode,omitempty"`
VethMTU string `yaml:"vethMTU" json:"vethMTU,omitempty"`
VethMTU int `yaml:"vethMTU" json:"vethMTU,omitempty"`
}
type FlannelCfg struct {

View File

@ -83,7 +83,7 @@ spec:
domain:
type: string
port:
type: string
type: integer
type: object
hosts:
description: Foo is an example field of Cluster. Edit Cluster_types.go
@ -101,7 +101,7 @@ spec:
password:
type: string
port:
type: string
type: integer
privateKey:
type: string
privateKeyPath:
@ -121,19 +121,19 @@ spec:
etcdBackupDir:
type: string
etcdBackupPeriod:
type: string
type: integer
etcdBackupScript:
type: string
imageRepo:
type: string
keepBackupNumber:
type: string
type: integer
masqueradeAll:
type: boolean
maxPods:
type: string
type: integer
nodeCidrMaskSize:
type: string
type: integer
proxyMode:
type: string
version:
@ -155,7 +155,7 @@ spec:
ipipMode:
type: string
vethMTU:
type: string
type: integer
vxlanMode:
type: string
type: object

View File

@ -88,7 +88,7 @@ spec:
domain:
type: string
port:
type: string
type: integer
type: object
hosts:
description: Foo is an example field of Cluster. Edit Cluster_types.go
@ -106,7 +106,7 @@ spec:
password:
type: string
port:
type: string
type: integer
privateKey:
type: string
privateKeyPath:
@ -126,19 +126,19 @@ spec:
etcdBackupDir:
type: string
etcdBackupPeriod:
type: string
type: integer
etcdBackupScript:
type: string
imageRepo:
type: string
keepBackupNumber:
type: string
type: integer
masqueradeAll:
type: boolean
maxPods:
type: string
type: integer
nodeCidrMaskSize:
type: string
type: integer
proxyMode:
type: string
version:
@ -160,7 +160,7 @@ spec:
ipipMode:
type: string
vethMTU:
type: string
type: integer
vxlanMode:
type: string
type: object

View File

@ -1,12 +1,12 @@
package tmpl
import (
"errors"
"fmt"
kubekeyapiv1alpha1 "github.com/kubesphere/kubekey/api/v1alpha1"
"github.com/kubesphere/kubekey/pkg/util"
"github.com/kubesphere/kubekey/pkg/util/manager"
"github.com/lithammer/dedent"
"os"
"strconv"
"strings"
"text/template"
@ -68,15 +68,14 @@ func EtcdBackupScript(mgr *manager.Manager, node *kubekeyapiv1alpha1.HostCfg) (s
for _, host := range mgr.EtcdNodes {
ips = append(ips, fmt.Sprintf("https://%s:2379", host.InternalAddress))
}
if mgr.Cluster.Kubernetes.EtcdBackupPeriod != "" {
period, _ := strconv.Atoi(mgr.Cluster.Kubernetes.EtcdBackupPeriod)
if mgr.Cluster.Kubernetes.EtcdBackupPeriod != 0 {
period := mgr.Cluster.Kubernetes.EtcdBackupPeriod
if period > 60 && period < 1440 {
mgr.Cluster.Kubernetes.EtcdBackupPeriod = strconv.Itoa(period % 60)
mgr.Cluster.Kubernetes.EtcdBackupPeriod = period % 60
etcdBackupHour = strconv.Itoa(period / 60)
}
if period > 1440 {
fmt.Println("Etcd backup cannot last more than one day, Please change it to within one day.")
os.Exit(0)
return "", errors.New("Etcd backup cannot last more than one day, Please change it to within one day.")
}
}

View File

@ -194,7 +194,7 @@ func GenerateKubeadmCfg(mgr *manager.Manager) (string, error) {
"CorednsTag": preinstall.GetImage(mgr, "coredns").Tag,
"Version": mgr.Cluster.Kubernetes.Version,
"ClusterName": mgr.Cluster.Kubernetes.ClusterName,
"ControlPlaneEndpoint": fmt.Sprintf("%s:%s", mgr.Cluster.ControlPlaneEndpoint.Domain, mgr.Cluster.ControlPlaneEndpoint.Port),
"ControlPlaneEndpoint": fmt.Sprintf("%s:%d", mgr.Cluster.ControlPlaneEndpoint.Domain, mgr.Cluster.ControlPlaneEndpoint.Port),
"PodSubnet": mgr.Cluster.Network.KubePodsCIDR,
"ServiceSubnet": mgr.Cluster.Network.KubeServiceCIDR,
"CertSANs": mgr.Cluster.GenerateCertSANs(),

View File

@ -152,7 +152,7 @@ func AllinoneCfg(user *user.User, k8sVersion, ksVersion string, ksEnabled bool,
Name: hostname,
Address: util.LocalIP(),
InternalAddress: util.LocalIP(),
Port: "",
Port: kubekeyapiv1alpha1.DefaultSSHPort,
User: user.Name,
Password: "",
PrivateKeyPath: fmt.Sprintf("%s/.ssh/id_rsa", user.HomeDir),

View File

@ -24,7 +24,7 @@ import (
"text/template"
)
var calicoTemplNew *template.Template = template.Must(template.New("calico").Parse(
var calicoTemplNew = template.Must(template.New("calico").Parse(
dedent.Dedent(`---
# Source: calico/templates/calico-config.yaml
# This ConfigMap is used to configure a self-hosted Calico installation.

View File

@ -18,7 +18,6 @@ package ssh
import (
kubekeyapiv1alpha1 "github.com/kubesphere/kubekey/api/v1alpha1"
"strconv"
"sync"
"time"
)
@ -41,10 +40,10 @@ func (dialer *Dialer) Connect(host kubekeyapiv1alpha1.HostCfg) (Connection, erro
defer dialer.lock.Unlock()
conn, _ := dialer.connections[host.ID]
port, _ := strconv.Atoi(host.Port)
opts := Cfg{
Username: host.User,
Port: port,
Port: host.Port,
Address: host.Address,
Password: host.Password,
PrivateKey: host.PrivateKey,