You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add ability to specify range of VM IDs to use (#286)
* Return VMIDFreeErr or the error object itself if CheckID returns true/an error
* Rename VMIDFreeErr to ErrVMIDFree and fix comment to make linter happy
* feat: Add ability to specify range of VM IDs to use
* Fix codespell error: fix spelling
* When checking if a vmid is free, first check the existing ProxmoxMachines before querying the Proxmox API.
* Check that the vmid of the Proxmox machine is set (not -1) before adding it to usedVMIDs
* Move spec.vmidRange from ProxmoxCluster to ProxmoxMachine
* Update github.com/luthermonson/go-proxmox to v0.2.0
* Revert "Update github.com/luthermonson/go-proxmox to v0.2.0"
This reverts commit c5d15e5.
Because of this bug luthermonson/go-proxmox#169
* Update github.com/luthermonson/go-proxmox to v0.2.1
* Add test for ClusterScope.ListProxmoxMachinesForCluster
* Fix wording in ProxmoxMachine types test
* Rename vmidRange to vmIDRange to follow k8s API conventions
* Add validation for vmIDRange: end should be greater than or equal to start
* Set failureMessage and failureReason when ErrNoVMIDInRangeFree is thrown
* Refactor getVMID to improve code quality
---------
Co-authored-by: Mohamed Chiheb Ben Jemaa <[email protected]>
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("ipv4PoolRef allows either InClusterIPPool or GlobalInClusterIPPool")))
It("Should only allow IPAM pool resources in IPv6PoolRef kind", func() {
179
186
dm:=defaultMachine()
180
187
dm.Spec.Network=&NetworkSpec{
181
-
AdditionalDevices: []AdditionalNetworkDevice{{
182
-
NetworkDevice: NetworkDevice{},
183
-
Name: "net1",
184
-
InterfaceConfig: InterfaceConfig{
185
-
IPv6PoolRef: &corev1.TypedLocalObjectReference{
186
-
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
187
-
Kind: "ConfigMap",
188
-
Name: "some-app",
189
-
}},
190
-
},
188
+
AdditionalDevices: []AdditionalNetworkDevice{
189
+
{
190
+
NetworkDevice: NetworkDevice{},
191
+
Name: "net1",
192
+
InterfaceConfig: InterfaceConfig{
193
+
IPv6PoolRef: &corev1.TypedLocalObjectReference{
194
+
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
195
+
Kind: "ConfigMap",
196
+
Name: "some-app",
197
+
},
198
+
},
199
+
},
191
200
},
192
201
}
193
202
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("ipv6PoolRef allows either InClusterIPPool or GlobalInClusterIPPool")))
It("Should only allow Machine with additional devices with at least a pool ref", func() {
197
206
dm:=defaultMachine()
198
207
dm.Spec.Network=&NetworkSpec{
199
-
AdditionalDevices: []AdditionalNetworkDevice{{
200
-
NetworkDevice: NetworkDevice{},
201
-
Name: "net1",
202
-
},
208
+
AdditionalDevices: []AdditionalNetworkDevice{
209
+
{
210
+
NetworkDevice: NetworkDevice{},
211
+
Name: "net1",
212
+
},
203
213
},
204
214
}
205
215
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("at least one pool reference must be set, either ipv4PoolRef or ipv6PoolRef")))
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("should be less than or equal to 4094")))
287
297
})
288
298
})
299
+
300
+
Context("VMIDRange", func() {
301
+
It("Should only allow spec.vmIDRange.start >= 100", func() {
302
+
dm:=defaultMachine()
303
+
dm.Spec.VMIDRange=&VMIDRange{
304
+
Start: 1,
305
+
}
306
+
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("should be greater than or equal to 100")))
307
+
})
308
+
It("Should only allow spec.vmIDRange.end >= 100", func() {
309
+
dm:=defaultMachine()
310
+
dm.Spec.VMIDRange=&VMIDRange{
311
+
End: 1,
312
+
}
313
+
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("should be greater than or equal to 100")))
314
+
})
315
+
It("Should only allow spec.vmIDRange.end >= spec.vmIDRange.start", func() {
316
+
dm:=defaultMachine()
317
+
dm.Spec.VMIDRange=&VMIDRange{
318
+
Start: 101,
319
+
End: 100,
320
+
}
321
+
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("should be greater than or equal to start")))
322
+
})
323
+
It("Should only allow spec.vmIDRange.start if spec.vmIDRange.end is set", func() {
324
+
dm:=defaultMachine()
325
+
dm.Spec.VMIDRange=&VMIDRange{
326
+
Start: 100,
327
+
}
328
+
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("spec.vmIDRange.end in body should be greater than or equal to 100")))
329
+
})
330
+
It("Should only allow spec.vmIDRange.end if spec.vmIDRange.start is set", func() {
331
+
dm:=defaultMachine()
332
+
dm.Spec.VMIDRange=&VMIDRange{
333
+
End: 100,
334
+
}
335
+
Expect(k8sClient.Create(context.Background(), dm)).Should(MatchError(ContainSubstring("spec.vmIDRange.start in body should be greater than or equal to 100")))
0 commit comments