types: fix marshalling of omitted "interfaces" key in IPConfig JSON
authorDan Williams <dcbw@redhat.com>
Thu, 15 Jun 2017 03:16:30 +0000 (22:16 -0500)
committerDan Williams <dcbw@redhat.com>
Wed, 21 Jun 2017 14:56:12 +0000 (09:56 -0500)
commit30ab80517f4b8eee5e8f2cf111ecb0df37edd23a
treeed90f71abc7a6a7816ecc679d901415f6eb22b1d
parent8a045b00e4a69ffb8481ae970e2aaae8d3324b41
types: fix marshalling of omitted "interfaces" key in IPConfig JSON

Plugins that don't have knowledge of interfaces, like host-local or
other IPAM plugins, should not set the 'interfaces' key of their
returned "Result" JSON.  This should then not be translated into
an interface index of 0, which it was due to the int marshaling and
omitempty.

Instead, ensure that an omitted 'interface' in JSON ends up being
nil in the IPConfig structure, and that a nil ensures that no 'interfaces'
key is present in the JSON.

Yes, this means that plugins must call the 'current.Int(x)' method
when setting the Interfaces member.  Oh well.

Fixes: https://github.com/containernetworking/cni/issues/404
pkg/types/current/types.go
pkg/types/current/types_test.go