"Deps": [
{
"ImportPath": "github.com/containernetworking/cni/libcni",
- "Comment": "v0.5.2",
- "Rev": "137b4975ecab6e1f0c24c1e3c228a50a3cfba75e"
+ "Comment": "v0.5.2-git49d814c",
+ "Rev": "49d814cf37bfea351a1caedd0c66825c9d6fca52"
},
{
"ImportPath": "github.com/containernetworking/cni/pkg/invoke",
- "Comment": "v0.5.2",
- "Rev": "137b4975ecab6e1f0c24c1e3c228a50a3cfba75e"
+ "Comment": "v0.5.2-git49d814c",
+ "Rev": "49d814cf37bfea351a1caedd0c66825c9d6fca52"
},
{
"ImportPath": "github.com/containernetworking/cni/pkg/skel",
- "Comment": "v0.5.2",
- "Rev": "137b4975ecab6e1f0c24c1e3c228a50a3cfba75e"
+ "Comment": "v0.5.2-git49d814c",
+ "Rev": "49d814cf37bfea351a1caedd0c66825c9d6fca52"
},
{
"ImportPath": "github.com/containernetworking/cni/pkg/types",
- "Comment": "v0.5.2",
- "Rev": "137b4975ecab6e1f0c24c1e3c228a50a3cfba75e"
+ "Comment": "v0.5.2-git49d814c",
+ "Rev": "49d814cf37bfea351a1caedd0c66825c9d6fca52"
},
{
"ImportPath": "github.com/containernetworking/cni/pkg/types/020",
- "Comment": "v0.5.2",
- "Rev": "137b4975ecab6e1f0c24c1e3c228a50a3cfba75e"
+ "Comment": "v0.5.2-git49d814c",
+ "Rev": "49d814cf37bfea351a1caedd0c66825c9d6fca52"
},
{
"ImportPath": "github.com/containernetworking/cni/pkg/types/current",
- "Comment": "v0.5.2",
- "Rev": "137b4975ecab6e1f0c24c1e3c228a50a3cfba75e"
+ "Comment": "v0.5.2-git49d814c",
+ "Rev": "49d814cf37bfea351a1caedd0c66825c9d6fca52"
},
{
"ImportPath": "github.com/containernetworking/cni/pkg/version",
- "Comment": "v0.5.2",
- "Rev": "137b4975ecab6e1f0c24c1e3c228a50a3cfba75e"
+ "Comment": "v0.5.2-git49d814c",
+ "Rev": "49d814cf37bfea351a1caedd0c66825c9d6fca52"
},
{
"ImportPath": "github.com/coreos/go-iptables/iptables",
pluginArgsStr = stringify(args.PluginArgs)
}
- env = append(env,
- "CNI_COMMAND="+args.Command,
- "CNI_CONTAINERID="+args.ContainerID,
- "CNI_NETNS="+args.NetNS,
- "CNI_ARGS="+pluginArgsStr,
- "CNI_IFNAME="+args.IfName,
- "CNI_PATH="+args.Path)
+ // Ensure that the custom values are first, so any value present in
+ // the process environment won't override them.
+ env = append([]string{
+ "CNI_COMMAND=" + args.Command,
+ "CNI_CONTAINERID=" + args.ContainerID,
+ "CNI_NETNS=" + args.NetNS,
+ "CNI_ARGS=" + pluginArgsStr,
+ "CNI_IFNAME=" + args.IfName,
+ "CNI_PATH=" + args.Path,
+ }, env...)
return env
}
if _, ok := err.(*exec.ExitError); ok {
emsg := types.Error{}
if perr := json.Unmarshal(output, &emsg); perr != nil {
- return fmt.Errorf("netplugin failed but error parsing its diagnostic message %q: %v", string(output), perr)
+ emsg.Msg = fmt.Sprintf("netplugin failed but error parsing its diagnostic message %q: %v", string(output), perr)
}
- details := ""
- if emsg.Details != "" {
- details = fmt.Sprintf("; %v", emsg.Details)
- }
- return fmt.Errorf("%v%v", emsg.Msg, details)
+ return &emsg
}
return err
"github.com/containernetworking/cni/pkg/types"
)
-const implementedSpecVersion string = "0.2.0"
+const ImplementedSpecVersion string = "0.2.0"
-var SupportedVersions = []string{"", "0.1.0", implementedSpecVersion}
+var SupportedVersions = []string{"", "0.1.0", ImplementedSpecVersion}
// Compatibility types for CNI version 0.1.0 and 0.2.0
func GetResult(r types.Result) (*Result, error) {
// We expect version 0.1.0/0.2.0 results
- result020, err := r.GetAsVersion(implementedSpecVersion)
+ result020, err := r.GetAsVersion(ImplementedSpecVersion)
if err != nil {
return nil, err
}
// Result is what gets returned from the plugin (via stdout) to the caller
type Result struct {
- IP4 *IPConfig `json:"ip4,omitempty"`
- IP6 *IPConfig `json:"ip6,omitempty"`
- DNS types.DNS `json:"dns,omitempty"`
+ CNIVersion string `json:"cniVersion,omitempty"`
+ IP4 *IPConfig `json:"ip4,omitempty"`
+ IP6 *IPConfig `json:"ip6,omitempty"`
+ DNS types.DNS `json:"dns,omitempty"`
}
func (r *Result) Version() string {
- return implementedSpecVersion
+ return ImplementedSpecVersion
}
func (r *Result) GetAsVersion(version string) (types.Result, error) {
for _, supportedVersion := range SupportedVersions {
if version == supportedVersion {
+ r.CNIVersion = version
return r, nil
}
}
"github.com/containernetworking/cni/pkg/types/020"
)
-const implementedSpecVersion string = "0.3.1"
+const ImplementedSpecVersion string = "0.3.1"
-var SupportedVersions = []string{"0.3.0", implementedSpecVersion}
+var SupportedVersions = []string{"0.3.0", ImplementedSpecVersion}
func NewResult(data []byte) (types.Result, error) {
result := &Result{}
}
func GetResult(r types.Result) (*Result, error) {
- resultCurrent, err := r.GetAsVersion(implementedSpecVersion)
+ resultCurrent, err := r.GetAsVersion(ImplementedSpecVersion)
if err != nil {
return nil, err
}
}
newResult := &Result{
- DNS: oldResult.DNS,
- Routes: []*types.Route{},
+ CNIVersion: ImplementedSpecVersion,
+ DNS: oldResult.DNS,
+ Routes: []*types.Route{},
}
if oldResult.IP4 != nil {
newResult.IPs = append(newResult.IPs, &IPConfig{
- Version: "4",
- Interface: -1,
- Address: oldResult.IP4.IP,
- Gateway: oldResult.IP4.Gateway,
+ Version: "4",
+ Address: oldResult.IP4.IP,
+ Gateway: oldResult.IP4.Gateway,
})
for _, route := range oldResult.IP4.Routes {
gw := route.GW
if oldResult.IP6 != nil {
newResult.IPs = append(newResult.IPs, &IPConfig{
- Version: "6",
- Interface: -1,
- Address: oldResult.IP6.IP,
- Gateway: oldResult.IP6.Gateway,
+ Version: "6",
+ Address: oldResult.IP6.IP,
+ Gateway: oldResult.IP6.Gateway,
})
for _, route := range oldResult.IP6.Routes {
gw := route.GW
if !ok {
return nil, fmt.Errorf("failed to convert result")
}
+ newResult.CNIVersion = ImplementedSpecVersion
return newResult, nil
}
// Result is what gets returned from the plugin (via stdout) to the caller
type Result struct {
+ CNIVersion string `json:"cniVersion,omitempty"`
Interfaces []*Interface `json:"interfaces,omitempty"`
IPs []*IPConfig `json:"ips,omitempty"`
Routes []*types.Route `json:"routes,omitempty"`
// Convert to the older 0.2.0 CNI spec Result type
func (r *Result) convertTo020() (*types020.Result, error) {
oldResult := &types020.Result{
- DNS: r.DNS,
+ CNIVersion: types020.ImplementedSpecVersion,
+ DNS: r.DNS,
}
for _, ip := range r.IPs {
}
func (r *Result) Version() string {
- return implementedSpecVersion
+ return ImplementedSpecVersion
}
func (r *Result) GetAsVersion(version string) (types.Result, error) {
switch version {
- case "0.3.0", implementedSpecVersion:
+ case "0.3.0", ImplementedSpecVersion:
+ r.CNIVersion = version
return r, nil
case types020.SupportedVersions[0], types020.SupportedVersions[1], types020.SupportedVersions[2]:
return r.convertTo020()
return fmt.Sprintf("%+v", *i)
}
+// Int returns a pointer to the int value passed in. Used to
+// set the IPConfig.Interface field.
+func Int(v int) *int {
+ return &v
+}
+
// IPConfig contains values necessary to configure an IP address on an interface
type IPConfig struct {
// IP version, either "4" or "6"
Version string
// Index into Result structs Interfaces list
- Interface int
+ Interface *int
Address net.IPNet
Gateway net.IP
}
// JSON (un)marshallable types
type ipConfig struct {
Version string `json:"version"`
- Interface int `json:"interface,omitempty"`
+ Interface *int `json:"interface,omitempty"`
Address types.IPNet `json:"address"`
Gateway net.IP `json:"gateway,omitempty"`
}
}
func (e *Error) Error() string {
- return e.Msg
+ details := ""
+ if e.Details != "" {
+ details = fmt.Sprintf("; %v", e.Details)
+ }
+ return fmt.Sprintf("%v%v", e.Msg, details)
}
func (e *Error) Print() error {