From 4e31add8fe9ac462495f0b3f63270570a8307ac0 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Steenis <mail@superseb.nl> Date: Thu, 26 Nov 2020 17:19:38 +0100 Subject: [PATCH] Add tolerations option to addons --- cluster/addons.go | 11 ++++++++++- cluster/network.go | 3 +++ types/rke_types.go | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cluster/addons.go b/cluster/addons.go index e5df80df..6b662a77 100644 --- a/cluster/addons.go +++ b/cluster/addons.go @@ -24,6 +24,7 @@ import ( "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" appsv1 "k8s.io/api/apps/v1" + v1 "k8s.io/api/core/v1" ) const ( @@ -66,6 +67,7 @@ type ingressOptions struct { HTTPSPort int NetworkMode string UpdateStrategy *appsv1.DaemonSetUpdateStrategy + Tolerations []v1.Toleration } type MetricsServerOptions struct { @@ -76,6 +78,7 @@ type MetricsServerOptions struct { Version string UpdateStrategy *appsv1.DeploymentStrategy Replicas *int32 + Tolerations []v1.Toleration } type CoreDNSOptions struct { @@ -89,6 +92,7 @@ type CoreDNSOptions struct { NodeSelector map[string]string UpdateStrategy *appsv1.DeploymentStrategy LinearAutoscalerParams string + Tolerations []v1.Toleration } type KubeDNSOptions struct { @@ -105,6 +109,7 @@ type KubeDNSOptions struct { NodeSelector map[string]string UpdateStrategy *appsv1.DeploymentStrategy LinearAutoscalerParams string + Tolerations []v1.Toleration } type NodelocalOptions struct { @@ -322,6 +327,7 @@ func (c *Cluster) deployKubeDNS(ctx context.Context, data map[string]interface{} Type: c.DNS.UpdateStrategy.Strategy, RollingUpdate: c.DNS.UpdateStrategy.RollingUpdate, }, + Tolerations: c.DNS.Tolerations, } linearModeBytes, err := json.Marshal(c.DNS.LinearAutoscalerParams) if err != nil { @@ -358,6 +364,7 @@ func (c *Cluster) deployCoreDNS(ctx context.Context, data map[string]interface{} Type: c.DNS.UpdateStrategy.Strategy, RollingUpdate: c.DNS.UpdateStrategy.RollingUpdate, }, + Tolerations: c.DNS.Tolerations, } linearModeBytes, err := json.Marshal(c.DNS.LinearAutoscalerParams) if err != nil { @@ -411,7 +418,8 @@ func (c *Cluster) deployMetricServer(ctx context.Context, data map[string]interf Type: c.Monitoring.UpdateStrategy.Strategy, RollingUpdate: c.Monitoring.UpdateStrategy.RollingUpdate, }, - Replicas: c.Monitoring.Replicas, + Replicas: c.Monitoring.Replicas, + Tolerations: c.Monitoring.Tolerations, } tmplt, err := templates.GetVersionedTemplates(kdm.MetricsServer, data, c.Version) if err != nil { @@ -575,6 +583,7 @@ func (c *Cluster) deployIngress(ctx context.Context, data map[string]interface{} Type: c.Ingress.UpdateStrategy.Strategy, RollingUpdate: c.Ingress.UpdateStrategy.RollingUpdate, }, + Tolerations: c.Ingress.Tolerations, } // since nginx ingress controller 0.16.0, it can be run as non-root and doesn't require privileged anymore. // So we can use securityContext instead of setting privileges via initContainer. diff --git a/cluster/network.go b/cluster/network.go index bce989ae..ca355b9c 100644 --- a/cluster/network.go +++ b/cluster/network.go @@ -257,6 +257,7 @@ const ( NodeSubnet = "NodeSubnet" NodeSelector = "NodeSelector" UpdateStrategy = "UpdateStrategy" + Tolerations = "Tolerations" ) var EtcdPortList = []string{ @@ -354,6 +355,7 @@ func (c *Cluster) doCalicoDeploy(ctx context.Context, data map[string]interface{ RollingUpdate: c.Network.UpdateStrategy.RollingUpdate, }, FlexVolPluginDir: c.Network.Options[CalicoFlexVolPluginDirectory], + Tolerations: c.Network.Tolerations, } pluginYaml, err := c.getNetworkPluginManifest(calicoConfig, data) if err != nil { @@ -399,6 +401,7 @@ func (c *Cluster) doCanalDeploy(ctx context.Context, data map[string]interface{} RollingUpdate: c.Network.UpdateStrategy.RollingUpdate, }, FlexVolPluginDir: c.Network.Options[CanalFlexVolPluginDirectory], + Tolerations: c.Network.Tolerations, } pluginYaml, err := c.getNetworkPluginManifest(canalConfig, data) if err != nil { diff --git a/types/rke_types.go b/types/rke_types.go index bc235500..c1c93794 100644 --- a/types/rke_types.go +++ b/types/rke_types.go @@ -389,6 +389,8 @@ type NetworkConfig struct { NodeSelector map[string]string `yaml:"node_selector" json:"nodeSelector,omitempty"` // Network plugin daemonset upgrade strategy UpdateStrategy *DaemonSetUpdateStrategy `yaml:"update_strategy" json:"updateStrategy,omitempty"` + // Tolerations for Deployments + Tolerations []v1.Toleration `yaml:"tolerations" json:"tolerations,omitempty"` } type AuthWebhookConfig struct { @@ -439,6 +441,8 @@ type IngressConfig struct { HTTPSPort int `yaml:"https_port" json:"httpsPort,omitempty"` // NetworkMode selector for ingress controller pods. Default is HostNetwork NetworkMode string `yaml:"network_mode" json:"networkMode,omitempty"` + // Tolerations for Deployments + Tolerations []v1.Toleration `yaml:"tolerations" json:"tolerations,omitempty"` } type ExtraEnv struct { @@ -895,6 +899,8 @@ type MonitoringConfig struct { UpdateStrategy *DeploymentStrategy `yaml:"update_strategy" json:"updateStrategy,omitempty"` // Number of monitoring addon pods Replicas *int32 `yaml:"replicas" json:"replicas,omitempty" norman:"default=1"` + // Tolerations for Deployments + Tolerations []v1.Toleration `yaml:"tolerations" json:"tolerations,omitempty"` } type RestoreConfig struct { @@ -925,6 +931,8 @@ type DNSConfig struct { UpdateStrategy *DeploymentStrategy `yaml:"update_strategy" json:"updateStrategy,omitempty"` // Autoscaler fields to determine number of dns replicas LinearAutoscalerParams *LinearAutoscalerParams `yaml:"linear_autoscaler_params" json:"linearAutoscalerParams,omitempty"` + // Tolerations for Deployments + Tolerations []v1.Toleration `yaml:"tolerations" json:"tolerations,omitempty"` } type Nodelocal struct {