Skip to content

Commit fd549f3

Browse files
committed
fix default cni selection for cri-docker(d)
1 parent f3b3d4e commit fd549f3

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

pkg/minikube/cni/cni.go

+14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"strings"
2828
"time"
2929

30+
"github.com/blang/semver/v4"
3031
"github.com/pkg/errors"
3132
"k8s.io/klog/v2"
3233
"k8s.io/minikube/pkg/kapi"
@@ -36,6 +37,7 @@ import (
3637
"k8s.io/minikube/pkg/minikube/constants"
3738
"k8s.io/minikube/pkg/minikube/driver"
3839
"k8s.io/minikube/pkg/minikube/vmpath"
40+
"k8s.io/minikube/pkg/util"
3941
)
4042

4143
const (
@@ -160,6 +162,18 @@ func chooseDefault(cc config.ClusterConfig) Manager {
160162
return Bridge{cc: cc}
161163
}
162164

165+
// for docker container runtime and k8s v1.24+ where dockershim and kubenet were removed, we fallback to bridge cni for cri-docker(d)
166+
// ref: https://github.com/Mirantis/cri-dockerd#important
167+
// ref: https://github.com/Mirantis/cri-dockerd#to-use-with-kubernetes
168+
// note: currently, default cni that we "distribute" (in /etc/cni/net.d) is based on cri-o bridge, and
169+
// because it does not currently use portmap plugin, we pick "our" bridge instead (cri-o one will be disabled automatically)
170+
// ref: https://github.com/cri-o/cri-o/blob/f317b267ddef21aee5ffc92d890a77112b006815/contrib/cni/10-crio-bridge.conflist
171+
kv, err := util.ParseKubernetesVersion(cc.KubernetesConfig.KubernetesVersion)
172+
if err == nil && kv.GTE(semver.MustParse("1.24.0-alpha.2")) {
173+
klog.Infof("%q driver + %s runtime found, recommending bridge", cc.Driver, cc.KubernetesConfig.ContainerRuntime)
174+
return Bridge{cc: cc}
175+
}
176+
163177
klog.Infof("CNI unnecessary in this configuration, recommending no CNI")
164178
return Disabled{cc: cc}
165179
}

pkg/minikube/cruntime/containerd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (r *Containerd) Enable(disOthers bool, cgroupDriver string, inUserNamespace
229229
currentVersion, err := r.Version()
230230
if err == nil && semver.MustParse(targetVersion).GT(semver.MustParse(currentVersion)) {
231231
klog.Infof("replacing original containerd with v%s-%s-%s", targetVersion, runtime.GOOS, runtime.GOARCH)
232-
r.Init.ForceStop("containerd")
232+
_ = r.Init.ForceStop("containerd")
233233
if err := updateContainerdBinary(r.Runner, targetVersion, runtime.GOOS, runtime.GOARCH); err != nil {
234234
klog.Warningf("unable to replace original containerd with v%s-%s-%s: %v", targetVersion, runtime.GOOS, runtime.GOARCH, err)
235235
}

pkg/minikube/cruntime/cri.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func stopCRIContainers(cr CommandRunner, ids []string) error {
236236
// - docker stop --help => -t, --time int Seconds to wait for stop before killing it (default 10)
237237
// - crictl stop --help => --timeout value, -t value Seconds to wait to kill the container after a graceful stop is requested (default: 0)
238238
// to prevent "stuck" containers blocking ports (eg, "[ERROR Port-2379|2380]: Port 2379|2380 is in use" for etcd during "live" k8s upgrade)
239-
args := append([]string{crictl, "stop", "--timeout", "10"}, ids...)
239+
args := append([]string{crictl, "stop", "--timeout=10"}, ids...)
240240
c := exec.Command("sudo", args...)
241241
if _, err := cr.RunCmd(c); err != nil {
242242
return errors.Wrap(err, "crictl")

pkg/minikube/cruntime/cruntime_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func (f *FakeRunner) crictl(args []string, _ bool) (string, error) {
460460
return strings.Join(ids, "\n"), nil
461461
}
462462
case "stop":
463-
for _, id := range args[1:] {
463+
for _, id := range args[2:] {
464464
f.t.Logf("fake crictl: Stopping id %q", id)
465465
if f.containers[id] == "" {
466466
return "", fmt.Errorf("no such container")

pkg/minikube/node/start.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -423,17 +423,16 @@ func configureRuntimes(runner cruntime.CommandRunner, cc config.ClusterConfig, k
423423
if err := cni.ConfigureLoopback(runner); err != nil {
424424
klog.Warningf("unable to name loopback interface in dockerConfigureNetworkPlugin: %v", err)
425425
}
426-
// ensure all default CNI(s) are properly configured on each and every node (re)start
427-
// make sure container runtime is restarted afterwards for these changes to take effect
428-
if err := cni.ConfigureDefaultBridgeCNIs(runner, cc.KubernetesConfig.NetworkPlugin); err != nil {
429-
klog.Errorf("unable to disable preinstalled bridge CNI(s): %v", err)
430-
}
431-
432426
if kv.GTE(semver.MustParse("1.24.0-alpha.2")) {
433427
if err := cruntime.ConfigureNetworkPlugin(cr, runner, cc.KubernetesConfig.NetworkPlugin); err != nil {
434428
exit.Error(reason.RuntimeEnable, "Failed to configure network plugin", err)
435429
}
436430
}
431+
// ensure all default CNI(s) are properly configured on each and every node (re)start
432+
// make sure container runtime is restarted afterwards for these changes to take effect
433+
if err := cni.ConfigureDefaultBridgeCNIs(runner, cc.KubernetesConfig.NetworkPlugin); err != nil {
434+
klog.Errorf("unable to disable preinstalled bridge CNI(s): %v", err)
435+
}
437436

438437
// Preload is overly invasive for bare metal, and caching is not meaningful.
439438
// KIC handles preload elsewhere.

test/integration/addons_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestAddons(t *testing.T) {
7171
// MOCK_GOOGLE_TOKEN forces the gcp-auth webhook to use a mock token instead of trying to get a valid one from the credentials.
7272
os.Setenv("MOCK_GOOGLE_TOKEN", "true")
7373

74-
// for some reason, (Docker_Cloud_Shell) sets 'MINIKUBE_FORCE_SYSTEMD=true' while having cgroupfs set in docker (and probably os itself), which might make it unstable and occasionaly fail:
74+
// for some reason, (Docker_Cloud_Shell) sets 'MINIKUBE_FORCE_SYSTEMD=true' while having cgroupfs set in docker (and probably os itself), which might make it unstable and occasionally fail:
7575
// - I1226 15:05:24.834294 11286 out.go:177] - MINIKUBE_FORCE_SYSTEMD=true
7676
// - I1226 15:05:25.070037 11286 info.go:266] docker info: {... CgroupDriver:cgroupfs ...}
7777
// ref: https://storage.googleapis.com/minikube-builds/logs/15463/27154/Docker_Cloud_Shell.html

0 commit comments

Comments
 (0)