-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement extra-config for kubeadm kubelet
- Loading branch information
Showing
6 changed files
with
458 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package kubeadm | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/minikube/pkg/minikube/bootstrapper" | ||
"k8s.io/minikube/pkg/util" | ||
) | ||
|
||
func TestGenerateConfig(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
cfg bootstrapper.KubernetesConfig | ||
expectedCfg string | ||
shouldErr bool | ||
}{ | ||
{ | ||
description: "no extra args", | ||
cfg: bootstrapper.KubernetesConfig{ | ||
NodeIP: "192.168.1.100", | ||
KubernetesVersion: "v1.8.0", | ||
NodeName: "minikube", | ||
}, | ||
expectedCfg: `apiVersion: kubeadm.k8s.io/v1alpha1 | ||
kind: MasterConfiguration | ||
api: | ||
advertiseAddress: 192.168.1.100 | ||
bindPort: 8443 | ||
kubernetesVersion: v1.8.0 | ||
certificatesDir: /var/lib/localkube/certs/ | ||
networking: | ||
serviceSubnet: 10.0.0.0/24 | ||
etcd: | ||
dataDir: /data | ||
nodeName: minikube | ||
`, | ||
}, | ||
{ | ||
description: "extra args all components", | ||
cfg: bootstrapper.KubernetesConfig{ | ||
NodeIP: "192.168.1.101", | ||
KubernetesVersion: "v1.8.0-alpha.0", | ||
NodeName: "extra-args-minikube", | ||
ExtraOptions: util.ExtraOptionSlice{ | ||
util.ExtraOption{ | ||
Component: Apiserver, | ||
Key: "fail-no-swap", | ||
Value: "true", | ||
}, | ||
util.ExtraOption{ | ||
Component: ControllerManager, | ||
Key: "kube-api-burst", | ||
Value: "32", | ||
}, | ||
util.ExtraOption{ | ||
Component: Scheduler, | ||
Key: "scheduler-name", | ||
Value: "mini-scheduler", | ||
}, | ||
}, | ||
}, | ||
expectedCfg: `apiVersion: kubeadm.k8s.io/v1alpha1 | ||
kind: MasterConfiguration | ||
api: | ||
advertiseAddress: 192.168.1.101 | ||
bindPort: 8443 | ||
kubernetesVersion: v1.8.0-alpha.0 | ||
certificatesDir: /var/lib/localkube/certs/ | ||
networking: | ||
serviceSubnet: 10.0.0.0/24 | ||
etcd: | ||
dataDir: /data | ||
nodeName: extra-args-minikube | ||
apiServerExtraArgs: | ||
fail-no-swap: true | ||
controllerManagerExtraArgs: | ||
kube-api-burst: 32 | ||
schedulerExtraArgs: | ||
scheduler-name: mini-scheduler | ||
`, | ||
}, | ||
{ | ||
// Unknown components should fail silently | ||
description: "unknown component", | ||
cfg: bootstrapper.KubernetesConfig{ | ||
NodeIP: "192.168.1.101", | ||
KubernetesVersion: "v1.8.0-alpha.0", | ||
NodeName: "extra-args-minikube", | ||
ExtraOptions: util.ExtraOptionSlice{ | ||
util.ExtraOption{ | ||
Component: "not-a-real-component", | ||
Key: "killswitch", | ||
Value: "true", | ||
}, | ||
}, | ||
}, | ||
shouldErr: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
actualCfg, err := generateConfig(test.cfg) | ||
if err != nil && !test.shouldErr { | ||
t.Errorf("got unexpected error generating config: %s", err) | ||
return | ||
} | ||
if err == nil && test.shouldErr { | ||
t.Errorf("expected error but got none, config: %s", actualCfg) | ||
return | ||
} | ||
if actualCfg != test.expectedCfg { | ||
t.Errorf("actual config does not match expected. actual:\n%sexpected:\n%s", actualCfg, test.expectedCfg) | ||
return | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package kubeadm | ||
|
||
import "html/template" | ||
|
||
var kubeadmConfigTemplate = template.Must(template.New("kubeadmConfigTemplate").Parse(`apiVersion: kubeadm.k8s.io/v1alpha1 | ||
kind: MasterConfiguration | ||
api: | ||
advertiseAddress: {{.AdvertiseAddress}} | ||
bindPort: {{.APIServerPort}} | ||
kubernetesVersion: {{.KubernetesVersion}} | ||
certificatesDir: {{.CertDir}} | ||
networking: | ||
serviceSubnet: {{.ServiceCIDR}} | ||
etcd: | ||
dataDir: {{.EtcdDataDir}} | ||
nodeName: {{.NodeName}} | ||
{{range .ExtraArgs}}{{.Component}}:{{range $key, $value := .Options}} | ||
{{$key}}: {{$value}} | ||
{{end}}{{end}}`)) | ||
|
||
var kubeletSystemdTemplate = template.Must(template.New("kubeletSystemdTemplate").Parse(` | ||
[Service] | ||
Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true" | ||
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true" | ||
Environment="KUBELET_DNS_ARGS=--cluster-dns=10.0.0.10 --cluster-domain=cluster.local" | ||
Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=0" | ||
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs" | ||
ExecStart= | ||
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_DNS_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CGROUP_ARGS {{.ExtraOptions}} | ||
`)) | ||
|
||
const kubeletService = ` | ||
[Unit] | ||
Description=kubelet: The Kubernetes Node Agent | ||
Documentation=http://kubernetes.io/docs/ | ||
[Service] | ||
ExecStart=/usr/bin/kubelet | ||
Restart=always | ||
StartLimitInterval=0 | ||
RestartSec=10 | ||
[Install] | ||
WantedBy=multi-user.target | ||
` | ||
|
||
var kubeadmRestoreTemplate = template.Must(template.New("kubeadmRestoreTemplate").Parse(` | ||
sudo kubeadm alpha phase certs all --config {{.KubeadmConfigFile}} && | ||
sudo /usr/bin/kubeadm alpha phase kubeconfig all --config {{.KubeadmConfigFile}} && | ||
sudo /usr/bin/kubeadm alpha phase controlplane all --config {{.KubeadmConfigFile}} && | ||
sudo /usr/bin/kubeadm alpha phase etcd local --config {{.KubeadmConfigFile}} | ||
`)) | ||
|
||
var kubeadmInitTemplate = template.Must(template.New("kubeadmInitTemplate").Parse("sudo /usr/bin/kubeadm init --config {{.KubeadmConfigFile}} --skip-preflight-checks")) |
Oops, something went wrong.