@@ -18,6 +18,7 @@ package cruntime
18
18
19
19
import (
20
20
"fmt"
21
+ "net"
21
22
"os/exec"
22
23
"strings"
23
24
@@ -96,7 +97,6 @@ func (r *CRIO) Available() error {
96
97
return errors .Wrapf (err , "check crio available." )
97
98
}
98
99
return nil
99
-
100
100
}
101
101
102
102
// Active returns if CRIO is active on the host
@@ -224,3 +224,30 @@ func (r *CRIO) Preload(cfg config.KubernetesConfig) error {
224
224
}
225
225
return fmt .Errorf ("not yet implemented for %s" , r .Name ())
226
226
}
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
+ }
0 commit comments