Skip to content

Commit d3afc6b

Browse files
Merge pull request #10741 from Luap99/test-ocicni
Do not use inotify for OCICNI
2 parents 1b27234 + e014608 commit d3afc6b

File tree

6 files changed

+71
-44
lines changed

6 files changed

+71
-44
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/containers/storage v1.32.3
2121
github.com/coreos/go-systemd/v22 v22.3.2
2222
github.com/coreos/stream-metadata-go v0.0.0-20210225230131-70edb9eb47b3
23-
github.com/cri-o/ocicni v0.2.1-0.20210301205850-541cf7c703cf
23+
github.com/cri-o/ocicni v0.2.1-0.20210621164014-d0acc7862283
2424
github.com/cyphar/filepath-securejoin v0.2.2
2525
github.com/davecgh/go-spew v1.1.1
2626
github.com/digitalocean/go-qemu v0.0.0-20210209191958-152a1535e49f

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
271271
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
272272
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
273273
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
274-
github.com/cri-o/ocicni v0.2.1-0.20210301205850-541cf7c703cf h1:k2wrxBiBseRfOD7h+9fABEuesABBQuUuW5fWwpARbeI=
275-
github.com/cri-o/ocicni v0.2.1-0.20210301205850-541cf7c703cf/go.mod h1:vingr1ztOAzP2WyTgGbpMov9dFhbjNxdLtDv0+PhAvY=
274+
github.com/cri-o/ocicni v0.2.1-0.20210621164014-d0acc7862283 h1:7FyIYKksGvRF8XjMkG5T6uIxg8PcgZoPyO+f6kHT5+s=
275+
github.com/cri-o/ocicni v0.2.1-0.20210621164014-d0acc7862283/go.mod h1:vingr1ztOAzP2WyTgGbpMov9dFhbjNxdLtDv0+PhAvY=
276276
github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg=
277277
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
278278
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ=

libpod/networking_linux.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const (
4646

4747
// rootlessCNINSName is the file name for the rootless network namespace bind mount
4848
rootlessCNINSName = "rootless-cni-ns"
49+
50+
// persistentCNIDir is the directory where the CNI files are stored
51+
persistentCNIDir = "/var/lib/cni"
4952
)
5053

5154
// Get an OCICNI network config
@@ -150,14 +153,31 @@ func (r *RootlessCNI) Do(toRun func() error) error {
150153
}
151154
}
152155

153-
// cni plugins need access to /var and /run
154-
runDir := filepath.Join(r.dir, "run")
155-
varDir := filepath.Join(r.dir, "var")
156+
// cni plugins need access to /var/lib/cni and /run
157+
varDir := ""
158+
varTarget := persistentCNIDir
159+
// we can only mount to a target dir which exists, check /var/lib/cni recursively
160+
// while we could always use /var there are cases where a user might store the cni
161+
// configs under /var/custom and this would break
162+
for {
163+
if _, err := os.Stat(varTarget); err == nil {
164+
varDir = filepath.Join(r.dir, strings.TrimPrefix(varTarget, "/"))
165+
break
166+
}
167+
varTarget = filepath.Base(varTarget)
168+
if varTarget == "/" {
169+
break
170+
}
171+
}
172+
if varDir == "" {
173+
return errors.New("failed to stat /var directory")
174+
}
156175
// make sure to mount var first
157-
err = unix.Mount(varDir, "/var", "none", unix.MS_BIND, "")
176+
err = unix.Mount(varDir, varTarget, "none", unix.MS_BIND, "")
158177
if err != nil {
159-
return errors.Wrap(err, "failed to mount /var for rootless cni")
178+
return errors.Wrapf(err, "failed to mount %s for rootless cni", varTarget)
160179
}
180+
runDir := filepath.Join(r.dir, "run")
161181
// recursive mount to keep the netns mount
162182
err = unix.Mount(runDir, "/run", "none", unix.MS_BIND|unix.MS_REC, "")
163183
if err != nil {
@@ -385,7 +405,7 @@ func (r *Runtime) GetRootlessCNINetNs(new bool) (*RootlessCNI, error) {
385405

386406
// create cni directories to store files
387407
// they will be bind mounted to the correct location in a extra mount ns
388-
err = os.MkdirAll(filepath.Join(cniDir, "var"), 0700)
408+
err = os.MkdirAll(filepath.Join(cniDir, strings.TrimPrefix(persistentCNIDir, "/")), 0700)
389409
if err != nil {
390410
return nil, errors.Wrap(err, "could not create rootless-cni var directory")
391411
}
@@ -1043,7 +1063,7 @@ func resultToBasicNetworkConfig(result *cnitypes.Result) (define.InspectBasicNet
10431063
// after itself on an unclean reboot. Return what we're pretty sure is the path
10441064
// to CNI's internal files (it's not really exposed to us).
10451065
func getCNINetworksDir() (string, error) {
1046-
return "/var/lib/cni/networks", nil
1066+
return filepath.Join(persistentCNIDir, "networks"), nil
10471067
}
10481068

10491069
type logrusDebugWriter struct {

libpod/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
468468
}
469469

470470
// Set up the CNI net plugin
471-
netPlugin, err := ocicni.InitCNI(runtime.config.Network.DefaultNetwork, runtime.config.Network.NetworkConfigDir, runtime.config.Network.CNIPluginDirs...)
471+
netPlugin, err := ocicni.InitCNINoInotify(runtime.config.Network.DefaultNetwork, runtime.config.Network.NetworkConfigDir, "", runtime.config.Network.CNIPluginDirs...)
472472
if err != nil {
473473
return errors.Wrapf(err, "error configuring CNI network plugin")
474474
}

vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go

Lines changed: 39 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ github.com/coreos/stream-metadata-go/fedoracoreos
254254
github.com/coreos/stream-metadata-go/fedoracoreos/internals
255255
github.com/coreos/stream-metadata-go/stream
256256
github.com/coreos/stream-metadata-go/stream/rhcos
257-
# github.com/cri-o/ocicni v0.2.1-0.20210301205850-541cf7c703cf
257+
# github.com/cri-o/ocicni v0.2.1-0.20210621164014-d0acc7862283
258258
github.com/cri-o/ocicni/pkg/ocicni
259259
# github.com/cyphar/filepath-securejoin v0.2.2
260260
github.com/cyphar/filepath-securejoin

0 commit comments

Comments
 (0)