Skip to content

Commit

Permalink
Configurable parameters (#63)
Browse files Browse the repository at this point in the history
Refactor

Nodeadm was not parsing cluster conf

Fix clusterConfig field name in Init and Join
configuration

Add unit tests for cluster configuration

Review comments
  • Loading branch information
puneetguptanitj authored Oct 4, 2018
1 parent 5e5dd95 commit 7474a41
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
15 changes: 11 additions & 4 deletions apis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ package apis

import (
kubeadmv1alpha1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha1"
kubeletconfigv1beta1 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1"
kubeproxyconfigv1alpha1 "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/v1alpha1"
)

// InitConfiguration specifies the configuration used by the init command
type InitConfiguration struct {
Networking Networking `json:"networking"`
VIPConfiguration VIPConfiguration `json:"vipConfiguration"`
MasterConfiguration kubeadmv1alpha1.MasterConfiguration `json:"masterConfiguration"`
Networking Networking `json:"networking"`
VIPConfiguration VIPConfiguration `json:"vipConfiguration"`
MasterConfiguration kubeadmv1alpha1.MasterConfiguration `json:"masterConfiguration"`
KubeProxy *kubeproxyconfigv1alpha1.KubeProxyConfiguration `json:"kubeProxy"`
Kubelet *kubeletconfigv1beta1.KubeletConfiguration `json:"kubelet"`
NetworkBackend map[string]string `json:"networkBackend"`
KeepAlived map[string]string `json:"keepAlived"`
}

// JoinConfiguration specifies the configuration used by the join command
type JoinConfiguration struct {
Networking Networking `json:"networking"`
Networking Networking `json:"networking"`
Kubelet *kubeletconfigv1beta1.KubeletConfiguration `json:"kubelet"`
}

// VIPConfiguration specifies the parameters used to provision a virtual IP
Expand Down
4 changes: 1 addition & 3 deletions apis/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ func SetInitDefaults(config *InitConfiguration) {
config.MasterConfiguration.APIVersion = "kubeadm.k8s.io/v1alpha1"
config.MasterConfiguration.KubernetesVersion = constants.KubernetesVersion
config.MasterConfiguration.NoTaintMaster = true

addOrAppend(&config.MasterConfiguration.APIServerExtraArgs, "feature-gates", constants.FeatureGates)
addOrAppend(&config.MasterConfiguration.ControllerManagerExtraArgs, "feature-gates", constants.FeatureGates)
addOrAppend(&config.MasterConfiguration.SchedulerExtraArgs, "feature-gates", constants.FeatureGates)

}

// SetInitDynamicDefaults sets defaults derived at runtime
// SetInitDynamicDefaults sets defaults derived at runtime
func SetInitDynamicDefaults(config *InitConfiguration) error {
nodeName, err := constants.GetHostnameOverride()
if err != nil {
Expand Down
13 changes: 3 additions & 10 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ const (
KeepalivedImage = "platform9/keepalived:v2.0.4"
CacheDir = "/var/cache/nodeadm/"
Execute = 0744
Read = 0644
ServiceNodePortRange = "80-32767"
// TODO: Add PodPriority when introduced in kubeadm
FeatureGates = "ExperimentalCriticalPodAnnotation=true"
Read = 0644 // TODO: Add PodPriority when introduced in kubeadm
FeatureGates = "ExperimentalCriticalPodAnnotation=true"
)

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

const (
// TODO(dlipovetsky) Move fields to configuration
KubeletFailSwapOn = false
KubeletMaxPods = 500
KubeletKubeAPIQPS = 20
KubeletKubeAPIBurst = 40
KubeletEvictionHard = "memory.available<600Mi,nodefs.available<10%"

KubeletEvictionHard = "memory.available<600Mi,nodefs.available<10%"
NodeadmKubeletSystemdDropinFilename = "20-nodeadm.conf"
NodeadmKubeletSystemdDropinTemplate = `[Service]
Environment="KUBELET_DNS_ARGS=--cluster-dns={{ .ClusterDNS }} --cluster-domain={{ .ClusterDomain }}"
Expand Down
41 changes: 21 additions & 20 deletions utils/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"text/template"

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

"github.com/platform9/nodeadm/apis"
"github.com/platform9/nodeadm/constants"
Expand All @@ -21,14 +22,16 @@ import (

func InstallMasterComponents(config *apis.InitConfiguration) {
PopulateCache()

placeKubeComponents()
placeCNIPlugin()
if err := systemd.StopIfActive("kubelet.service"); err != nil {
log.Fatalf("Failed to install kubelet service: %v", err)
}
if err := systemd.DisableIfEnabled("kubelet.service"); err != nil {
log.Fatalf("Failed to install kubelet service: %v", err)
}
PlaceComponentsFromCache(config.Networking)
placeKubeletSystemAndDropinFiles(config.Networking, config.Kubelet)
placeNetworkConfig()
if err := systemd.Enable("kubelet.service"); err != nil {
log.Fatalf("Failed to install kubelet service: %v", err)
}
Expand All @@ -49,19 +52,20 @@ func InstallMasterComponents(config *apis.InitConfiguration) {
if err := systemd.Start("keepalived.service"); err != nil {
log.Fatalf("Failed to install keepalived service: %v", err)
}

}

func InstallNodeComponents(config *apis.JoinConfiguration) {
PopulateCache()

placeKubeComponents()
placeCNIPlugin()
if err := systemd.StopIfActive("kubelet.service"); err != nil {
log.Fatalf("Failed to install kubelet service: %v", err)
}
if err := systemd.DisableIfEnabled("kubelet.service"); err != nil {
log.Fatalf("Failed to install kubelet service: %v", err)
}
PlaceComponentsFromCache(config.Networking)
placeKubeletSystemAndDropinFiles(config.Networking, config.Kubelet)
placeNetworkConfig()
if err := systemd.Enable("kubelet.service"); err != nil {
log.Fatalf("Failed to install kubelet service: %v", err)
}
Expand All @@ -70,13 +74,10 @@ func InstallNodeComponents(config *apis.JoinConfiguration) {
}
}

func PlaceComponentsFromCache(netConfig apis.Networking) {
placeKubeComponents()
placeCNIPlugin()
func placeKubeletSystemAndDropinFiles(netConfig apis.Networking, kubeletConfig *kubeletconfigv1beta1.KubeletConfiguration) {
placeAndModifyKubeletServiceFile()
placeAndModifyKubeadmKubeletSystemdDropin(netConfig)
placeAndModifyNodeadmKubeletSystemdDropin(netConfig)
placeNetworkConfig()
placeAndModifyKubeadmKubeletSystemdDropin()
placeAndModifyNodeadmKubeletSystemdDropin(netConfig, kubeletConfig)
}

func placeAndModifyKubeletServiceFile() {
Expand All @@ -85,7 +86,7 @@ func placeAndModifyKubeletServiceFile() {
ReplaceString(serviceFile, "/usr/bin", constants.BaseInstallDir)
}

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

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

data := struct {
FailSwapOn bool
MaxPods int
MaxPods int32
ClusterDNS string
ClusterDomain string
HostnameOverride string
KubeAPIQPS int
KubeAPIBurst int
KubeAPIQPS int32
KubeAPIBurst int32
EvictionHard string
FeatureGates string
}{
FailSwapOn: constants.KubeletFailSwapOn,
MaxPods: constants.KubeletMaxPods,
FailSwapOn: *kubeletConfig.FailSwapOn,
MaxPods: kubeletConfig.MaxPods,
ClusterDNS: dnsIP.String(),
ClusterDomain: netConfig.DNSDomain,
HostnameOverride: hostnameOverride,
KubeAPIQPS: constants.KubeletKubeAPIQPS,
KubeAPIBurst: constants.KubeletKubeAPIBurst,
KubeAPIQPS: *kubeletConfig.KubeAPIQPS,
KubeAPIBurst: kubeletConfig.KubeAPIBurst,
EvictionHard: constants.KubeletEvictionHard,
FeatureGates: constants.FeatureGates,
}
Expand Down

0 comments on commit 7474a41

Please sign in to comment.