Skip to content

Commit 79d5ad9

Browse files
committed
update container state structure
This commit replaces the now deprecated `configs.HookState` struct with `*specs.State` structure in aim of achieving compatibility with the latest version of runc and libcontainer (as of this commit, v1.0.0-rc92). Signed-off-by: Alexander Jung <[email protected]>
1 parent 00d5d07 commit 79d5ad9

25 files changed

+22
-1322
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ require (
88
github.com/genuinetools/pkg v0.0.0-20180910213200-1c141f661797
99
github.com/godbus/dbus v4.1.0+incompatible // indirect
1010
github.com/onsi/gomega v1.4.2 // indirect
11-
github.com/opencontainers/runc v0.0.0-20180920170208-00dc70017d22
12-
github.com/opencontainers/runtime-spec v1.0.1 // indirect
11+
github.com/opencontainers/runtime-spec v1.0.1
1312
github.com/pmezard/go-difflib v1.0.0 // indirect
1413
github.com/sirupsen/logrus v1.0.6
1514
github.com/stretchr/testify v1.2.2 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
2020
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
2121
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
2222
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
23-
github.com/opencontainers/runc v0.0.0-20180920170208-00dc70017d22 h1:7SedAwoOg6rLvFs91xPmi3NTkhyqqA2zABaqZ2tgf/U=
24-
github.com/opencontainers/runc v0.0.0-20180920170208-00dc70017d22/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
2523
github.com/opencontainers/runtime-spec v1.0.1 h1:wY4pOY8fBdSIvs9+IDHC55thBuEulhzfSgKeC1yFvzQ=
2624
github.com/opencontainers/runtime-spec v1.0.1/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
2725
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/genuinetools/netns/network"
1313
"github.com/genuinetools/netns/version"
1414
"github.com/genuinetools/pkg/cli"
15-
"github.com/opencontainers/runc/libcontainer/configs"
15+
"github.com/opencontainers/runtime-spec/specs-go"
1616
"github.com/sirupsen/logrus"
1717
)
1818

