Skip to content

Commit

Permalink
correctly use CNI version conversion when create result from bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
dionysius committed Jun 10, 2022
1 parent acc919f commit b8d3a45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion network/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/containernetworking/cni/pkg/invoke"
"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/types/create"
rtApi "k8s.io/cri-api/pkg/apis/runtime/v1"
)

Expand Down Expand Up @@ -225,7 +226,7 @@ func (s *cniPodNetwork) ips(previousresult []byte) ([]net.IP, error) {
previousresult = []byte{}
}

prevResult, err := current.NewResult(previousresult)
prevResult, err := create.CreateFromBytes(previousresult)
if err != nil {
return nil, err
}
Expand Down
24 changes: 23 additions & 1 deletion network/cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,29 @@ func Test_cniPodNetwork_ips_Simple(t *testing.T) {
assert.Equal(t, "10.22.0.64", ips[0].String())
}

// TODO: ips from old result
func Test_cniPodNetwork_ips_from020(t *testing.T) {
t.Parallel()

podNet, _, tmpDir := testCNIPodNet(t)
defer os.RemoveAll(tmpDir)

ips, err := podNet.ips([]byte(`{"cniVersion":"0.2.0", "ip4": {"ip": "10.22.0.64/16"}}`))
assert.NoError(t, err)
assert.Len(t, ips, 1)
assert.Equal(t, "10.22.0.64", ips[0].String())
}

func Test_cniPodNetwork_ips_from040(t *testing.T) {
t.Parallel()

podNet, _, tmpDir := testCNIPodNet(t)
defer os.RemoveAll(tmpDir)

ips, err := podNet.ips([]byte(`{"cniVersion":"0.4.0", "ips":[{"address":"10.22.0.64/16"}]}`))
assert.NoError(t, err)
assert.Len(t, ips, 1)
assert.Equal(t, "10.22.0.64", ips[0].String())
}

func Test_cniPodNetwork_ips_Missing(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit b8d3a45

Please sign in to comment.