Skip to content

Commit

Permalink
Add config parameter for the cri socket path (#3154)
Browse files Browse the repository at this point in the history
* Add config parameter for the cri socket path

Closes #3153

* Remove stray newline, when not using criSocket

* Add the --cri-socket parameter to configuration

Also fix the syntax for CRI-O, adding unix://
  • Loading branch information
afbjorklund authored and balopat committed Nov 15, 2018
1 parent 3deef53 commit 2ceec0d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(&registryMirror, "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.")
Expand Down
6 changes: 4 additions & 2 deletions docs/alternative_runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ Or you can use the extended version:
```shell
$ minikube start \
--network-plugin=cni \
--cri-socket=/var/run/crio/crio.sock \
--extra-config=kubelet.container-runtime=remote \
--extra-config=kubelet.container-runtime-endpoint=/var/run/crio/crio.sock \
--extra-config=kubelet.image-service-endpoint=/var/run/crio/crio.sock
--extra-config=kubelet.container-runtime-endpoint=unix:///var/run/crio/crio.sock \
--extra-config=kubelet.image-service-endpoint=unix:///var/run/crio/crio.sock
```

### Using containerd
Expand All @@ -44,6 +45,7 @@ Or you can use the extended version:
```shell
$ minikube start \
--network-plugin=cni \
--cri-socket=/run/containerd/containerd.sock \
--extra-config=kubelet.container-runtime=remote \
--extra-config=kubelet.container-runtime-endpoint=unix:///run/containerd/containerd.sock \
--extra-config=kubelet.image-service-endpoint=unix:///run/containerd/containerd.sock
Expand Down
22 changes: 22 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,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) {
Expand Down Expand Up @@ -352,6 +370,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 {
Expand All @@ -372,6 +392,7 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) {
KubernetesVersion string
EtcdDataDir string
NodeName string
CRISocket string
ExtraArgs []ComponentExtraArgs
FeatureArgs map[string]bool
NoTaintMaster bool
Expand All @@ -383,6 +404,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, // That does not work with k8s 1.12+
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/bootstrapper/kubeadm/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ networking:
etcd:
dataDir: {{.EtcdDataDir}}
nodeName: {{.NodeName}}
{{range .ExtraArgs}}{{.Component}}:{{range $i, $val := printMapInOrder .Options ": " }}
{{if .CRISocket}}criSocket: {{.CRISocket}}
{{end}}{{range .ExtraArgs}}{{.Component}}:{{range $i, $val := printMapInOrder .Options ": " }}
{{$val}}{{end}}
{{end}}{{if .FeatureArgs}}featureGates: {{range $i, $val := .FeatureArgs}}
{{$i}}: {{$val}}{{end}}
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type KubernetesConfig struct {
APIServerIPs []net.IP
DNSDomain string
ContainerRuntime string
CRISocket string
NetworkPlugin string
FeatureGates string
ServiceCIDR string
Expand Down

0 comments on commit 2ceec0d

Please sign in to comment.