@@ -56,8 +56,8 @@ var _ = Describe("IP Pool Reconciler", func() {
56
56
})
57
57
58
58
DescribeTable ("it shows the total, used, free ip addresses in the pool" ,
59
- func (poolType string , addresses []string , gateway string , expectedTotal , expectedUsed , expectedFree int ) {
60
- genericPool = newPool (poolType , testPool , namespace , gateway , addresses , 24 )
59
+ func (poolType string , prefix int , addresses []string , gateway string , expectedTotal , expectedUsed , expectedFree int ) {
60
+ genericPool = newPool (poolType , testPool , namespace , gateway , addresses , prefix )
61
61
Expect (k8sClient .Create (context .Background (), genericPool )).To (Succeed ())
62
62
63
63
Eventually (Object (genericPool )).
@@ -94,34 +94,47 @@ var _ = Describe("IP Pool Reconciler", func() {
94
94
},
95
95
96
96
Entry ("When there is 1 claim and no gateway - InClusterIPPool" ,
97
- "InClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "" , 11 , 1 , 10 ),
97
+ "InClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "" , 11 , 1 , 10 ),
98
98
Entry ("When there are 2 claims and no gateway - InClusterIPPool" ,
99
- "InClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "" , 11 , 2 , 9 ),
99
+ "InClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "" , 11 , 2 , 9 ),
100
100
Entry ("When there is 1 claim with gateway in range - InClusterIPPool" ,
101
- "InClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.10" , 10 , 1 , 9 ),
101
+ "InClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.10" , 10 , 1 , 9 ),
102
102
Entry ("When there are 2 claims with gateway in range - InClusterIPPool" ,
103
- "InClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.10" , 10 , 2 , 8 ),
103
+ "InClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.10" , 10 , 2 , 8 ),
104
104
Entry ("When there is 1 claim with gateway outside of range - InClusterIPPool" ,
105
- "InClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.1" , 11 , 1 , 10 ),
105
+ "InClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.1" , 11 , 1 , 10 ),
106
+ Entry ("When the addresses range includes network addr, it is not available - InClusterIPPool" ,
107
+ "InClusterIPPool" , 24 , []string {"10.0.0.0-10.0.0.1" }, "10.0.0.2" , 1 , 1 , 0 ),
108
+ Entry ("When the addresses range includes broadcast, it is not available - InClusterIPPool" ,
109
+ "InClusterIPPool" , 24 , []string {"10.0.0.254-10.0.0.255" }, "10.0.0.1" , 1 , 1 , 0 ),
110
+ Entry ("When the addresses range is IPv6 and the last range in the subnet, it is available - InClusterIPPool" ,
111
+ "InClusterIPPool" , 120 , []string {"fe80::ffff" }, "fe80::a" , 1 , 1 , 0 ),
106
112
107
113
Entry ("When there is 1 claim and no gateway - GlobalInClusterIPPool" ,
108
- "GlobalInClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "" , 11 , 1 , 10 ),
114
+ "GlobalInClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "" , 11 , 1 , 10 ),
109
115
Entry ("When there are 2 claims and no gateway - GlobalInClusterIPPool" ,
110
- "GlobalInClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "" , 11 , 2 , 9 ),
116
+ "GlobalInClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "" , 11 , 2 , 9 ),
111
117
Entry ("When there is 1 claim with gateway in range - GlobalInClusterIPPool" ,
112
- "GlobalInClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.10" , 10 , 1 , 9 ),
118
+ "GlobalInClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.10" , 10 , 1 , 9 ),
113
119
Entry ("When there are 2 claims with gateway in range - GlobalInClusterIPPool" ,
114
- "GlobalInClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.10" , 10 , 2 , 8 ),
120
+ "GlobalInClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.10" , 10 , 2 , 8 ),
115
121
Entry ("When there is 1 claim with gateway outside of range - GlobalInClusterIPPool" ,
116
- "GlobalInClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.1" , 11 , 1 , 10 ),
122
+ "GlobalInClusterIPPool" , 24 , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.1" , 11 , 1 , 10 ),
123
+ Entry ("When the addresses range includes network addr, it is not available - GlobalInClusterIPPool" ,
124
+ "GlobalInClusterIPPool" , 24 , []string {"10.0.0.0-10.0.0.1" }, "10.0.0.2" , 1 , 1 , 0 ),
125
+ Entry ("When the addresses range includes broadcast, it is not available - GlobalInClusterIPPool" ,
126
+ "GlobalInClusterIPPool" , 24 , []string {"10.0.0.254-10.0.0.255" }, "10.0.0.1" , 1 , 1 , 0 ),
127
+ Entry ("When the addresses range is IPv6 and the last range in the subnet, it is available - GlobalInClusterIPPool" ,
128
+ "GlobalInClusterIPPool" , 120 , []string {"fe80::ffff" }, "fe80::a" , 1 , 1 , 0 ),
117
129
)
118
130
119
131
DescribeTable ("it shows the out of range ips if any" ,
120
132
func (poolType string , addresses []string , gateway string , updatedAddresses []string , numClaims , expectedOutOfRange int ) {
121
133
poolSpec := v1alpha2.InClusterIPPoolSpec {
122
- Prefix : 24 ,
123
- Gateway : gateway ,
124
- Addresses : addresses ,
134
+ Prefix : 24 ,
135
+ Gateway : gateway ,
136
+ Addresses : addresses ,
137
+ AllocateReservedIPAddresses : true ,
125
138
}
126
139
127
140
switch poolType {
@@ -164,6 +177,7 @@ var _ = Describe("IP Pool Reconciler", func() {
164
177
HaveField ("Status.Addresses.Used" , Equal (numClaims )))
165
178
166
179
genericPool .PoolSpec ().Addresses = updatedAddresses
180
+ genericPool .PoolSpec ().AllocateReservedIPAddresses = false
167
181
Expect (k8sClient .Update (context .Background (), genericPool )).To (Succeed ())
168
182
169
183
Eventually (Object (genericPool )).
@@ -173,8 +187,20 @@ var _ = Describe("IP Pool Reconciler", func() {
173
187
174
188
Entry ("InClusterIPPool" ,
175
189
"InClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.1" , []string {"10.0.0.13-10.0.0.20" }, 5 , 3 ),
190
+ Entry ("InClusterIPPool when removing network address" ,
191
+ "InClusterIPPool" , []string {"10.0.0.0-10.0.0.255" }, "10.0.0.1" , []string {"10.0.0.1-10.0.0.255" }, 4 , 0 ),
192
+ Entry ("InClusterIPPool when removing gateway address" ,
193
+ "InClusterIPPool" , []string {"10.0.0.0-10.0.0.255" }, "10.0.0.1" , []string {"10.0.0.0" , "10.0.0.2-10.0.0.255" }, 5 , 1 ),
194
+ Entry ("InClusterIPPool when removing broadcast address" ,
195
+ "InClusterIPPool" , []string {"10.0.0.251-10.0.0.255" }, "10.0.0.1" , []string {"10.0.0.251-10.0.0.254" }, 5 , 1 ),
176
196
Entry ("GlobalInClusterIPPool" ,
177
197
"GlobalInClusterIPPool" , []string {"10.0.0.10-10.0.0.20" }, "10.0.0.1" , []string {"10.0.0.13-10.0.0.20" }, 5 , 3 ),
198
+ Entry ("GlobalInClusterIPPool when removing network address" ,
199
+ "GlobalInClusterIPPool" , []string {"10.0.0.0-10.0.0.255" }, "10.0.0.1" , []string {"10.0.0.1-10.0.0.255" }, 4 , 0 ),
200
+ Entry ("GlobalInClusterIPPool when removing gateway address" ,
201
+ "GlobalInClusterIPPool" , []string {"10.0.0.0-10.0.0.255" }, "10.0.0.1" , []string {"10.0.0.0" , "10.0.0.2-10.0.0.255" }, 5 , 1 ),
202
+ Entry ("GlobalInClusterIPPool when removing broadcast address" ,
203
+ "GlobalInClusterIPPool" , []string {"10.0.0.251-10.0.0.255" }, "10.0.0.1" , []string {"10.0.0.251-10.0.0.254" }, 5 , 1 ),
178
204
)
179
205
})
180
206
0 commit comments