From 9ec92ee1fa895d371f456236ea720eba23563036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 22 Sep 2018 23:37:13 +0200 Subject: [PATCH] Add config parameter for the cri socket path Closes #3153 --- cmd/minikube/cmd/start.go | 3 +++ pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 22 +++++++++++++++++++ .../bootstrapper/kubeadm/templates.go | 1 + pkg/minikube/config/types.go | 1 + 4 files changed, 27 insertions(+) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 3b9d136e3316..c0d8e7e7ba75 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -57,6 +57,7 @@ const ( kubernetesVersion = "kubernetes-version" hostOnlyCIDR = "host-only-cidr" containerRuntime = "container-runtime" + criSocket = "cri-socket" networkPlugin = "network-plugin" hypervVirtualSwitch = "hyperv-virtual-switch" kvmNetwork = "kvm-network" @@ -220,6 +221,7 @@ func runStart(cmd *cobra.Command, args []string) { DNSDomain: viper.GetString(dnsDomain), FeatureGates: viper.GetString(featureGates), ContainerRuntime: viper.GetString(containerRuntime), + CRISocket: viper.GetString(criSocket), NetworkPlugin: viper.GetString(networkPlugin), ServiceCIDR: pkgutil.DefaultServiceCIDR, ExtraOptions: extraOptions, @@ -398,6 +400,7 @@ func init() { startCmd.Flags().StringSliceVar(&insecureRegistry, "insecure-registry", nil, "Insecure Docker registries to pass to the Docker daemon. The default service CIDR range will automatically be added.") startCmd.Flags().StringSliceVar(®istryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon") startCmd.Flags().String(containerRuntime, "", "The container runtime to be used") + startCmd.Flags().String(criSocket, "", "The cri socket path to be used") startCmd.Flags().String(kubernetesVersion, constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will use (ex: v1.2.3)") startCmd.Flags().String(networkPlugin, "", "The name of the network plugin") startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.") diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 5455f984c7ae..7cb53bea852d 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -234,6 +234,24 @@ func SetContainerRuntime(cfg map[string]string, runtime string) map[string]strin return cfg } +func GetCRISocket(path string, runtime string) string { + if path != "" { + glog.Infoln("Container runtime interface socket provided, using path.") + return path + } + + switch runtime { + case "crio", "cri-o": + path = "/var/run/crio/crio.sock" + case "containerd": + path = "/run/containerd/containerd.sock" + default: + path = "" + } + + return path +} + // NewKubeletConfig generates a new systemd unit containing a configured kubelet // based on the options present in the KubernetesConfig. func NewKubeletConfig(k8s config.KubernetesConfig) (string, error) { @@ -347,6 +365,8 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) { return "", errors.Wrap(err, "parsing kubernetes version") } + criSocket := GetCRISocket(k8s.CRISocket, k8s.ContainerRuntime) + // parses a map of the feature gates for kubeadm and component kubeadmFeatureArgs, componentFeatureArgs, err := ParseFeatureArgs(k8s.FeatureGates) if err != nil { @@ -367,6 +387,7 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) { KubernetesVersion string EtcdDataDir string NodeName string + CRISocket string ExtraArgs []ComponentExtraArgs FeatureArgs map[string]bool NoTaintMaster bool @@ -378,6 +399,7 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) { KubernetesVersion: k8s.KubernetesVersion, EtcdDataDir: "/data/minikube", //TODO(r2d4): change to something else persisted NodeName: k8s.NodeName, + CRISocket: criSocket, ExtraArgs: extraComponentConfig, FeatureArgs: kubeadmFeatureArgs, NoTaintMaster: false, diff --git a/pkg/minikube/bootstrapper/kubeadm/templates.go b/pkg/minikube/bootstrapper/kubeadm/templates.go index cbb3f2bce9d2..cb93b4d63195 100644 --- a/pkg/minikube/bootstrapper/kubeadm/templates.go +++ b/pkg/minikube/bootstrapper/kubeadm/templates.go @@ -38,6 +38,7 @@ networking: etcd: dataDir: {{.EtcdDataDir}} nodeName: {{.NodeName}} +{{if .CRISocket}}criSocket: {{.CRISocket}}{{end}} {{range .ExtraArgs}}{{.Component}}:{{range $i, $val := printMapInOrder .Options ": " }} {{$val}}{{end}} {{end}}{{if .FeatureArgs}}featureGates: {{range $i, $val := .FeatureArgs}} diff --git a/pkg/minikube/config/types.go b/pkg/minikube/config/types.go index 332810f7d0d4..2d805c13b912 100644 --- a/pkg/minikube/config/types.go +++ b/pkg/minikube/config/types.go @@ -63,6 +63,7 @@ type KubernetesConfig struct { APIServerIPs []net.IP DNSDomain string ContainerRuntime string + CRISocket string NetworkPlugin string FeatureGates string ServiceCIDR string