package legacy_examples

import "github.com/containernetworking/cni/pkg/version/legacy_examples"

Package legacy_examples contains sample code from prior versions of the CNI library, for use in verifying backwards compatibility.

Index

Variables

var ExpectedResult = &types020.Result{
	IP4: &types020.IPConfig{
		IP: net.IPNet{
			IP:   net.ParseIP("10.1.2.3"),
			Mask: net.CIDRMask(24, 32),
		},
		Gateway: net.ParseIP("10.1.2.1"),
		Routes: []types.Route{
			types.Route{
				Dst: net.IPNet{
					IP:   net.ParseIP("0.0.0.0"),
					Mask: net.CIDRMask(0, 32),
				},
				GW: net.ParseIP("10.1.0.1"),
			},
		},
	},
	DNS: types.DNS{
		Nameservers: []string{"8.8.8.8"},
		Domain:      "example.com",
	},
}

ExpectedResult is the current representation of the plugin result that is expected from each of the examples.

As we change the CNI spec, the Result type and this value may change. The text of the example plugins should not.

var NetConfs = map[string]string{
	"unversioned": `{
	"name": "default",
	"type": "ptp",
	"ipam": {
		"type": "host-local",
		"subnet": "10.1.2.0/24"
	}
}`,
	"0.1.0": "" /* 129 byte string literal not displayed */,
}

NetConfs are various versioned network configuration files. Examples should specify which version they expect

var V010 = Example{
	Name:          "example_v010",
	CNIRepoGitRef: "2c482f4",
	PluginSource:  "" /* 677 byte string literal not displayed */,
}

V010 acts like a CNI plugin from the v0.1.0 era

var V010_Runtime = ExampleRuntime{
	NetConfs: []string{"unversioned", "0.1.0"},
	Example: Example{
		Name:          "example_invoker_v010",
		CNIRepoGitRef: "c0d34c69",
		PluginSource:  "" /* 2134 byte string literal not displayed */,
	},
}

V010_Runtime creates a simple ptp network configuration, then executes libcni against the currently-built plugins.

Types

type Example

type Example struct {
	Name          string
	CNIRepoGitRef string
	PluginSource  string
}

An Example is a Git reference to the CNI repo and a Golang CNI plugin that builds against that version of the repo.

By convention, every Example plugin returns an ADD result that is semantically equivalent to the ExpectedResult.

func (Example) Build

func (e Example) Build() (string, error)

Build builds the example, returning the path to the binary

type ExampleRuntime

type ExampleRuntime struct {
	Example
	NetConfs []string // The network configuration names to pass
}

An ExampleRuntime is a small program that uses libcni to invoke a network plugin. It should call ADD and DELETE, verifying all intermediate steps and data structures.

Source Files

example_runtime.go examples.go

Version
v0.5.1
Published
Mar 22, 2017
Platform
js/wasm
Imports
7 packages
Last checked
4 hours ago

Tools for package owners.