diff --git a/cmd/kk/apis/kubekey/v1alpha2/network_types.go b/cmd/kk/apis/kubekey/v1alpha2/network_types.go index 727b4db81..d53fb770c 100644 --- a/cmd/kk/apis/kubekey/v1alpha2/network_types.go +++ b/cmd/kk/apis/kubekey/v1alpha2/network_types.go @@ -28,14 +28,24 @@ type NetworkConfig struct { } type CalicoCfg struct { - IPIPMode string `yaml:"ipipMode" json:"ipipMode,omitempty"` - VXLANMode string `yaml:"vxlanMode" json:"vxlanMode,omitempty"` - VethMTU int `yaml:"vethMTU" json:"vethMTU,omitempty"` - Ipv4NatOutgoing *bool `yaml:"ipv4NatOutgoing" json:"ipv4NatOutgoing,omitempty"` - DefaultIPPOOL *bool `yaml:"defaultIPPOOL" json:"defaultIPPOOL,omitempty"` - EnableTypha *bool `yaml:"enableTypha" json:"enableTypha,omitempty"` - Replicas int `yaml:"replicas" json:"replicas,omitempty"` - NodeSelector map[string]string `yaml:"nodeSelector" json:"nodeSelector,omitempty"` + IPIPMode string `yaml:"ipipMode" json:"ipipMode,omitempty"` + VXLANMode string `yaml:"vxlanMode" json:"vxlanMode,omitempty"` + VethMTU int `yaml:"vethMTU" json:"vethMTU,omitempty"` + Ipv4NatOutgoing *bool `yaml:"ipv4NatOutgoing" json:"ipv4NatOutgoing,omitempty"` + DefaultIPPOOL *bool `yaml:"defaultIPPOOL" json:"defaultIPPOOL,omitempty"` + Typha Typha `yaml:"typha" json:"typha,omitempty"` + Controller Controller `yaml:"controller" json:"controller,omitempty"` +} + +type Typha struct { + Replicas int `yaml:"replicas" json:"replicas,omitempty"` + NodeSelector map[string]string `yaml:"nodeSelector" json:"nodeSelector,omitempty"` + Enabled *bool `yaml:"enabled" json:"enabled,omitempty"` +} + +type Controller struct { + Replicas int `yaml:"replicas" json:"replicas,omitempty"` + NodeSelector map[string]string `yaml:"nodeSelector" json:"nodeSelector,omitempty"` } type FlannelCfg struct { @@ -186,12 +196,12 @@ func (c *CalicoCfg) EnableDefaultIPPOOL() bool { return *c.DefaultIPPOOL } -// Typha is used to determine whether to enable calico Typha -func (c *CalicoCfg) Typha() bool { - if c.EnableTypha == nil { +// EnableTypha is used to determine whether to enable calico Typha +func (c *CalicoCfg) EnableTypha() bool { + if c.Typha.Enabled == nil { return false } - return *c.EnableTypha + return *c.Typha.Enabled } // EnableInit is used to determine whether to create default network diff --git a/cmd/kk/pkg/plugins/network/tasks.go b/cmd/kk/pkg/plugins/network/tasks.go index 08f5d066b..3bdc62b9d 100644 --- a/cmd/kk/pkg/plugins/network/tasks.go +++ b/cmd/kk/pkg/plugins/network/tasks.go @@ -460,7 +460,7 @@ func (g *GenerateCalicoManifests) Execute(runtime connector.Runtime) error { "CalicoFlexvolImage": images.GetImage(runtime, g.KubeConf, "calico-flexvol").ImageName(), "CalicoControllersImage": images.GetImage(runtime, g.KubeConf, "calico-kube-controllers").ImageName(), "CalicoTyphaImage": images.GetImage(runtime, g.KubeConf, "calico-typha").ImageName(), - "TyphaEnabled": len(runtime.GetHostsByRole(common.K8s)) > 50 || g.KubeConf.Cluster.Network.Calico.Typha(), + "TyphaEnabled": len(runtime.GetHostsByRole(common.K8s)) > 50 || g.KubeConf.Cluster.Network.Calico.EnableTypha(), "VethMTU": g.KubeConf.Cluster.Network.Calico.VethMTU, "NodeCidrMaskSize": g.KubeConf.Cluster.Kubernetes.NodeCidrMaskSize, "IPIPMode": g.KubeConf.Cluster.Network.Calico.IPIPMode, @@ -469,8 +469,10 @@ func (g *GenerateCalicoManifests) Execute(runtime connector.Runtime) error { "IPV4POOLNATOUTGOING": g.KubeConf.Cluster.Network.Calico.EnableIPV4POOL_NAT_OUTGOING(), "DefaultIPPOOL": g.KubeConf.Cluster.Network.Calico.EnableDefaultIPPOOL(), "IPv6Support": IPv6Support, - "Replicas": g.KubeConf.Cluster.Network.Calico.Replicas, - "NodeSelector": g.KubeConf.Cluster.Network.Calico.NodeSelector, + "TyphaReplicas": g.KubeConf.Cluster.Network.Calico.Typha.Replicas, + "TyphaNodeSelector": g.KubeConf.Cluster.Network.Calico.Typha.NodeSelector, + "ControllerReplicas": g.KubeConf.Cluster.Network.Calico.Controller.Replicas, + "ControllerNodeSelector": g.KubeConf.Cluster.Network.Calico.Controller.NodeSelector, }, } templateAction.Init(nil, nil) diff --git a/cmd/kk/pkg/plugins/network/templates/calico.tmpl b/cmd/kk/pkg/plugins/network/templates/calico.tmpl index 23a50f784..74e0c18b7 100644 --- a/cmd/kk/pkg/plugins/network/templates/calico.tmpl +++ b/cmd/kk/pkg/plugins/network/templates/calico.tmpl @@ -5171,7 +5171,7 @@ metadata: k8s-app: calico-kube-controllers spec: # The controllers can only have a single active instance. - replicas: {{ if .Replicas }}{{ .Replicas }}{{ else }}1{{ end }} + replicas: {{ if .ControllerReplicas }}{{ .ControllerReplicas }}{{ else }}1{{ end }} selector: matchLabels: k8s-app: calico-kube-controllers @@ -5186,8 +5186,8 @@ spec: spec: nodeSelector: kubernetes.io/os: linux -{{ if .NodeSelector }} - {{- toYaml .NodeSelector | indent 8 }} +{{ if .ControllerNodeSelector }} + {{- toYaml .ControllerNodeSelector | indent 8 }} {{- end }} tolerations: # Mark the pod as a critical add-on for rescheduling. @@ -5197,7 +5197,7 @@ spec: effect: NoSchedule - key: node-role.kubernetes.io/control-plane effect: NoSchedule -{{ if .NodeSelector }} +{{ if .ControllerNodeSelector }} affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: @@ -5258,7 +5258,7 @@ spec: # We recommend using Typha if you have more than 50 nodes. Above 100 nodes it is essential # (when using the Kubernetes datastore). Use one replica for every 100-200 nodes. In # production, we recommend running at least 3 replicas to reduce the impact of rolling upgrade. - replicas: {{ if .Replicas }}{{ .Replicas }}{{ else }}1{{ end }} + replicas: {{ if .TyphaReplicas }}{{ .TyphaReplicas }}{{ else }}1{{ end }} revisionHistoryLimit: 2 selector: matchLabels: @@ -5285,14 +5285,14 @@ spec: spec: nodeSelector: kubernetes.io/os: linux -{{ if .NodeSelector }} - {{- toYaml .NodeSelector | indent 8 }} +{{ if .TyphaNodeSelector }} + {{- toYaml .TyphaNodeSelector | indent 8 }} {{- end }} hostNetwork: true # Typha supports graceful shut down, disconnecting clients slowly during the grace period. # The TYPHA_SHUTDOWNTIMEOUTSECS env var should be kept in sync with this value. terminationGracePeriodSeconds: 300 -{{ if .NodeSelector }} +{{ if .TyphaNodeSelector }} affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: