mirror of
https://github.com/clearlinux/rkt.git
synced 2026-09-01 11:26:05 +00:00
incorporating code review feedback
This commit is contained in:
@@ -37,7 +37,7 @@ echo "Building metadatasvc..."
|
||||
go build -o $GOBIN/metadatasvc ${REPO_PATH}/metadatasvc
|
||||
|
||||
echo "Building network plugins"
|
||||
for d in network/plugins/*; do
|
||||
for d in networking/plugins/*; do
|
||||
plugin=$(basename $d)
|
||||
echo " " $plugin
|
||||
go build -o $GOBIN/$plugin ${REPO_PATH}/$d
|
||||
|
||||
@@ -11,7 +11,9 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/rocket/network/util"
|
||||
"github.com/appc/spec/schema/types"
|
||||
|
||||
"github.com/coreos/rocket/networking/util"
|
||||
)
|
||||
|
||||
type options struct {
|
||||
@@ -89,7 +91,7 @@ func parseArgs(args string) (*options, error) {
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func AllocIP(contID, netConf, ifName, args string) (*net.IPNet, net.IP, error) {
|
||||
func AllocIP(contID types.UUID, netConf, ifName, args string) (*net.IPNet, net.IP, error) {
|
||||
opts, err := parseArgs(args)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -129,6 +131,6 @@ func AllocIP(contID, netConf, ifName, args string) (*net.IPNet, net.IP, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func DeallocIP(contID, netConf, ifName string, ipn *net.IPNet) error {
|
||||
func DeallocIP(contID types.UUID, netConf, ifName string, ipn *net.IPNet) error {
|
||||
return nil
|
||||
}
|
||||
@@ -12,7 +12,9 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/rocket/network/util"
|
||||
"github.com/appc/spec/schema/types"
|
||||
|
||||
"github.com/coreos/rocket/networking/util"
|
||||
)
|
||||
|
||||
type NetPlugin struct {
|
||||
@@ -60,7 +62,7 @@ func LoadNetPlugins() (map[string]*NetPlugin, error) {
|
||||
npPath := filepath.Join(RktNetPluginsPath, dent.Name())
|
||||
np, err := LoadNetPlugin(npPath)
|
||||
if err != nil {
|
||||
log.Printf("Loading %v: %v", npPath, err)
|
||||
log.Printf("Error loading %v: %v", npPath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -70,17 +72,17 @@ func LoadNetPlugins() (map[string]*NetPlugin, error) {
|
||||
return plugins, nil
|
||||
}
|
||||
|
||||
func (np *NetPlugin) Add(n *Net, contID, netns, args, ifName string) (*net.IPNet, error) {
|
||||
func (np *NetPlugin) Add(n *Net, contID types.UUID, netns, args, ifName string) (*net.IPNet, error) {
|
||||
switch {
|
||||
case np.Endpoint != "":
|
||||
return nil, execHTTP(np.Endpoint, "add", n.Name, contID, netns, n.Filename, args, ifName)
|
||||
return nil, execHTTP(np.Endpoint, "add", n.Name, contID.String(), netns, n.Filename, args, ifName)
|
||||
|
||||
default:
|
||||
if len(np.Command.Add) == 0 {
|
||||
return nil, fmt.Errorf("plugin does not define command.add")
|
||||
}
|
||||
|
||||
output, err := execCmd(np.Command.Add, n.Name, contID, netns, n.Filename, args, ifName)
|
||||
output, err := execCmd(np.Command.Add, n.Name, contID.String(), netns, n.Filename, args, ifName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -91,17 +93,17 @@ func (np *NetPlugin) Add(n *Net, contID, netns, args, ifName string) (*net.IPNet
|
||||
}
|
||||
}
|
||||
|
||||
func (np *NetPlugin) Del(n *Net, contID, netns, args, ifName string) error {
|
||||
func (np *NetPlugin) Del(n *Net, contID types.UUID, netns, args, ifName string) error {
|
||||
switch {
|
||||
case np.Endpoint != "":
|
||||
return execHTTP(np.Endpoint, "del", n.Name, contID, netns, n.Filename, args, ifName)
|
||||
return execHTTP(np.Endpoint, "del", n.Name, contID.String(), netns, n.Filename, args, ifName)
|
||||
|
||||
default:
|
||||
if len(np.Command.Del) == 0 {
|
||||
return fmt.Errorf("plugin does not define command.del")
|
||||
}
|
||||
|
||||
_, err := execCmd(np.Command.Del, n.Name, contID, netns, n.Filename, args, ifName)
|
||||
_, err := execCmd(np.Command.Del, n.Name, contID.String(), netns, n.Filename, args, ifName)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -121,8 +123,8 @@ func execCmd(cmd []string, netName, contID, netns, confFile, args, ifName string
|
||||
replaceAll(cmd, "{cont-id}", contID)
|
||||
replaceAll(cmd, "{netns}", netns)
|
||||
replaceAll(cmd, "{conf-file}", confFile)
|
||||
replaceAll(cmd, "{args}", args)
|
||||
replaceAll(cmd, "{if-name}", ifName)
|
||||
replaceAll(cmd, "{args}", args)
|
||||
|
||||
stdout := &bytes.Buffer{}
|
||||
|
||||
@@ -1,33 +1,28 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/coreos/rocket/network/util"
|
||||
"github.com/coreos/rocket/networking/util"
|
||||
)
|
||||
|
||||
const RktNetPath = "/etc/rkt-net.conf.d"
|
||||
const DefaultIPNet = "172.16.28.0/24"
|
||||
|
||||
type Net struct {
|
||||
util.Net
|
||||
args string
|
||||
}
|
||||
|
||||
var defaultNet Net
|
||||
const RktNetPath = "/etc/rkt-net.conf.d"
|
||||
const DefaultIPNet = "172.16.28.0/24"
|
||||
|
||||
func init() {
|
||||
defaultNet = Net{
|
||||
Net: util.Net{
|
||||
Name: "default",
|
||||
Type: "veth",
|
||||
},
|
||||
args: fmt.Sprintf("default,iprange=%v", DefaultIPNet),
|
||||
}
|
||||
var defaultNet = Net{
|
||||
Net: util.Net{
|
||||
Name: "default",
|
||||
Type: "veth",
|
||||
},
|
||||
args: "default,iprange=" + DefaultIPNet,
|
||||
}
|
||||
|
||||
func LoadNets() ([]Net, error) {
|
||||
@@ -59,5 +54,4 @@ func LoadNets() ([]Net, error) {
|
||||
|
||||
nets = append(nets, defaultNet)
|
||||
|
||||
return nets, nil
|
||||
}
|
||||
return nets, nil }
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/appc/spec/schema/types"
|
||||
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/vishvananda/netlink"
|
||||
|
||||
"github.com/coreos/rocket/network/util"
|
||||
"github.com/coreos/rocket/networking/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -25,7 +25,7 @@ type activeNet struct {
|
||||
ipn *net.IPNet
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
type Networking struct {
|
||||
MetadataIP net.IP
|
||||
|
||||
contID types.UUID
|
||||
@@ -36,9 +36,9 @@ type Network struct {
|
||||
plugins map[string]*NetPlugin
|
||||
}
|
||||
|
||||
func Setup(contID types.UUID) (*Network, error) {
|
||||
func Setup(contID types.UUID) (*Networking, error) {
|
||||
var err error
|
||||
n := Network{contID: contID}
|
||||
n := Networking{contID: contID}
|
||||
|
||||
defer func() {
|
||||
// cleanup on error
|
||||
@@ -82,7 +82,7 @@ func Setup(contID types.UUID) (*Network, error) {
|
||||
return &n, nil
|
||||
}
|
||||
|
||||
func (n *Network) Teardown() {
|
||||
func (n *Networking) Teardown() {
|
||||
// teardown everything in reverse order of setup.
|
||||
// this is called during error case as well so not
|
||||
// everything maybe setup.
|
||||
@@ -128,11 +128,11 @@ func basicNetNS() (hostNS, contNS *os.File, err error) {
|
||||
}
|
||||
|
||||
|
||||
func (n *Network) EnterHostNS() error {
|
||||
func (n *Networking) EnterHostNS() error {
|
||||
return util.SetNS(n.hostNS, syscall.CLONE_NEWNET)
|
||||
}
|
||||
|
||||
func (n *Network) EnterContNS() error {
|
||||
func (n *Networking) EnterContNS() error {
|
||||
return util.SetNS(n.contNS, syscall.CLONE_NEWNET)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func setupNets(contID types.UUID, netns string, plugins map[string]*NetPlugin, n
|
||||
for i, nt := range nets {
|
||||
plugin, ok := plugins[nt.Type]
|
||||
if !ok {
|
||||
err = fmt.Errorf("could not find network plugin %q\n", nt.Type)
|
||||
err = fmt.Errorf("could not find network plugin %q", nt.Type)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -155,9 +155,9 @@ func setupNets(contID types.UUID, netns string, plugins map[string]*NetPlugin, n
|
||||
|
||||
log.Printf("Executing net-plugin %v", nt.Type)
|
||||
|
||||
an.ipn, err = plugin.Add(&nt, contID.String(), netns, nt.args, an.ifName)
|
||||
an.ipn, err = plugin.Add(&nt, contID, netns, nt.args, an.ifName)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error adding network %q: %v\n", nt.Name, err)
|
||||
err = fmt.Errorf("error adding network %q: %v", nt.Name, err)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ func teardownNets(contID types.UUID, netns string, plugins map[string]*NetPlugin
|
||||
nt := nets[i]
|
||||
plugin := plugins[nt.Type]
|
||||
|
||||
err := plugin.Del(&nt.Net, contID.String(), netns, nt.args, nt.ifName)
|
||||
err := plugin.Del(&nt.Net, contID, netns, nt.args, nt.ifName)
|
||||
if err != nil {
|
||||
log.Printf("Error deleting %q: %v", nt.Name, err)
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/vishvananda/netlink"
|
||||
|
||||
"github.com/coreos/rocket/network/util"
|
||||
"github.com/coreos/rocket/networking/util"
|
||||
)
|
||||
|
||||
const defaultBrName = "rkt0"
|
||||
@@ -9,10 +9,11 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/appc/spec/schema/types"
|
||||
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/vishvananda/netlink"
|
||||
|
||||
"github.com/coreos/rocket/network/ipam"
|
||||
"github.com/coreos/rocket/network/util"
|
||||
"github.com/coreos/rocket/networking/ipam"
|
||||
"github.com/coreos/rocket/networking/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -35,7 +36,12 @@ func argsHasDefault(args string) bool {
|
||||
func cmdAdd(contID, netns, netConf, ifName, args string) error {
|
||||
var hostVethName string
|
||||
|
||||
ipn, gw, err := ipam.AllocIP(contID, netConf, ifName, args)
|
||||
cid, err := types.NewUUID(contID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error parsing ContainerID: %v", err)
|
||||
}
|
||||
|
||||
ipn, gw, err := ipam.AllocIP(*cid, netConf, ifName, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user