Skip to content

Commit

Permalink
Merge pull request #72 from maiqueb/address-calico-not-defining-sandbox
Browse files Browse the repository at this point in the history
Preserve backwards compatibility of CreateNetworkStatus
  • Loading branch information
dougbtv authored Sep 30, 2024
2 parents 506cfda + ed6baad commit 9b218a2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
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() {
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(
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

0 comments on commit 9b218a2

Please sign in to comment.