Skip to content

Commit

Permalink
Merge pull request #60 from UKHomeOffice/kube_args
Browse files Browse the repository at this point in the history
Kube extra args and taints if provided
  • Loading branch information
lewismarshall authored Jul 21, 2017
2 parents e25d18d + 7b09b60 commit 5c416e8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
30 changes: 29 additions & 1 deletion pkg/kmm/kmm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
log "github.com/Sirupsen/logrus"
"net/url"
"os"
"strings"
"time"

"github.com/UKHomeOffice/keto-k8/pkg/etcd"
Expand Down Expand Up @@ -43,7 +44,9 @@ type ConfigType struct {
Etcd etcd.Clienter
Kubeadm kubeadm.Kubeadmer
Kmm Interface
KubeletExtraArgs string
NodeLabels map[string]string
NodeTaints map[string]string
}

// Both structs here use the same config but are bound to different methods...
Expand Down Expand Up @@ -306,9 +309,34 @@ func (k *Kmm) UpdateCloudCfg() (err error) {
return fmt.Errorf("error parsing kubeversion %s", k.KubeadmCfg.KubeVersion)
}
k.NodeLabels = nd.Labels
k.NodeTaints = nd.Taints
k.KubeadmCfg.APIServerExtraArgs = stringToMap(nd.KubeArgs.APIServerExtraArgs)
k.KubeadmCfg.ControllerManagerExtraArgs = stringToMap(nd.KubeArgs.ControllerManagerExtraArgs)
k.KubeadmCfg.SchedulerExtraArgs = stringToMap(nd.KubeArgs.SchedulerExtraArgs)
k.KubeletExtraArgs = nd.KubeArgs.KubeletExtraArgs
} else {
log.Printf("No cloud provider specified - not loading...")
}

return nil
}

func stringToMap(args string) map[string]string {
argsMap := map[string]string{}

f := func(c rune) bool {
return c == '=' || c == ' '
}

argsAry := strings.Split(args, ",")
for _, arg := range argsAry {
// Separate into fields with func.
argItemAry := strings.FieldsFunc(arg, f)
if len(argItemAry) == 2 {
argsMap[argItemAry[0]] = argItemAry[1]
}
if len(argItemAry) == 1 {
argsMap[argItemAry[0]] = ""
}
}
return argsMap
}
9 changes: 9 additions & 0 deletions pkg/kmm/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ func (k *Kmm) CreateAndStartKubelet(master bool) error {
s = append(s, fmt.Sprintf("%s=%s", k, v))
}
nodeLables := strings.Join(s, ",")
s = []string{}
for k, v := range k.NodeTaints {
s = append(s, fmt.Sprintf("%s=%s", k, v))
}
nodeTaints := strings.Join(s, ",")

// Render kubelet.service
data := struct {
CloudProviderName string
IsMaster bool
KubeVersion string
KubeletExtraArgs string
NodeLabels string
NodeTaints string
}{
CloudProviderName: k.KubeadmCfg.CloudProvider,
IsMaster: master,
KubeVersion: k.KubeadmCfg.KubeVersion,
KubeletExtraArgs: k.KubeletExtraArgs,
NodeLabels: nodeLables,
NodeTaints: nodeTaints,
}
t := template.Must(template.New("kubeletUnit").Parse(kubeletTemplate))
var b bytes.Buffer
Expand Down
16 changes: 10 additions & 6 deletions pkg/kmm/kubelet_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Environment="RKT_OPTS=\
--volume var-log,kind=host,source=/var/log --mount volume=var-log,target=/var/log \
--volume var-lib-cni,kind=host,source=/var/lib/cni --mount volume=var-lib-cni,target=/var/lib/cni"
EnvironmentFile=/etc/environment
{{if not .IsMaster }}
{{ if not .IsMaster }}
EnvironmentFile=/etc/kubernetes/keto-token.env
{{end}}
{{ end }}
ExecStartPre=/bin/mkdir -p /etc/kubernetes/manifests
ExecStartPre=/bin/mkdir -p /etc/cni/net.d
ExecStartPre=/bin/mkdir -p /opt/cni/bin
Expand All @@ -35,9 +35,9 @@ ExecStart=/usr/lib/coreos/kubelet-wrapper \
--cluster-dns=10.96.0.10 \
--cluster-domain=cluster.local \
--cni-conf-dir=/etc/cni/net.d \
{{if not .IsMaster }} \
{{ if not .IsMaster }} \
--experimental-bootstrap-kubeconfig=${KETO_TOKENS_KUBELET_CONF} \
{{end}} \
{{ end }} \
--hostname-override="${COREOS_PRIVATE_IPV4}" \
--image-gc-high-threshold=60 \
--image-gc-low-threshold=40 \
Expand All @@ -46,10 +46,14 @@ ExecStart=/usr/lib/coreos/kubelet-wrapper \
--logtostderr=true \
--network-plugin=cni \
--node-labels={{ .NodeLabels }} \
{{ if .NodeTaints }} \
--register-with-taints={{ .NodeTaints }} \
{{ end }} \
--pod-manifest-path=/etc/kubernetes/manifests \
{{if .IsMaster }} \
{{ if .IsMaster }} \
--register-schedulable=false \
{{end}} \
{{ end }} \
{{ .KubeletExtraArgs }} \
--require-kubeconfig=true \
--system-reserved=cpu=50m,memory=100Mi
Expand Down
26 changes: 16 additions & 10 deletions pkg/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ var (
CaKeyFile string = kubeadmconstants.KubernetesDir + "/pki" + "/" + kubeadmconstants.CACertAndKeyBaseName + ".key"
)

// Config represents runtime params cfg structure.
// Config represents runtime params cfg structure.
type Config struct {
EtcdClientConfig etcd.Client
CaCert string
CaKey string
APIServer *url.URL
KubeletID string
CloudProvider string
KubeVersion string
MasterCount uint
PodNetworkCidr string
EtcdClientConfig etcd.Client
CaCert string
CaKey string
APIServer *url.URL
KubeletID string
CloudProvider string
KubeVersion string
MasterCount uint
PodNetworkCidr string
APIServerExtraArgs map[string]string
ControllerManagerExtraArgs map[string]string
SchedulerExtraArgs map[string]string
}

// SharedAssets - the data to be shared between all kubernetes masters
Expand Down Expand Up @@ -224,6 +227,9 @@ func GetKubeadmCfg(kmmCfg Config) (cfg *kubeadmapi.MasterConfiguration, err erro
cfg.Networking.DNSDomain = constants.DefaultServiceDNSDomain
cfg.Networking.ServiceSubnet = constants.DefaultServicesSubnet
cfg.Networking.PodSubnet = kmmCfg.PodNetworkCidr
cfg.APIServerExtraArgs = kmmCfg.APIServerExtraArgs
cfg.ControllerManagerExtraArgs = kmmCfg.ControllerManagerExtraArgs
cfg.SchedulerExtraArgs = kmmCfg.SchedulerExtraArgs
return cfg, nil
}

Expand Down

0 comments on commit 5c416e8

Please sign in to comment.