Skip to content

Commit

Permalink
add replicas and nodeselector fields for calico
Browse files Browse the repository at this point in the history
Signed-off-by: pixiake <[email protected]>
(cherry picked from commit 0652e81)
  • Loading branch information
pixiake committed May 17, 2024
1 parent 7a58ce7 commit 4923911
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
14 changes: 8 additions & 6 deletions cmd/kk/apis/kubekey/v1alpha2/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ 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"`
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"`
}

type FlannelCfg struct {
Expand Down
6 changes: 5 additions & 1 deletion cmd/kk/pkg/plugins/network/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"text/template"
"time"

"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/utils"

"github.com/pkg/errors"

"github.com/kubesphere/kubekey/v3/cmd/kk/apis/kubekey/v1alpha2"
Expand Down Expand Up @@ -437,7 +439,7 @@ func (g *GenerateCalicoManifests) Execute(runtime connector.Runtime) error {
if err != nil {
return err
}
calico := template.Must(template.New("network-plugin.yaml").Parse(string(calicoContent)))
calico := template.Must(template.New("network-plugin.yaml").Funcs(utils.FuncMap).Parse(string(calicoContent)))

IPv6Support := false
kubePodsV6CIDR := ""
Expand Down Expand Up @@ -467,6 +469,8 @@ 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,
},
}
templateAction.Init(nil, nil)
Expand Down
38 changes: 36 additions & 2 deletions cmd/kk/pkg/plugins/network/templates/calico.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5161,7 +5161,7 @@ metadata:
k8s-app: calico-kube-controllers
spec:
# The controllers can only have a single active instance.
replicas: 1
replicas: {{ if .Replicas }}{{ .Replicas }}{{ else }}1{{ end }}
selector:
matchLabels:
k8s-app: calico-kube-controllers
Expand All @@ -5176,6 +5176,9 @@ spec:
spec:
nodeSelector:
kubernetes.io/os: linux
{{ if .NodeSelector }}
{{- toYaml .NodeSelector | indent 8 }}
{{- end }}
tolerations:
# Mark the pod as a critical add-on for rescheduling.
- key: CriticalAddonsOnly
Expand All @@ -5184,6 +5187,20 @@ spec:
effect: NoSchedule
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
{{ if .NodeSelector }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: k8s-app
operator: In
values:
- calico-kube-controllers
topologyKey: kubernetes.io/hostname
{{- end }}
serviceAccountName: calico-kube-controllers
priorityClassName: system-cluster-critical
containers:
Expand Down Expand Up @@ -5231,7 +5248,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: 1
replicas: {{ if .Replicas }}{{ .Replicas }}{{ else }}1{{ end }}
revisionHistoryLimit: 2
selector:
matchLabels:
Expand All @@ -5258,10 +5275,27 @@ spec:
spec:
nodeSelector:
kubernetes.io/os: linux
{{ if .NodeSelector }}
{{- toYaml .NodeSelector | 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 }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: k8s-app
operator: In
values:
- calico-typha
topologyKey: kubernetes.io/hostname
{{- end }}
tolerations:
# Mark the pod as a critical add-on for rescheduling.
- key: CriticalAddonsOnly
Expand Down

0 comments on commit 4923911

Please sign in to comment.