Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update container state structure #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ require (
github.com/genuinetools/pkg v0.0.0-20180910213200-1c141f661797
github.com/godbus/dbus v4.1.0+incompatible // indirect
github.com/onsi/gomega v1.4.2 // indirect
github.com/opencontainers/runc v0.0.0-20180920170208-00dc70017d22
github.com/opencontainers/runtime-spec v1.0.1 // indirect
github.com/opencontainers/runtime-spec v1.0.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.0.6
github.com/stretchr/testify v1.2.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opencontainers/runc v0.0.0-20180920170208-00dc70017d22 h1:7SedAwoOg6rLvFs91xPmi3NTkhyqqA2zABaqZ2tgf/U=
github.com/opencontainers/runc v0.0.0-20180920170208-00dc70017d22/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runtime-spec v1.0.1 h1:wY4pOY8fBdSIvs9+IDHC55thBuEulhzfSgKeC1yFvzQ=
github.com/opencontainers/runtime-spec v1.0.1/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
20 changes: 10 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/genuinetools/netns/network"
"github.com/genuinetools/netns/version"
"github.com/genuinetools/pkg/cli"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -81,12 +81,12 @@ func main() {

// Set the main program action.
p.Action = func(ctx context.Context, args []string) error {
hook, err := readHookData()
s, err := readHookData()
if err != nil {
return err
}

ip, err := client.Create(hook, brOpt, staticip)
ip, err := client.Create(s, brOpt, staticip)
if err != nil {
return err
}
Expand All @@ -103,20 +103,20 @@ func main() {
p.Run()
}

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

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

logrus.Debugf("hooks state: %#v", hook)
logrus.Debugf("hooks state: %#v", s)

return hook, nil
return s, nil
}
18 changes: 9 additions & 9 deletions network/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (

"github.com/genuinetools/netns/bridge"
"github.com/genuinetools/netns/netutils"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"github.com/vishvananda/netns"
bolt "go.etcd.io/bbolt"
)

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

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

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions network/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/genuinetools/netns/bridge"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runtime-spec/specs-go"
)

func TestCreateNetwork(t *testing.T) {
Expand All @@ -27,7 +27,7 @@ func TestCreateNetwork(t *testing.T) {
}
defer os.RemoveAll(defaultStateDir)

ip, err := c.Create(configs.HookState{
ip, err := c.Create(&specs.State{
Pid: process.Pid,
}, bridge.Opt{
IPAddr: defaultBridgeIP,
Expand Down
191 changes: 0 additions & 191 deletions vendor/github.com/opencontainers/runc/LICENSE

This file was deleted.

17 changes: 0 additions & 17 deletions vendor/github.com/opencontainers/runc/NOTICE

This file was deleted.

Loading