Repository: kubernetes/minikube
Pull request #15628 (2023-01-11 06:58:26)

Update kvm docker machine base image
- Updated `without_lxc` to `libvirt_without_lxc` as per https://gitlab.com/libvirt/libvirt-go-module/-/merge_requests/34
- Updated base image of `docker-machine-driver-kvm2-amd64` builder from Ubuntu 16.04 to Ubuntu 20.04 to fix libvirt build error
- Added `docker system prune -a --volumes -f` to cross build to clear out previous run artifacts

This makes the build on https://github.com/kubernetes/minikube/pull/15537 complete


Patch:
diff --git a/Makefile b/Makefile
index 7a90b8b9e..57e90590b 100644
--- a/Makefile
+++ b/Makefile
@@ -901,7 +901,7 @@ else
 		-buildvcs=false \
 		-installsuffix "static" \
 		-ldflags="$(KVM2_LDFLAGS)" \
-		-tags "libvirt.1.3.1 without_lxc" \
+		-tags "libvirt_without_lxc" \
 		-o $@ \
 		k8s.io/minikube/cmd/drivers/kvm
 endif
@@ -911,15 +911,14 @@ out/docker-machine-driver-kvm2-%:
 ifeq ($(MINIKUBE_BUILD_IN_DOCKER),y)
 	docker image inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE_AMD64) || $(MAKE) kvm-image-amd64
 	$(call DOCKER,$(KVM_BUILD_IMAGE_AMD64),/usr/bin/make $@ COMMIT=$(COMMIT))
-	# make extra sure that we are linking with the older version of libvirt (1.3.1)
-	test "`strings $@ | grep '^LIBVIRT_[0-9]' | sort | tail -n 1`" = "LIBVIRT_1.2.9"
 else
 	$(if $(quiet),@echo "  GO       $@")
 	$(Q)GOARCH=$* \
 	go build \
+	        -buildvcs=false \
 		-installsuffix "static" \
 		-ldflags="$(KVM2_LDFLAGS)" \
-		-tags "libvirt.1.3.1 without_lxc" \
+		-tags "libvirt_without_lxc" \
 		-o $@ \
 		k8s.io/minikube/cmd/drivers/kvm
 endif
diff --git a/hack/jenkins/minikube_cross_build_and_upload.sh b/hack/jenkins/minikube_cross_build_and_upload.sh
index 5f9a4effb..1c540fafa 100755
--- a/hack/jenkins/minikube_cross_build_and_upload.sh
+++ b/hack/jenkins/minikube_cross_build_and_upload.sh
@@ -39,6 +39,7 @@ declare -rx DEB_VER="$(make deb_version)"
 
 docker kill $(docker ps -q) || true
 docker rm $(docker ps -aq) || true
+docker system prune -a --volumes -f
 make -j 16 \
   all \
   minikube-darwin-arm64 \
diff --git a/installers/linux/kvm/Dockerfile.amd64 b/installers/linux/kvm/Dockerfile.amd64
index 41814301b..2c9e8ff7e 100644
--- a/installers/linux/kvm/Dockerfile.amd64
+++ b/installers/linux/kvm/Dockerfile.amd64
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-FROM gcr.io/gcp-runtimes/ubuntu_16_0_4
+FROM gcr.io/gcp-runtimes/ubuntu_20_0_4
 
 RUN apt-get update && apt-get install -y --no-install-recommends \
 		gcc \
