Repository: kubernetes/minikube
Pull request #16912 (2023-07-18 21:56:05)

cni: Fix regression in auto selection
Fixes https://github.com/kubernetes/minikube/issues/16911

**Before:**
```
$ minikube start --driver docker --container-runtime=docker --version=v1.26.6
...
I0718 14:49:13.457621   40145 cni.go:149] "docker" driver + "docker" runtime found, recommending kindnet
...
```

**After:**
```
$ minikube start --driver docker --container-runtime=docker --version=v1.26.6
...
I0718 14:55:13.614039   41957 cni.go:158] "docker" driver + "docker" container runtime found on kubernetes v1.24+, recommending bridge
...
```

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes/minikube/pull/16912#" title="Author self-approved">spowelljr</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes%2Fminikube).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes/minikube/blob/master/OWNERS)~~ [spowelljr]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/pkg/minikube/cni/cni.go b/pkg/minikube/cni/cni.go
index 00e1c7174..0c46aa430 100644
--- a/pkg/minikube/cni/cni.go
+++ b/pkg/minikube/cni/cni.go
@@ -87,7 +87,7 @@ func New(cc *config.ClusterConfig) (Manager, error) {
 	var err error
 	switch cc.KubernetesConfig.CNI {
 	case "", "auto":
-		cnm, err = chooseDefault(*cc)
+		cnm = chooseDefault(*cc)
 	case "false":
 		cnm = Disabled{cc: *cc}
 	case "kindnet", "true":
@@ -117,40 +117,34 @@ func IsDisabled(cc config.ClusterConfig) bool {
 		return true
 	}
 
-	def, err := chooseDefault(cc)
-	if err == nil && def.String() == "Disabled" {
+	if chooseDefault(cc).String() == "Disabled" {
 		return true
 	}
 	return false
 }
 
-func chooseDefault(cc config.ClusterConfig) (Manager, error) {
+func chooseDefault(cc config.ClusterConfig) Manager {
 	// For backwards compatibility with older profiles using --enable-default-cni
 	if cc.KubernetesConfig.EnableDefaultCNI {
 		klog.Infof("EnableDefaultCNI is true, recommending bridge")
-		return Bridge{}, nil
+		return Bridge{}
 	}
 
 	if len(cc.Nodes) > 1 || cc.MultiNodeRequested {
 		// Enables KindNet CNI in master in multi node cluster, This solves the network problem
 		// inside pod for multi node clusters. See https://github.com/kubernetes/minikube/issues/9838.
 		klog.Infof("%d nodes found, recommending kindnet", len(cc.Nodes))
-		return KindNet{cc: cc}, nil
+		return KindNet{cc: cc}
 	}
 
-	version, err := util.ParseKubernetesVersion(cc.KubernetesConfig.KubernetesVersion)
-	if err != nil {
-		return nil, err
-	}
-
-	if cc.KubernetesConfig.ContainerRuntime != constants.Docker || version.GTE(semver.MustParse("1.24.0-alpha.2")) {
+	if cc.KubernetesConfig.ContainerRuntime != constants.Docker {
 		// Always use CNI when running with CRI (without dockershim)
 		if driver.IsKIC(cc.Driver) {
 			klog.Infof("%q driver + %q runtime found, recommending kindnet", cc.Driver, cc.KubernetesConfig.ContainerRuntime)
-			return KindNet{cc: cc}, nil
+			return KindNet{cc: cc}
 		}
 		klog.Infof("%q driver + %q runtime found, recommending bridge", cc.Driver, cc.KubernetesConfig.ContainerRuntime)
-		return Bridge{cc: cc}, nil
+		return Bridge{cc: cc}
 	}
 
 	// for docker container runtime and k8s v1.24+ where dockershim and kubenet were removed, we fallback to bridge cni for cri-docker(d)
@@ -162,11 +156,11 @@ func chooseDefault(cc config.ClusterConfig) (Manager, error) {
 	kv, err := util.ParseKubernetesVersion(cc.KubernetesConfig.KubernetesVersion)
 	if err == nil && kv.GTE(semver.MustParse("1.24.0-alpha.2")) {
 		klog.Infof("%q driver + %q container runtime found on kubernetes v1.24+, recommending bridge", cc.Driver, cc.KubernetesConfig.ContainerRuntime)
-		return Bridge{cc: cc}, nil
+		return Bridge{cc: cc}
 	}
 
 	klog.Infof("CNI unnecessary in this configuration, recommending no CNI")
-	return Disabled{cc: cc}, nil
+	return Disabled{cc: cc}
 }
 
 // manifestPath returns the path to the CNI manifest
diff --git a/translations/fr.json b/translations/fr.json
index 9b56de3a8..808199d06 100644
--- a/translations/fr.json
+++ b/translations/fr.json
@@ -651,7 +651,7 @@
 	"Successfully purged minikube directory located at - [{{.minikubeDirectory}}]": "Répertoire minikube purgé avec succès situé à - [{{.minikubeDirectory}}]",
 	"Successfully started node {{.name}}!": "Nœud {{.name}} démarré avec succès !",
 	"Successfully stopped node {{.name}}": "Nœud {{.name}} arrêté avec succès",
-	"Successfully unblocked bootpd process from firewall, retrying": "Déblocage réussi du processus bootpd du pare-feu, nouvelle tentative",
+	"Successfully unblocked bootpd process from firewall, retrying": "",
 	"Suggestion: {{.advice}}": "Suggestion : {{.advice}}",
 	"System only has {{.size}}MiB available, less than the required {{.req}}MiB for Kubernetes": "Le système n'a que {{.size}} Mio disponibles, moins que les {{.req}} Mio requis pour Kubernetes",
 	"Tag images": "Marquer des images",
@@ -860,7 +860,7 @@
 	"Using rootless driver was required, but the current driver does not seem rootless": "L'utilisation d'un pilote sans root était nécessaire, mais le pilote actuel ne semble pas sans root",
 	"Using rootless {{.driver_name}} driver": "Utilisation du pilote {{.driver_name}} sans root",
 	"Using the '{{.runtime}}' runtime with the 'none' driver is an untested configuration!": "L'utilisation du runtime '{{.runtime}}' avec le pilote 'none' est une configuration non testée !",
-	"Using the docker-env command with the containerd runtime is a highly experimental feature, please provide feedback or contribute to make it better": "L'utilisation de la commande docker-env avec le runtime containerd est une fonctionnalité hautement expérimentale, veuillez fournir des commentaires ou contribuer à l'améliorer",
+	"Using the docker-env command with the containerd runtime is a highly experimental feature, please provide feedback or contribute to make it better": "",
 	"Using the {{.driver}} driver based on existing profile": "Utilisation du pilote {{.driver}} basé sur le profil existant",
 	"Using the {{.driver}} driver based on user configuration": "Utilisation du pilote {{.driver}} basé sur la configuration de l'utilisateur",
 	"Using {{.driver_name}} driver with root privileges": "Utilisation du pilote {{.driver_name}} avec le privilège root",
@@ -942,7 +942,7 @@
 	"dry-run mode. Validates configuration, but does not mutate system state": "mode simulation. Valide la configuration, mais ne modifie pas l'état du système",
 	"dry-run validation complete!": "validation de la simulation terminée !",
 	"enable failed": "échec de l'activation",
-	"enabled failed": "activation échouée",
+	"enabled failed": "",
 	"error creating clientset": "erreur lors de la création de l'ensemble de clients",
 	"error creating urls": "erreur lors de la création d'urls",
 	"error getting defaults: {{.error}}": "erreur lors de l'obtention des valeurs par défaut : {{.error}}",


Test patch:
diff --git a/pkg/minikube/cni/cni_test.go b/pkg/minikube/cni/cni_test.go
new file mode 100644
index 000000000..a8a01eaff
--- /dev/null
+++ b/pkg/minikube/cni/cni_test.go
@@ -0,0 +1,54 @@
+/*
+Copyright 2023 The Kubernetes Authors All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package cni
+
+import (
+	"testing"
+
+	"k8s.io/minikube/pkg/minikube/config"
+)
+
+func TestChooseDefault(t *testing.T) {
+	tests := []struct {
+		driver           string
+		containerRuntime string
+		version          string
+		want             string
+	}{
+		{"docker", "docker", "v1.23.0", "Disabled"},
+		{"docker", "docker", "v1.27.0", "bridge CNI"},
+		{"docker", "containerd", "v1.23.0", "CNI"},
+		{"docker", "containerd", "v1.27.0", "CNI"},
+		{"qemu", "docker", "v1.23.0", "Disabled"},
+		{"qemu", "docker", "v1.27.0", "bridge CNI"},
+		{"qemu", "containerd", "v1.23.0", "bridge CNI"},
+		{"qemu", "containerd", "v1.27.0", "bridge CNI"},
+	}
+	for _, tc := range tests {
+		cc := config.ClusterConfig{
+			Driver: tc.driver,
+			KubernetesConfig: config.KubernetesConfig{
+				ContainerRuntime:  tc.containerRuntime,
+				KubernetesVersion: tc.version,
+			},
+		}
+		got := chooseDefault(cc).String()
+		if got != tc.want {
+			t.Errorf("chooseDefault(%+v) = %s; want = %s", cc, got, tc.want)
+		}
+	}
+}