Skip to content

Commit cdc456a

Browse files
authored
Merge pull request #8570 from tstromberg/cni-split2
CNI: Update CRIO netconfig with matching subnet
2 parents c6769df + f192df8 commit cdc456a

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

pkg/minikube/bootstrapper/kubeadm/kubeadm.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ func (k *Bootstrapper) applyCNI(cfg config.ClusterConfig) error {
282282
}
283283

284284
if cfg.KubernetesConfig.ContainerRuntime == "crio" {
285-
if err := sysinit.New(k.c).Restart("crio"); err != nil {
286-
glog.Errorf("failed to restart CRI: %v", err)
285+
if err := cruntime.UpdateCRIONet(k.c, cnm.CIDR()); err != nil {
286+
return errors.Wrap(err, "update crio")
287287
}
288288
}
289289

pkg/minikube/cni/bridge.go

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func (c Bridge) Apply(r Runner) error {
8282
if err := r.Copy(f); err != nil {
8383
return errors.Wrapf(err, "copy")
8484
}
85+
8586
return nil
8687
}
8788

pkg/minikube/cruntime/crio.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cruntime
1818

1919
import (
2020
"fmt"
21+
"net"
2122
"os/exec"
2223
"strings"
2324

@@ -96,7 +97,6 @@ func (r *CRIO) Available() error {
9697
return errors.Wrapf(err, "check crio available.")
9798
}
9899
return nil
99-
100100
}
101101

102102
// Active returns if CRIO is active on the host
@@ -224,3 +224,30 @@ func (r *CRIO) Preload(cfg config.KubernetesConfig) error {
224224
}
225225
return fmt.Errorf("not yet implemented for %s", r.Name())
226226
}
227+
228+
// UpdateCRIONet updates CRIO CNI network configuration and restarts it
229+
func UpdateCRIONet(r CommandRunner, cidr string) error {
230+
glog.Infof("Updating CRIO to use CIDR: %q", cidr)
231+
ip, net, err := net.ParseCIDR(cidr)
232+
if err != nil {
233+
return errors.Wrap(err, "parse cidr")
234+
}
235+
236+
oldNet := "10.88.0.0/16"
237+
oldGw := "10.88.0.1"
238+
239+
newNet := cidr
240+
241+
// Assume gateway is first IP in netmask (10.244.0.1, for instance)
242+
newGw := ip.Mask(net.Mask)
243+
newGw[3]++
244+
245+
// Update subnets used by 100-crio-bridge.conf & 87-podman-bridge.conflist
246+
// avoids: "Error adding network: failed to set bridge addr: could not add IP address to \"cni0\": permission denied"
247+
sed := fmt.Sprintf("sed -i -e s#%s#%s# -e s#%s#%s# /etc/cni/net.d/*bridge*", oldNet, newNet, oldGw, newGw)
248+
if _, err := r.RunCmd(exec.Command("sudo", "/bin/bash", "-c", sed)); err != nil {
249+
glog.Errorf("netconf update failed: %v", err)
250+
}
251+
252+
return sysinit.New(r).Restart("crio")
253+
}

test/integration/net_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestNetworkPlugins(t *testing.T) {
6666
profile := UniqueProfileName(tc.name)
6767

6868
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
69-
defer Cleanup(t, profile, cancel)
69+
defer CleanupWithLogs(t, profile, cancel)
7070

7171
startArgs := append([]string{"start", "-p", profile, "--memory=1800", "--alsologtostderr", "--wait=true", "--wait-timeout=25m"}, tc.args...)
7272
startArgs = append(startArgs, StartArgs()...)
@@ -129,6 +129,10 @@ func TestNetworkPlugins(t *testing.T) {
129129
})
130130
}
131131

132+
if strings.Contains(tc.name, "weave") {
133+
t.Skipf("skipping remaining tests for weave, as results can be unpredictable")
134+
}
135+
132136
if !t.Failed() {
133137
t.Run("DNS", func(t *testing.T) {
134138
var rr *RunResult
@@ -166,10 +170,6 @@ func TestNetworkPlugins(t *testing.T) {
166170

167171
if !t.Failed() {
168172
t.Run("HairPin", func(t *testing.T) {
169-
if strings.Contains(tc.name, "weave") {
170-
t.Skipf("skipping: weavenet hairpin results vary substantially across environments")
171-
}
172-
173173
tryHairPin := func() error {
174174
_, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "exec", "deployment/netcat", "--", "/bin/sh", "-c", "nc -w 5 -i 5 -z netcat 8080"))
175175
return err

0 commit comments

Comments
 (0)