diff --git a/pkg/minikube/download/image.go b/pkg/minikube/download/image.go
index 16dfa40bc..841596c19 100644
--- a/pkg/minikube/download/image.go
+++ b/pkg/minikube/download/image.go
@@ -36,7 +36,6 @@ import (
 	"k8s.io/minikube/pkg/minikube/detect"
 	"k8s.io/minikube/pkg/minikube/image"
 	"k8s.io/minikube/pkg/minikube/localpath"
-	"k8s.io/minikube/pkg/minikube/out"
 )
 
 var (
@@ -139,12 +138,6 @@ func ImageToCache(img string) error {
 		return errors.Wrap(err, "getting remote image")
 	}
 	klog.V(3).Infof("Writing image %v", tag)
-	if out.JSON {
-		if err := tarball.WriteToFile(f, tag, i); err != nil {
-			return errors.Wrap(err, "writing tarball image")
-		}
-		return nil
-	}
 	errchan := make(chan error)
 	p := pb.Full.Start64(0)
 	fn := image.Tag(ref.Name())
diff --git a/pkg/network/network.go b/pkg/network/network.go
index f0a35ed1a..f7772183d 100644
--- a/pkg/network/network.go
+++ b/pkg/network/network.go
@@ -28,7 +28,28 @@ import (
 
 const defaultReservationPeriod = 1 * time.Minute
 
-var reservedSubnets = sync.Map{}
+var (
+	reservedSubnets = sync.Map{}
+
+	// valid private network subnets (RFC1918)
+	privateSubnets = []net.IPNet{
+		// 10.0.0.0/8
+		{
+			IP:   []byte{10, 0, 0, 0},
+			Mask: []byte{255, 0, 0, 0},
+		},
+		// 172.16.0.0/12
+		{
+			IP:   []byte{172, 16, 0, 0},
+			Mask: []byte{255, 240, 0, 0},
+		},
+		// 192.168.0.0/16
+		{
+			IP:   []byte{192, 168, 0, 0},
+			Mask: []byte{255, 255, 0, 0},
+		},
+	}
+)
 
 // reservation of free private subnet is held for defined reservation period from createdAt time.
 type reservation struct {
@@ -45,7 +66,6 @@ type Parameters struct {
 	ClientMin string // second IP address
 	ClientMax string // last IP address before broadcast
 	Broadcast string // last IP address
-	IsPrivate bool   // whether the IP is private or not
 	Interface
 }
 
@@ -138,7 +158,6 @@ var inspect = func(addr string) (*Parameters, error) {
 	n.Netmask = net.IP(network.Mask).String() // dotted-decimal format ('a.b.c.d')
 	n.Prefix, _ = network.Mask.Size()
 	n.CIDR = network.String()
-	n.IsPrivate = network.IP.IsPrivate()
 
 	networkIP := binary.BigEndian.Uint32(network.IP)                      // IP address of network
 	networkMask := binary.BigEndian.Uint32(network.Mask)                  // network mask
@@ -186,6 +205,16 @@ var isSubnetTaken = func(subnet string) (bool, error) {
 	return false, nil
 }
 
+// isSubnetPrivate returns if subnet is private network.
+func isSubnetPrivate(subnet string) bool {
+	for _, ipnet := range privateSubnets {
+		if ipnet.Contains(net.ParseIP(subnet)) {
+			return true
+		}
+	}
+	return false
+}
+
 // IsUser returns if network is user.
 func IsUser(network string) bool {
 	return network == "user"
@@ -200,7 +229,7 @@ func FreeSubnet(startSubnet string, step, tries int) (*Parameters, error) {
 			return nil, err
 		}
 		subnet := n.IP
-		if n.IsPrivate {
+		if isSubnetPrivate(subnet) {
 			taken, err := isSubnetTaken(subnet)
 			if err != nil {
 				return nil, err
diff --git a/site/content/en/docs/tutorials/docker_desktop_replacement.md b/site/content/en/docs/tutorials/docker_desktop_replacement.md
index 66062ad9d..d6d9c3094 100644
--- a/site/content/en/docs/tutorials/docker_desktop_replacement.md
+++ b/site/content/en/docs/tutorials/docker_desktop_replacement.md
@@ -87,8 +87,6 @@ minikube start --container-runtime=docker --vm=true
 <h2 class="step"><span class="fa-stack fa-1x"><i class="fa fa-circle fa-stack-2x"></i><strong class="fa-stack-1x text-primary">3</strong></span>Point Docker CLI to minikube</h2>
 Use the `minikube docker-env` command to point your terminal's Docker CLI to the Docker instance inside minikube.
 
-<br>Note: the default profile name is `minikube`
-
 {{% tabs %}}
 {{% tab "bash/zsh" %}}
 ```


Test patch:
diff --git a/pkg/network/network_test.go b/pkg/network/network_test.go
index 5390bf5f3..f2d995d6c 100644
--- a/pkg/network/network_test.go
+++ b/pkg/network/network_test.go
@@ -22,6 +22,32 @@ import (
 	"time"
 )
 
+func TestIsSubnetPrivate(t *testing.T) {
+	tests := []struct {
+		subnet   string
+		expected bool
+	}{
+		{"9.255.255.255", false},
+		{"10.0.0.0", true},
+		{"10.255.255.255", true},
+		{"11.0.0.0", false},
+		{"172.15.255.255", false},
+		{"172.16.0.0", true},
+		{"172.31.255.255", true},
+		{"172.32.0.0", false},
+		{"192.167.255.255", false},
+		{"192.168.0.0", true},
+		{"192.168.255.255", true},
+		{"192.169.0.0", false},
+	}
+	for _, test := range tests {
+		got := isSubnetPrivate(test.subnet)
+		if got != test.expected {
+			t.Errorf("isSubnetPrivate(%q) = %t; expected = %t", test.subnet, got, test.expected)
+		}
+	}
+}
+
 func TestFreeSubnet(t *testing.T) {
 	reserveSubnet = func(subnet string, period time.Duration) bool { return true }
 
@@ -39,11 +65,6 @@ func TestFreeSubnet(t *testing.T) {
 
 	t.Run("FirstSubnetTaken", func(t *testing.T) {
 		count := 0
-		originalIsSubnetTaken := isSubnetTaken
-		defer func() {
-			isSubnetTaken = originalIsSubnetTaken
-		}()
-
 		isSubnetTaken = func(subnet string) (bool, error) {
 			count++
 			return count == 1, nil
@@ -62,17 +83,11 @@ func TestFreeSubnet(t *testing.T) {
 
 	t.Run("FirstSubnetIPV6NetworkFound", func(t *testing.T) {
 		count := 0
-		originalInspect := inspect
-		defer func() {
-			inspect = originalInspect
-		}()
-
 		inspect = func(addr string) (*Parameters, error) {
 			count++
-			p := &Parameters{IP: addr, IsPrivate: true}
+			p := &Parameters{IP: addr}
 			if count == 1 {
 				p.IP = "0.0.0.0"
-				p.IsPrivate = false
 			}
 			return p, nil
 		}