open-nomad/vendor/github.com/containerd/go-cni
Seth Hoenig 435c0d9fc8 deps: Switch to Go modules for dependency management
This PR switches the Nomad repository from using govendor to Go modules
for managing dependencies. Aspects of the Nomad workflow remain pretty
much the same. The usual Makefile targets should continue to work as
they always did. The API submodule simply defers to the parent Nomad
version on the repository, keeping the semantics of API versioning that
currently exists.
2020-06-02 14:30:36 -05:00
..
.travis.yml deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
cni.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
errors.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
helper.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
LICENSE ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
namespace.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
namespace_opts.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
opts.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
README.md ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
result.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
testutils.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
types.go ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00
vendor.conf ar: refactor network bridge config to use go-cni lib (#6255) 2019-09-04 16:33:25 -04:00

Build Status

go-cni

A generic CNI library to provide APIs for CNI plugin interactions. The library provides APIs to:

  • Load CNI network config from different sources
  • Setup networks for container namespace
  • Remove networks from container namespace
  • Query status of CNI network plugin initialization

go-cni aims to support plugins that implement Container Network Interface

Usage

func main() {
	id := "123456"
	netns := "/proc/9999/ns/net"
	defaultIfName := "eth0"
	// Initialize library
	l = gocni.New(gocni.WithMinNetworkCount(2),
		gocni.WithPluginConfDir("/etc/mycni/net.d"),
		gocni.WithPluginDir([]string{"/opt/mycni/bin", "/opt/cni/bin"}),
		gocni.WithDefaultIfName(defaultIfName))
	
	// Load the cni configuration
	err:= l.Load(gocni.WithLoNetwork, gocni.WithDefaultConf)
        if err != nil{
		log.Errorf("failed to load cni configuration: %v", err)
		return 
	}
	
	// Setup network for namespace.
	labels := map[string]string{
		"K8S_POD_NAMESPACE":          "namespace1",
		"K8S_POD_NAME":               "pod1",
		"K8S_POD_INFRA_CONTAINER_ID": id,
	}
	result, err := l.Setup(id, netns, gocni.WithLabels(labels))
	if err != nil {
		log.Errorf("failed to setup network for namespace %q: %v",id, err)
		return 
	}
	
	// Get IP of the default interface
	IP := result.Interfaces[defaultIfName].IPConfigs[0].IP.String()
	fmt.Printf("IP of the default interface %s:%s", defaultIfName, IP)
}

Project details

The go-cni is a containerd sub-project, licensed under the Apache 2.0 license. As a containerd sub-project, you will find the:

information in our containerd/project repository.