Skip to content
This repository was archived by the owner on Dec 31, 2025. It is now read-only.

Commit 7474a41

Browse files
Configurable parameters (#63)
Refactor Nodeadm was not parsing cluster conf Fix clusterConfig field name in Init and Join configuration Add unit tests for cluster configuration Review comments
1 parent 5e5dd95 commit 7474a41

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

apis/config.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@ package apis
22

33
import (
44
kubeadmv1alpha1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha1"
5+
kubeletconfigv1beta1 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1"
6+
kubeproxyconfigv1alpha1 "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/v1alpha1"
57
)
68

79
// InitConfiguration specifies the configuration used by the init command
810
type InitConfiguration struct {
9-
Networking Networking `json:"networking"`
10-
VIPConfiguration VIPConfiguration `json:"vipConfiguration"`
11-
MasterConfiguration kubeadmv1alpha1.MasterConfiguration `json:"masterConfiguration"`
11+
Networking Networking `json:"networking"`
12+
VIPConfiguration VIPConfiguration `json:"vipConfiguration"`
13+
MasterConfiguration kubeadmv1alpha1.MasterConfiguration `json:"masterConfiguration"`
14+
KubeProxy *kubeproxyconfigv1alpha1.KubeProxyConfiguration `json:"kubeProxy"`
15+
Kubelet *kubeletconfigv1beta1.KubeletConfiguration `json:"kubelet"`
16+
NetworkBackend map[string]string `json:"networkBackend"`
17+
KeepAlived map[string]string `json:"keepAlived"`
1218
}
1319

1420
// JoinConfiguration specifies the configuration used by the join command
1521
type JoinConfiguration struct {
16-
Networking Networking `json:"networking"`
22+
Networking Networking `json:"networking"`
23+
Kubelet *kubeletconfigv1beta1.KubeletConfiguration `json:"kubelet"`
1724
}
1825

1926
// VIPConfiguration specifies the parameters used to provision a virtual IP

apis/defaults.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ func SetInitDefaults(config *InitConfiguration) {
1919
config.MasterConfiguration.APIVersion = "kubeadm.k8s.io/v1alpha1"
2020
config.MasterConfiguration.KubernetesVersion = constants.KubernetesVersion
2121
config.MasterConfiguration.NoTaintMaster = true
22-
2322
addOrAppend(&config.MasterConfiguration.APIServerExtraArgs, "feature-gates", constants.FeatureGates)
2423
addOrAppend(&config.MasterConfiguration.ControllerManagerExtraArgs, "feature-gates", constants.FeatureGates)
2524
addOrAppend(&config.MasterConfiguration.SchedulerExtraArgs, "feature-gates", constants.FeatureGates)
26-
2725
}
2826

29-
// SetInitDynamicDefaults sets defaults derived at runtime
27+
// SetInitDynamicDefaults sets defaults derived at runtime
3028
func SetInitDynamicDefaults(config *InitConfiguration) error {
3129
nodeName, err := constants.GetHostnameOverride()
3230
if err != nil {

constants/constants.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ const (
2727
KeepalivedImage = "platform9/keepalived:v2.0.4"
2828
CacheDir = "/var/cache/nodeadm/"
2929
Execute = 0744
30-
Read = 0644
31-
ServiceNodePortRange = "80-32767"
32-
// TODO: Add PodPriority when introduced in kubeadm
33-
FeatureGates = "ExperimentalCriticalPodAnnotation=true"
30+
Read = 0644 // TODO: Add PodPriority when introduced in kubeadm
31+
FeatureGates = "ExperimentalCriticalPodAnnotation=true"
3432
)
3533

3634
const (
@@ -61,12 +59,7 @@ var CNIPluginsFilename = fmt.Sprintf("cni-plugins-amd64-%s.tgz", CNIVersion)
6159

6260
const (
6361
// TODO(dlipovetsky) Move fields to configuration
64-
KubeletFailSwapOn = false
65-
KubeletMaxPods = 500
66-
KubeletKubeAPIQPS = 20
67-
KubeletKubeAPIBurst = 40
68-
KubeletEvictionHard = "memory.available<600Mi,nodefs.available<10%"
69-
62+
KubeletEvictionHard = "memory.available<600Mi,nodefs.available<10%"
7063
NodeadmKubeletSystemdDropinFilename = "20-nodeadm.conf"
7164
NodeadmKubeletSystemdDropinTemplate = `[Service]
7265
Environment="KUBELET_DNS_ARGS=--cluster-dns={{ .ClusterDNS }} --cluster-domain={{ .ClusterDomain }}"

utils/install.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"text/template"
1212

1313
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
14+
kubeletconfigv1beta1 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1"
1415

1516
"github.com/platform9/nodeadm/apis"
1617
"github.com/platform9/nodeadm/constants"
@@ -21,14 +22,16 @@ import (
2122

2223
func InstallMasterComponents(config *apis.InitConfiguration) {
2324
PopulateCache()
24-
25+
placeKubeComponents()
26+
placeCNIPlugin()
2527
if err := systemd.StopIfActive("kubelet.service"); err != nil {
2628
log.Fatalf("Failed to install kubelet service: %v", err)
2729
}
2830
if err := systemd.DisableIfEnabled("kubelet.service"); err != nil {
2931
log.Fatalf("Failed to install kubelet service: %v", err)
3032
}
31-
PlaceComponentsFromCache(config.Networking)
33+
placeKubeletSystemAndDropinFiles(config.Networking, config.Kubelet)
34+
placeNetworkConfig()
3235
if err := systemd.Enable("kubelet.service"); err != nil {
3336
log.Fatalf("Failed to install kubelet service: %v", err)
3437
}
@@ -49,19 +52,20 @@ func InstallMasterComponents(config *apis.InitConfiguration) {
4952
if err := systemd.Start("keepalived.service"); err != nil {
5053
log.Fatalf("Failed to install keepalived service: %v", err)
5154
}
52-
5355
}
5456

5557
func InstallNodeComponents(config *apis.JoinConfiguration) {
5658
PopulateCache()
57-
59+
placeKubeComponents()
60+
placeCNIPlugin()
5861
if err := systemd.StopIfActive("kubelet.service"); err != nil {
5962
log.Fatalf("Failed to install kubelet service: %v", err)
6063
}
6164
if err := systemd.DisableIfEnabled("kubelet.service"); err != nil {
6265
log.Fatalf("Failed to install kubelet service: %v", err)
6366
}
64-
PlaceComponentsFromCache(config.Networking)
67+
placeKubeletSystemAndDropinFiles(config.Networking, config.Kubelet)
68+
placeNetworkConfig()
6569
if err := systemd.Enable("kubelet.service"); err != nil {
6670
log.Fatalf("Failed to install kubelet service: %v", err)
6771
}
@@ -70,13 +74,10 @@ func InstallNodeComponents(config *apis.JoinConfiguration) {
7074
}
7175
}
7276

73-
func PlaceComponentsFromCache(netConfig apis.Networking) {
74-
placeKubeComponents()
75-
placeCNIPlugin()
77+
func placeKubeletSystemAndDropinFiles(netConfig apis.Networking, kubeletConfig *kubeletconfigv1beta1.KubeletConfiguration) {
7678
placeAndModifyKubeletServiceFile()
77-
placeAndModifyKubeadmKubeletSystemdDropin(netConfig)
78-
placeAndModifyNodeadmKubeletSystemdDropin(netConfig)
79-
placeNetworkConfig()
79+
placeAndModifyKubeadmKubeletSystemdDropin()
80+
placeAndModifyNodeadmKubeletSystemdDropin(netConfig, kubeletConfig)
8081
}
8182

8283
func placeAndModifyKubeletServiceFile() {
@@ -85,7 +86,7 @@ func placeAndModifyKubeletServiceFile() {
8586
ReplaceString(serviceFile, "/usr/bin", constants.BaseInstallDir)
8687
}
8788

88-
func placeAndModifyKubeadmKubeletSystemdDropin(netConfig apis.Networking) {
89+
func placeAndModifyKubeadmKubeletSystemdDropin() {
8990
err := os.MkdirAll(filepath.Join(constants.SystemdDir, "kubelet.service.d"), constants.Execute)
9091
if err != nil {
9192
log.Fatalf("Failed to create dir with error %v\n", err)
@@ -95,7 +96,7 @@ func placeAndModifyKubeadmKubeletSystemdDropin(netConfig apis.Networking) {
9596
ReplaceString(confFile, "/usr/bin", constants.BaseInstallDir)
9697
}
9798

98-
func placeAndModifyNodeadmKubeletSystemdDropin(netConfig apis.Networking) {
99+
func placeAndModifyNodeadmKubeletSystemdDropin(netConfig apis.Networking, kubeletConfig *kubeletconfigv1beta1.KubeletConfiguration) {
99100
err := os.MkdirAll(filepath.Join(constants.SystemdDir, "kubelet.service.d"), constants.Execute)
100101
if err != nil {
101102
log.Fatalf("Failed to create dir with error %v\n", err)
@@ -114,22 +115,22 @@ func placeAndModifyNodeadmKubeletSystemdDropin(netConfig apis.Networking) {
114115

115116
data := struct {
116117
FailSwapOn bool
117-
MaxPods int
118+
MaxPods int32
118119
ClusterDNS string
119120
ClusterDomain string
120121
HostnameOverride string
121-
KubeAPIQPS int
122-
KubeAPIBurst int
122+
KubeAPIQPS int32
123+
KubeAPIBurst int32
123124
EvictionHard string
124125
FeatureGates string
125126
}{
126-
FailSwapOn: constants.KubeletFailSwapOn,
127-
MaxPods: constants.KubeletMaxPods,
127+
FailSwapOn: *kubeletConfig.FailSwapOn,
128+
MaxPods: kubeletConfig.MaxPods,
128129
ClusterDNS: dnsIP.String(),
129130
ClusterDomain: netConfig.DNSDomain,
130131
HostnameOverride: hostnameOverride,
131-
KubeAPIQPS: constants.KubeletKubeAPIQPS,
132-
KubeAPIBurst: constants.KubeletKubeAPIBurst,
132+
KubeAPIQPS: *kubeletConfig.KubeAPIQPS,
133+
KubeAPIBurst: kubeletConfig.KubeAPIBurst,
133134
EvictionHard: constants.KubeletEvictionHard,
134135
FeatureGates: constants.FeatureGates,
135136
}

0 commit comments

Comments
 (0)