Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve backwards compatibility of CreateNetworkStatus #72

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/utils/net-attach-def.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func CreateNetworkStatuses(r cnitypes.Result, networkName string, defaultNetwork
return nil, fmt.Errorf("error converting the type.Result to cni100.Result: %v", err)
}

if len(result.Interfaces) == 1 {
networkStatus, err := CreateNetworkStatus(r, networkName, defaultNetwork, dev)
return []*v1.NetworkStatus{networkStatus}, err
}

// Discover default routes upfront and reuse them if necessary.
var useDefaultRoute []string
for _, route := range result.Routes {
Expand Down
42 changes: 42 additions & 0 deletions pkg/utils/net-attach-def_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,48 @@ var _ = Describe("Netwok Attachment Definition manipulations", func() {
})
})

Context("create network statuses for a single interface which omits the sandbox info", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding the test case for this one

var cniResult *cni100.Result

BeforeEach(func() {
cniResult = &cni100.Result{
CNIVersion: "1.1.0",
Interfaces: []*cni100.Interface{
{
Name: "foo",
},
},
IPs: []*cni100.IPConfig{
{
Address: *EnsureCIDR("10.244.196.152/32"),
},
{
Address: *EnsureCIDR("fd10:244::c497/128"),
},
},
}
})

It("creates network statuses with a single entry", func() {
networkStatuses, err := CreateNetworkStatuses(cniResult, "test-default-net-without-sandbox", true, nil)
Expect(err).NotTo(HaveOccurred())

Expect(networkStatuses).To(WithTransform(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we must clear the DNS information since we are using the convertDNS function within CreateNetworkStatuses ...

func(status []*v1.NetworkStatus) []*v1.NetworkStatus {
for i := range status {
status[i].DNS = v1.DNS{}
}
return status
}, ConsistOf(
&v1.NetworkStatus{
Name: "test-default-net-without-sandbox",
IPs: []string{"10.244.196.152", "fd10:244::c497"},
Default: true,
},
)))
})
})

It("parse network selection element in pod", func() {
selectionElement := `
[{
Expand Down
Loading