From 5e5dd95320f2f51b68e1870a59a33b5eb273fafc Mon Sep 17 00:00:00 2001 From: ojmhetar Date: Thu, 4 Oct 2018 00:52:50 -0700 Subject: [PATCH] Add eviction-hard and feature-gates flag (#64) --- apis/defaults.go | 23 ++++++++++++++++++++--- constants/constants.go | 5 ++++- utils/install.go | 5 +++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/apis/defaults.go b/apis/defaults.go index 7d092d5..62baad0 100644 --- a/apis/defaults.go +++ b/apis/defaults.go @@ -19,9 +19,10 @@ func SetInitDefaults(config *InitConfiguration) { config.MasterConfiguration.APIVersion = "kubeadm.k8s.io/v1alpha1" config.MasterConfiguration.KubernetesVersion = constants.KubernetesVersion config.MasterConfiguration.NoTaintMaster = true - config.MasterConfiguration.APIServerExtraArgs = map[string]string{ - "service-node-port-range": constants.ServiceNodePortRange, - } + + addOrAppend(&config.MasterConfiguration.APIServerExtraArgs, "feature-gates", constants.FeatureGates) + addOrAppend(&config.MasterConfiguration.ControllerManagerExtraArgs, "feature-gates", constants.FeatureGates) + addOrAppend(&config.MasterConfiguration.SchedulerExtraArgs, "feature-gates", constants.FeatureGates) } @@ -63,3 +64,19 @@ func SetMasterConfigurationNetworkingDefaultsWithNetworking(config *InitConfigur config.MasterConfiguration.Networking.DNSDomain = config.Networking.DNSDomain } } + +func addOrAppend(extraArgs *map[string]string, key string, value string) { + // Create a new map if it doesn't exist. + if *extraArgs == nil { + *extraArgs = make(map[string]string) + } + // Add the key with the value if it doesn't exist. Otherwise, append the value + // to the pre-existing values. + prevFeatureGates := (*extraArgs)[key] + if prevFeatureGates == "" { + (*extraArgs)[key] = value + } else { + featureGates := prevFeatureGates + "," + value + (*extraArgs)[key] = featureGates + } +} diff --git a/constants/constants.go b/constants/constants.go index d72c1cc..9857a8e 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -29,6 +29,8 @@ const ( Execute = 0744 Read = 0644 ServiceNodePortRange = "80-32767" + // TODO: Add PodPriority when introduced in kubeadm + FeatureGates = "ExperimentalCriticalPodAnnotation=true" ) const ( @@ -63,11 +65,12 @@ const ( KubeletMaxPods = 500 KubeletKubeAPIQPS = 20 KubeletKubeAPIBurst = 40 + KubeletEvictionHard = "memory.available<600Mi,nodefs.available<10%" NodeadmKubeletSystemdDropinFilename = "20-nodeadm.conf" NodeadmKubeletSystemdDropinTemplate = `[Service] Environment="KUBELET_DNS_ARGS=--cluster-dns={{ .ClusterDNS }} --cluster-domain={{ .ClusterDomain }}" -Environment="KUBELET_EXTRA_ARGS=--max-pods={{ .MaxPods }} --fail-swap-on={{ .FailSwapOn }} --hostname-override={{ .HostnameOverride }} --kube-api-qps={{ .KubeAPIQPS }} --kube-api-burst={{ .KubeAPIBurst }}" +Environment="KUBELET_EXTRA_ARGS=--max-pods={{ .MaxPods }} --fail-swap-on={{ .FailSwapOn }} --hostname-override={{ .HostnameOverride }} --kube-api-qps={{ .KubeAPIQPS }} --kube-api-burst={{ .KubeAPIBurst }} --feature-gates={{ .FeatureGates}} --eviction-hard={{ .EvictionHard }}" ` ) diff --git a/utils/install.go b/utils/install.go index fefb24e..4aee33e 100644 --- a/utils/install.go +++ b/utils/install.go @@ -120,6 +120,8 @@ func placeAndModifyNodeadmKubeletSystemdDropin(netConfig apis.Networking) { HostnameOverride string KubeAPIQPS int KubeAPIBurst int + EvictionHard string + FeatureGates string }{ FailSwapOn: constants.KubeletFailSwapOn, MaxPods: constants.KubeletMaxPods, @@ -128,6 +130,8 @@ func placeAndModifyNodeadmKubeletSystemdDropin(netConfig apis.Networking) { HostnameOverride: hostnameOverride, KubeAPIQPS: constants.KubeletKubeAPIQPS, KubeAPIBurst: constants.KubeletKubeAPIBurst, + EvictionHard: constants.KubeletEvictionHard, + FeatureGates: constants.FeatureGates, } writeTemplateIntoFile(constants.NodeadmKubeletSystemdDropinTemplate, "nodeadm-kubelet-systemd-dropin", confFile, data) @@ -259,6 +263,7 @@ ExecStartPre=-/usr/bin/docker kill vip ExecStartPre=-/usr/bin/docker rm vip ExecStop=/usr/bin/docker stop vip Restart=on-failure +MemoryLow=10M [Install] WantedBy=multi-user.target `