From 6b80986194c0ec525775e24d7fa973cd5c067ed0 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 2 Oct 2018 13:19:56 -0400 Subject: Update OCICNI vendor to e617a611 Includes necessary changes for static IPs. Signed-off-by: Matthew Heon --- .../github.com/cri-o/ocicni/pkg/ocicni/ocicni.go | 41 ++++++++++++++++------ vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go | 13 +++++++ 2 files changed, 43 insertions(+), 11 deletions(-) (limited to 'vendor') diff --git a/vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go b/vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go index 33a3ae063..dfc216389 100644 --- a/vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go +++ b/vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go @@ -3,6 +3,7 @@ package ocicni import ( "errors" "fmt" + "net" "os" "path" "sort" @@ -351,14 +352,14 @@ func (plugin *cniNetworkPlugin) getNetwork(name string) (*cniNetwork, error) { return net, nil } -func (plugin *cniNetworkPlugin) getDefaultNetworkName() string { +func (plugin *cniNetworkPlugin) GetDefaultNetworkName() string { plugin.RLock() defer plugin.RUnlock() return plugin.defaultNetName } func (plugin *cniNetworkPlugin) getDefaultNetwork() *cniNetwork { - defaultNetName := plugin.getDefaultNetworkName() + defaultNetName := plugin.GetDefaultNetworkName() if defaultNetName == "" { return nil } @@ -383,7 +384,7 @@ func (plugin *cniNetworkPlugin) Name() string { func (plugin *cniNetworkPlugin) forEachNetwork(podNetwork *PodNetwork, forEachFunc func(*cniNetwork, string, *PodNetwork) error) error { networks := podNetwork.Networks if len(networks) == 0 { - networks = append(networks, plugin.getDefaultNetworkName()) + networks = append(networks, plugin.GetDefaultNetworkName()) } for i, netName := range networks { // Interface names start at "eth0" and count up for each network @@ -408,7 +409,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) ([]cnitypes.Resu plugin.podLock(podNetwork).Lock() defer plugin.podUnlock(podNetwork) - _, err := plugin.loNetwork.addToNetwork(plugin.cacheDir, &podNetwork, "lo") + _, err := plugin.loNetwork.addToNetwork(plugin.cacheDir, &podNetwork, "lo", "") if err != nil { logrus.Errorf("Error while adding to cni lo network: %s", err) return nil, err @@ -416,7 +417,12 @@ func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) ([]cnitypes.Resu results := make([]cnitypes.Result, 0) if err := plugin.forEachNetwork(&podNetwork, func(network *cniNetwork, ifName string, podNetwork *PodNetwork) error { - result, err := network.addToNetwork(plugin.cacheDir, podNetwork, ifName) + ip := "" + if conf, ok := podNetwork.NetworkConfig[network.name]; ok { + ip = conf.IP + } + + result, err := network.addToNetwork(plugin.cacheDir, podNetwork, ifName, ip) if err != nil { logrus.Errorf("Error while adding pod to CNI network %q: %s", network.name, err) return err @@ -439,7 +445,12 @@ func (plugin *cniNetworkPlugin) TearDownPod(podNetwork PodNetwork) error { defer plugin.podUnlock(podNetwork) return plugin.forEachNetwork(&podNetwork, func(network *cniNetwork, ifName string, podNetwork *PodNetwork) error { - if err := network.deleteFromNetwork(plugin.cacheDir, podNetwork, ifName); err != nil { + ip := "" + if conf, ok := podNetwork.NetworkConfig[network.name]; ok { + ip = conf.IP + } + + if err := network.deleteFromNetwork(plugin.cacheDir, podNetwork, ifName, ip); err != nil { logrus.Errorf("Error while removing pod from CNI network %q: %s", network.name, err) return err } @@ -491,8 +502,8 @@ func (plugin *cniNetworkPlugin) GetPodNetworkStatus(podNetwork PodNetwork) ([]cn return results, nil } -func (network *cniNetwork) addToNetwork(cacheDir string, podNetwork *PodNetwork, ifName string) (cnitypes.Result, error) { - rt, err := buildCNIRuntimeConf(cacheDir, podNetwork, ifName) +func (network *cniNetwork) addToNetwork(cacheDir string, podNetwork *PodNetwork, ifName, ip string) (cnitypes.Result, error) { + rt, err := buildCNIRuntimeConf(cacheDir, podNetwork, ifName, ip) if err != nil { logrus.Errorf("Error adding network: %v", err) return nil, err @@ -509,8 +520,8 @@ func (network *cniNetwork) addToNetwork(cacheDir string, podNetwork *PodNetwork, return res, nil } -func (network *cniNetwork) deleteFromNetwork(cacheDir string, podNetwork *PodNetwork, ifName string) error { - rt, err := buildCNIRuntimeConf(cacheDir, podNetwork, ifName) +func (network *cniNetwork) deleteFromNetwork(cacheDir string, podNetwork *PodNetwork, ifName, ip string) error { + rt, err := buildCNIRuntimeConf(cacheDir, podNetwork, ifName, ip) if err != nil { logrus.Errorf("Error deleting network: %v", err) return err @@ -526,7 +537,7 @@ func (network *cniNetwork) deleteFromNetwork(cacheDir string, podNetwork *PodNet return nil } -func buildCNIRuntimeConf(cacheDir string, podNetwork *PodNetwork, ifName string) (*libcni.RuntimeConf, error) { +func buildCNIRuntimeConf(cacheDir string, podNetwork *PodNetwork, ifName, ip string) (*libcni.RuntimeConf, error) { logrus.Infof("Got pod network %+v", podNetwork) rt := &libcni.RuntimeConf{ @@ -542,6 +553,14 @@ func buildCNIRuntimeConf(cacheDir string, podNetwork *PodNetwork, ifName string) }, } + // Add requested static IP to CNI_ARGS + if ip != "" { + if tstIP := net.ParseIP(ip); tstIP == nil { + return nil, fmt.Errorf("unable to parse IP address %q", ip) + } + rt.Args = append(rt.Args, [2]string{"IP", ip}) + } + if len(podNetwork.PortMappings) == 0 { return rt, nil } diff --git a/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go b/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go index 8ca61657a..fed5d2f6a 100644 --- a/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go +++ b/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go @@ -24,6 +24,14 @@ type PortMapping struct { HostIP string `json:"hostIP"` } +// NetworkConfig is additional configuration for a single CNI network. +type NetworkConfig struct { + // IP is a static IP to be specified in the network. Can only be used + // with the hostlocal IP allocator. If left unset, an IP will be + // dynamically allocated. + IP string +} + // PodNetwork configures the network of a pod sandbox. type PodNetwork struct { // Name is the name of the sandbox. @@ -40,6 +48,11 @@ type PodNetwork struct { // Networks is a list of CNI network names to attach to the sandbox // Leave this list empty to attach the default network to the sandbox Networks []string + + // NetworkConfig is configuration specific to a single CNI network. + // It is optional, and can be omitted for some or all specified networks + // without issue. + NetworkConfig map[string]NetworkConfig } // CNIPlugin is the interface that needs to be implemented by a plugin -- cgit v1.2.3-54-g00ecf From b3cde231abb1fe5c70aaf18f6f7540e6a123ae9d Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 10 Oct 2018 11:47:25 -0400 Subject: Update OCICNI vendor to 2d2983e4 Signed-off-by: Matthew Heon --- vendor.conf | 2 +- vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'vendor') diff --git a/vendor.conf b/vendor.conf index ae1f367ff..88fc85777 100644 --- a/vendor.conf +++ b/vendor.conf @@ -14,7 +14,7 @@ github.com/containers/image 7a1eac5d1df2dbd73d8b71853ebce32d989fcae3 github.com/containers/storage 41294c85d97bef688e18f710402895dbecde3308 github.com/containers/psgo 5dde6da0bc8831b35243a847625bcf18183bd1ee github.com/coreos/go-systemd v14 -github.com/cri-o/ocicni e617a611e1755a5aa1014541d5074ff09352fe00 +github.com/cri-o/ocicni 2d2983e40c242322a56c22a903785e7f83eb378c github.com/cyphar/filepath-securejoin v0.2.1 github.com/davecgh/go-spew v1.1.0 github.com/docker/distribution 7a8efe719e55bbfaff7bc5718cdf0ed51ca821df diff --git a/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go b/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go index fed5d2f6a..d76094292 100644 --- a/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go +++ b/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go @@ -61,6 +61,10 @@ type CNIPlugin interface { // for a plugin by name, e.g. Name() string + // GetDefaultNetworkName returns the name of the plugin's default + // network. + GetDefaultNetworkName() string + // SetUpPod is the method called after the sandbox container of // the pod has been created but before the other containers of the // pod are launched. -- cgit v1.2.3-54-g00ecf