@@ -81,12 +81,12 @@ func main() {
8181

8282
// Set the main program action.
8383
p.Action = func(ctx context.Context, args []string) error {
84-
hook, err := readHookData()
84+
s, err := readHookData()
8585
if err != nil {
8686
return err
8787
}
8888

89-
ip, err := client.Create(hook, brOpt, staticip)
89+
ip, err := client.Create(s, brOpt, staticip)
9090
if err != nil {
9191
return err
9292
}
@@ -103,20 +103,20 @@ func main() {
103103
p.Run()
104104
}
105105

106-
// readHookData decodes stdin as HookState.
107-
func readHookData() (hook configs.HookState, err error) {
106+
// readHookData decodes stdin as *spec.State.
107+
func readHookData() (s *specs.State, err error) {
108108
// Read hook data from stdin.
109109
b, err := ioutil.ReadAll(os.Stdin)
110110
if err != nil {
111-
return hook, fmt.Errorf("reading hook data from stdin failed: %v", err)
111+
return s, fmt.Errorf("reading hook data from stdin failed: %v", err)
112112
}
113113

114114
// Umarshal the hook state.
115-
if err := json.Unmarshal(b, &hook); err != nil {
116-
return hook, fmt.Errorf("unmarshaling stdin as HookState failed: %v", err)
115+
if err := json.Unmarshal(b, &s); err != nil {
116+
return s, fmt.Errorf("unmarshaling stdin as specs.State failed: %v", err)
117117
}
118118

119-
logrus.Debugf("hooks state: %#v", hook)
119+
logrus.Debugf("hooks state: %#v", s)
120120

121-
return hook, nil
121+
return s, nil
122122
}

network/create.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import (
77

88
"github.com/genuinetools/netns/bridge"
99
"github.com/genuinetools/netns/netutils"
10-
"github.com/opencontainers/runc/libcontainer/configs"
10+
"github.com/opencontainers/runtime-spec/specs-go"
1111
"github.com/sirupsen/logrus"
1212
"github.com/vishvananda/netlink"
1313
"github.com/vishvananda/netns"
1414
bolt "go.etcd.io/bbolt"
1515
)
1616

1717
// Create returns a container IP that was created with the given bridge name,
18-
// the settings from the HookState passed, and the bridge options.
19-
func (c *Client) Create(hook configs.HookState, brOpt bridge.Opt, staticip string) (net.IP, error) {
18+
// the settings from the spec.State passed, and the bridge options.
19+
func (c *Client) Create(s *specs.State, brOpt bridge.Opt, staticip string) (net.IP, error) {
2020
var nsip net.IP
2121
// Open the database.
2222
if err := c.openDB(false); err != nil {
@@ -32,9 +32,9 @@ func (c *Client) Create(hook configs.HookState, brOpt bridge.Opt, staticip strin
3232
}
3333

3434
// Create and attach local name to the bridge.
35-
localVethPair, err := c.vethPair(hook.Pid, c.opt.BridgeName)
35+
localVethPair, err := c.vethPair(s.Pid, c.opt.BridgeName)
3636
if err != nil {
37-
return nil, fmt.Errorf("getting vethpair for pid %d failed: %v", hook.Pid, err)
37+
return nil, fmt.Errorf("getting vethpair for pid %d failed: %v", s.Pid, err)
3838
}
3939
if err := netlink.LinkAdd(localVethPair); err != nil {
4040
return nil, fmt.Errorf("create veth pair named [ %#v ] failed: %v", localVethPair, err)
@@ -47,8 +47,8 @@ func (c *Client) Create(hook configs.HookState, brOpt bridge.Opt, staticip strin
4747
}
4848

4949
// Put peer interface into the network namespace of specified PID.
50-
if err := netlink.LinkSetNsPid(peer, hook.Pid); err != nil {
51-
return nil, fmt.Errorf("adding peer interface to network namespace of pid %d failed: %v", hook.Pid, err)
50+
if err := netlink.LinkSetNsPid(peer, s.Pid); err != nil {
51+
return nil, fmt.Errorf("adding peer interface to network namespace of pid %d failed: %v", s.Pid, err)
5252
}
5353

5454
// Bring the veth pair up.
@@ -83,7 +83,7 @@ func (c *Client) Create(hook configs.HookState, brOpt bridge.Opt, staticip strin
8383
if staticip != "" {
8484
nsip = net.ParseIP(staticip)
8585
} else {
86-
nsip, err = c.AllocateIP(hook.Pid)
86+
nsip, err = c.AllocateIP(s.Pid)
8787
}
8888

8989
if err != nil {
@@ -96,7 +96,7 @@ func (c *Client) Create(hook configs.HookState, brOpt bridge.Opt, staticip strin
9696
}
9797

9898
// Configure the interface in the network namespace.
99-
if err := c.configureInterface(localVethPair.PeerName, hook.Pid, newIP, ip.String()); err != nil {
99+
if err := c.configureInterface(localVethPair.PeerName, s.Pid, newIP, ip.String()); err != nil {
100100
return nil, err
101101
}
102102

network/create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99

1010
"github.com/genuinetools/netns/bridge"
11-
"github.com/opencontainers/runc/libcontainer/configs"
11+
"github.com/opencontainers/runtime-spec/specs-go"
1212
)
1313

1414
func TestCreateNetwork(t *testing.T) {
@@ -27,7 +27,7 @@ func TestCreateNetwork(t *testing.T) {
2727
}
2828
defer os.RemoveAll(defaultStateDir)
2929

30-
ip, err := c.Create(configs.HookState{
30+
ip, err := c.Create(specs.State{
3131
Pid: process.Pid,
3232
}, bridge.Opt{
3333
IPAddr: defaultBridgeIP,

vendor/github.com/opencontainers/runc/LICENSE

Lines changed: 0 additions & 191 deletions
This file was deleted.

vendor/github.com/opencontainers/runc/NOTICE

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)