Skip to content

Commit 17d8c00

Browse files
author
Samuel Ortiz
committed
ocihook: Use the passed netns annotation when set
When a runtime specify the labels.NetworkNamespace annotation, we use it over the passed Pid. That allows VM based runtimes to explictly use a networking namespace path they create. Fixes #787 Signed-off-by: Samuel Ortiz <s.ortiz@apple.com>
1 parent f17189a commit 17d8c00

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/ocihook/ocihook.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,21 @@ func loadSpec(bundle string) (*hookSpec, error) {
262262
}
263263

264264
func getNetNSPath(state *specs.State) (string, error) {
265-
if state.Pid == 0 {
266-
return "", errors.New("state.Pid is unset")
265+
// If we have a network-namespace annotation we use it over the passed Pid.
266+
netNsPath, netNsFound := state.Annotations[NetworkNamespace]
267+
if netNsFound {
268+
if _, err := os.Stat(netNsPath); err != nil {
269+
return "", err
270+
}
271+
272+
return netNsPath, nil
267273
}
274+
275+
if state.Pid == 0 && !netNsFound {
276+
return "", errors.New("Both state.Pid and the netNs annotation are unset")
277+
}
278+
279+
// We dont't have a networking namespace annotation, but we have a PID.
268280
s := fmt.Sprintf("/proc/%d/ns/net", state.Pid)
269281
if _, err := os.Stat(s); err != nil {
270282
return "", err

0 commit comments

Comments
 (0)