-
Notifications
You must be signed in to change notification settings - Fork 152
Add pick_addresses option for explicit IP candidate selection
#674
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
Open
DeamonMV
wants to merge
1
commit into
k8snetworkplumbingwg:master
Choose a base branch
from
DeamonMV:dml-changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,12 +27,80 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| var exrange []string | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("192.168.1.1")) | ||
|
|
||
| }) | ||
|
|
||
| Context("pickAddr selection", func() { | ||
| It("selects the first valid IP from the pick list", func() { | ||
| _, ipnet, err := net.ParseCIDR("10.0.0.0/24") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| pick := []net.IP{net.ParseIP("10.0.0.50"), net.ParseIP("10.0.0.60")} | ||
| newip, _, err := IterateForAssignment(*ipnet, nil, nil, pick, nil, nil, "cid-1", "pod/ns", "eth0") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("10.0.0.50")) | ||
| }) | ||
|
|
||
| It("skips pick IPs outside of the pool CIDR", func() { | ||
| _, ipnet, err := net.ParseCIDR("10.0.0.0/24") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| pick := []net.IP{net.ParseIP("192.168.1.10"), net.ParseIP("10.0.0.5")} | ||
| newip, _, err := IterateForAssignment(*ipnet, nil, nil, pick, nil, nil, "cid-2", "pod/ns", "eth0") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("10.0.0.5")) | ||
| }) | ||
|
|
||
| It("skips already reserved pick IPs and uses the next candidate", func() { | ||
| _, ipnet, err := net.ParseCIDR("10.0.0.0/24") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| ipres := []types.IPReservation{{IP: net.ParseIP("10.0.0.5"), PodRef: "default/pod1"}} | ||
| pick := []net.IP{net.ParseIP("10.0.0.5"), net.ParseIP("10.0.0.6")} | ||
| newip, _, err := IterateForAssignment(*ipnet, nil, nil, pick, ipres, nil, "cid-3", "pod/ns", "eth0") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("10.0.0.6")) | ||
| }) | ||
|
|
||
| It("honors exclude ranges when evaluating pick list (single IP and CIDR)", func() { | ||
| _, ipnet, err := net.ParseCIDR("10.0.0.0/24") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| exrange := []string{"10.0.0.5", "10.0.0.6/31"} // excludes .5 and {.6,.7} | ||
| pick := []net.IP{net.ParseIP("10.0.0.5"), net.ParseIP("10.0.0.6"), net.ParseIP("10.0.0.8")} | ||
| newip, _, err := IterateForAssignment(*ipnet, nil, nil, pick, nil, exrange, "cid-4", "pod/ns", "eth0") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("10.0.0.8")) | ||
| }) | ||
|
|
||
| It("returns an error when all pick candidates are invalid", func() { | ||
| _, ipnet, err := net.ParseCIDR("10.0.0.0/24") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| // .1 is within CIDR but reserved; 192.168.1.10 is out of CIDR | ||
| ipres := []types.IPReservation{{IP: net.ParseIP("10.0.0.1"), PodRef: "default/pod1"}} | ||
| pick := []net.IP{net.ParseIP("192.168.1.10"), net.ParseIP("10.0.0.1")} | ||
| _, _, err = IterateForAssignment(*ipnet, nil, nil, pick, ipres, nil, "cid-5", "pod/ns", "eth0") | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring("Could not allocate IP in range")) | ||
|
Comment on lines
+87
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
|
|
||
| It("allocates a pick candidate even if outside rangeStart/rangeEnd but inside CIDR", func() { | ||
| _, ipnet, err := net.ParseCIDR("10.0.0.0/24") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| rangeStart := net.ParseIP("10.0.0.100") | ||
| rangeEnd := net.ParseIP("10.0.0.150") | ||
| pick := []net.IP{net.ParseIP("10.0.0.10")} | ||
| newip, _, err := IterateForAssignment(*ipnet, rangeStart, rangeEnd, pick, nil, nil, "cid-6", "pod/ns", "eth0") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("10.0.0.10")) | ||
| }) | ||
| }) | ||
|
|
||
| It("can IterateForAssignment on an IPv6 address when the first hextet has NO leading zeroes", func() { | ||
|
|
||
| firstip, ipnet, err := net.ParseCIDR("caa5::0/112") | ||
|
|
@@ -43,7 +111,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| var exrange []string | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("caa5::1")) | ||
|
|
||
|
|
@@ -59,7 +127,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| var exrange []string | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("::1")) | ||
|
|
||
|
|
@@ -77,7 +145,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| var exrange []string | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("fd::1")) | ||
|
|
||
|
|
@@ -93,7 +161,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| var exrange []string | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("100::2:1")) | ||
| }) | ||
|
|
@@ -108,7 +176,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| exrange := []string{"192.168.0.0/30"} | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(fmt.Sprint(newip)).To(Equal("192.168.0.4")) | ||
|
|
||
| }) | ||
|
|
@@ -122,7 +190,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| exrange := []string{"192.168.0.1"} | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, err := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("192.168.0.2")) | ||
| }) | ||
|
|
@@ -136,7 +204,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| exrange := []string{"192.168.0.1/123"} | ||
| _, _, err = IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| _, _, err = IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).To(MatchError(HavePrefix("could not parse exclude range"))) | ||
| }) | ||
|
|
||
|
|
@@ -150,7 +218,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| exrange := []string{"100::2:1/126"} | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(fmt.Sprint(newip)).To(Equal("100::2:4")) | ||
|
|
||
| }) | ||
|
|
@@ -164,7 +232,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| exrange := []string{"100::2:1"} | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(fmt.Sprint(newip)).To(Equal("100::2:2")) | ||
| }) | ||
|
|
||
|
|
@@ -177,7 +245,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| exrange := []string{"100::2::1"} | ||
| _, _, err = IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| _, _, err = IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).To(MatchError(HavePrefix("could not parse exclude range"))) | ||
| }) | ||
|
|
||
|
|
@@ -191,7 +259,7 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| exrange := []string{"2001:db8::0/32"} | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(fmt.Sprint(newip)).To(Equal("2001:db9::")) | ||
|
|
||
| }) | ||
|
|
@@ -206,11 +274,11 @@ var _ = Describe("Allocation operations", func() { | |
|
|
||
| var ipres []types.IPReservation | ||
| exrange := []string{"192.168.0.0/30", "192.168.0.6/31", "192.168.0.8/31", "192.168.0.4/30"} | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, _ := IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(fmt.Sprint(newip)).To(Equal("192.168.0.10")) | ||
|
|
||
| exrange = []string{"192.168.0.0/30", "192.168.0.14/31", "192.168.0.4/30", "192.168.0.6/31", "192.168.0.8/31"} | ||
| newip, _, _ = IterateForAssignment(*ipnet, calculatedrangestart, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| newip, _, _ = IterateForAssignment(*ipnet, calculatedrangestart, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(fmt.Sprint(newip)).To(Equal("192.168.0.10")) | ||
| }) | ||
|
|
||
|
|
@@ -234,7 +302,7 @@ var _ = Describe("Allocation operations", func() { | |
| }, | ||
| } | ||
| exrange := []string{"192.168.0.0/30"} | ||
| _, _, err = IterateForAssignment(*ipnet, firstip, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| _, _, err = IterateForAssignment(*ipnet, firstip, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).To(MatchError(HavePrefix("Could not allocate IP in range"))) | ||
|
|
||
| }) | ||
|
|
@@ -258,7 +326,7 @@ var _ = Describe("Allocation operations", func() { | |
| }, | ||
| } | ||
| exrange := []string{"192.168.0.4/30"} | ||
| _, _, err = IterateForAssignment(*ipnet, firstip, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| _, _, err = IterateForAssignment(*ipnet, firstip, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).To(MatchError(HavePrefix("Could not allocate IP in range"))) | ||
|
|
||
| }) | ||
|
|
@@ -284,7 +352,7 @@ var _ = Describe("Allocation operations", func() { | |
| } | ||
|
|
||
| exrange := []string{"100::2:4/126"} | ||
| _, _, err = IterateForAssignment(*ipnet, firstip, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| _, _, err = IterateForAssignment(*ipnet, firstip, nil, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).To(MatchError(HavePrefix("Could not allocate IP in range"))) | ||
|
|
||
| }) | ||
|
|
@@ -297,7 +365,7 @@ var _ = Describe("Allocation operations", func() { | |
| _, ipnet, err := net.ParseCIDR("192.168.0.0/29") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| rangeStart := net.ParseIP("192.168.0.0") // Network address, out of bounds. | ||
| newip, _, err := IterateForAssignment(*ipnet, rangeStart, nil, nil, nil, "0xdeadbeef", "", "") | ||
| newip, _, err := IterateForAssignment(*ipnet, rangeStart, nil, nil, nil, nil, "0xdeadbeef", "", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("192.168.0.1")) | ||
| }) | ||
|
|
@@ -309,7 +377,7 @@ var _ = Describe("Allocation operations", func() { | |
| Expect(err).NotTo(HaveOccurred()) | ||
| rangeStart := net.ParseIP("192.168.0.0") // Network address, out of bounds. | ||
| rangeEnd := net.ParseIP("192.168.0.8") // Broadcast address, out of bounds. | ||
| newip, _, err := IterateForAssignment(*ipnet, rangeStart, rangeEnd, nil, nil, "0xdeadbeef", "", "") | ||
| newip, _, err := IterateForAssignment(*ipnet, rangeStart, rangeEnd, nil, nil, nil, "0xdeadbeef", "", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(fmt.Sprint(newip)).To(Equal("192.168.0.1")) | ||
| }) | ||
|
|
@@ -337,7 +405,7 @@ var _ = Describe("Allocation operations", func() { | |
| }, | ||
| } | ||
| exrange := []string{"192.168.0.4/30"} | ||
| _, _, err = IterateForAssignment(*ipnet, startip, lastip, ipres, exrange, "0xdeadbeef", "", "") | ||
| _, _, err = IterateForAssignment(*ipnet, startip, lastip, nil, ipres, exrange, "0xdeadbeef", "", "") | ||
| Expect(err).To(MatchError(HavePrefix("Could not allocate IP in range"))) | ||
| }) | ||
|
|
||
|
|
@@ -350,7 +418,7 @@ var _ = Describe("Allocation operations", func() { | |
| lastip := net.ParseIP("192.168.0.6") | ||
|
|
||
| ipres := []types.IPReservation{} | ||
| _, ipres, err = IterateForAssignment(*ipnet, startip, lastip, ipres, nil, "0xdeadbeef", "dummy-0", "") | ||
| _, ipres, err = IterateForAssignment(*ipnet, startip, lastip, nil, ipres, nil, "0xdeadbeef", "dummy-0", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(len(ipres)).To(Equal(1)) | ||
| Expect(fmt.Sprint(ipres[0].IP)).To(Equal("192.168.0.1")) | ||
|
|
@@ -379,7 +447,7 @@ var _ = Describe("Allocation operations", func() { | |
| }, | ||
| } | ||
|
|
||
| _, ipres, err = IterateForAssignment(*ipnet, startip, lastip, ipres, nil, "0xdeadbeef", "dummy-0", "") | ||
| _, ipres, err = IterateForAssignment(*ipnet, startip, lastip, nil, ipres, nil, "0xdeadbeef", "dummy-0", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(len(ipres)).To(Equal(4)) | ||
| Expect(fmt.Sprint(ipres[3].IP)).To(Equal("192.168.0.4")) | ||
|
|
@@ -408,7 +476,7 @@ var _ = Describe("Allocation operations", func() { | |
| }, | ||
| } | ||
|
|
||
| _, ipres, err = IterateForAssignment(*ipnet, startip, lastip, ipres, nil, "0xdeadbeef", "dummy-0", "") | ||
| _, ipres, err = IterateForAssignment(*ipnet, startip, lastip, nil, ipres, nil, "0xdeadbeef", "dummy-0", "") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(len(ipres)).To(Equal(4)) | ||
| Expect(fmt.Sprint(ipres[3].IP)).To(Equal("192.168.0.3")) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message returned when no valid IPs are found in the
pickAddrlist could be more informative. Consider including details about why the IPs were invalid (e.g., out of range, reserved, excluded) to aid in debugging.Also, consider returning a wrapped error that includes the original
AssignmentErrorfor better context.