@@ -39,6 +39,11 @@ import (
3939 infrav1 "github.com/ionos-cloud/cluster-api-provider-proxmox/api/v1alpha2"
4040)
4141
42+ const (
43+ globalInClusterIPPool = "GlobalInClusterIPPool"
44+ inClusterIPPool = "InClusterIPPool"
45+ )
46+
4247// Helper provides handling of ipam objects such as, InClusterPool, IPAddressClaim.
4348type Helper struct {
4449 ctrlClient client.Client
@@ -200,13 +205,13 @@ func (h *Helper) GetIPPoolAnnotations(ctx context.Context, ipAddress *ipamv1.IPA
200205 Name : poolRef .Name ,
201206 }
202207
203- if poolRef .Kind == "InClusterIPPool" {
208+ if poolRef .Kind == inClusterIPPool {
204209 ipPool , err := h .GetInClusterIPPool (ctx , key )
205210 annotations = ipPool .ObjectMeta .Annotations
206211 if err != nil {
207212 return nil , err
208213 }
209- } else if poolRef .Kind == "GlobalInClusterIPPool" {
214+ } else if poolRef .Kind == globalInClusterIPPool {
210215 ipPool , err := h .GetGlobalInClusterIPPool (ctx , key )
211216 annotations = ipPool .ObjectMeta .Annotations
212217 if err != nil {
@@ -240,7 +245,7 @@ func (h *Helper) CreateIPAddressClaim(ctx context.Context, owner client.Object,
240245 if err != nil {
241246 return err
242247 }
243- case ref .Kind == "InClusterIPPool" :
248+ case ref .Kind == inClusterIPPool :
244249 pool , err := h .GetInClusterIPPool (ctx , ref )
245250 if err != nil {
246251 return errors .Wrapf (err , "unable to find inclusterpool for cluster %s" , h .cluster .Name )
@@ -250,7 +255,7 @@ func (h *Helper) CreateIPAddressClaim(ctx context.Context, owner client.Object,
250255 if err != nil {
251256 return err
252257 }
253- case ref .Kind == "GlobalInClusterIPPool" :
258+ case ref .Kind == globalInClusterIPPool :
254259 pool , err := h .GetGlobalInClusterIPPool (ctx , ref )
255260 if err != nil {
256261 return errors .Wrapf (err , "unable to find global inclusterpool for cluster %s" , h .cluster .Name )
@@ -302,7 +307,7 @@ func (h *Helper) CreateIPAddressClaimV2(ctx context.Context, owner client.Object
302307 suffix := infrav1 .DefaultSuffix
303308
304309 switch {
305- case ref .Kind == "InClusterIPPool" :
310+ case ref .Kind == inClusterIPPool :
306311 pool , err := h .GetInClusterIPPool (ctx , ref )
307312 if err != nil {
308313 return errors .Wrapf (err , "unable to find inclusterpool for cluster %s" , h .cluster .Name )
@@ -312,7 +317,7 @@ func (h *Helper) CreateIPAddressClaimV2(ctx context.Context, owner client.Object
312317 if err != nil {
313318 return err
314319 }
315- case ref .Kind == "GlobalInClusterIPPool" :
320+ case ref .Kind == globalInClusterIPPool :
316321 pool , err := h .GetGlobalInClusterIPPool (ctx , ref )
317322 if err != nil {
318323 return errors .Wrapf (err , "unable to find global inclusterpool for cluster %s" , h .cluster .Name )
@@ -368,9 +373,8 @@ func (h *Helper) GetIPAddress(ctx context.Context, key client.ObjectKey) (*ipamv
368373// GetIPAddressByPool attempts to retrieve all IPAddresses belonging to a pool
369374func (h * Helper ) GetIPAddressByPool (ctx context.Context , poolRef corev1.TypedLocalObjectReference ) ([]ipamv1.IPAddress , error ) {
370375 addresses := & ipamv1.IPAddressList {}
371- var out []ipamv1.IPAddress
372376
373- //fieldSelector, err := fields.ParseSelector("spec.poolRef.name=" + poolRef.Name + ",spec.poolRef.kind=" + poolRef.Kind)
377+ // fieldSelector, err := fields.ParseSelector("spec.poolRef.name=" + poolRef.Name + ",spec.poolRef.kind=" + poolRef.Kind)
374378 fieldSelector , err := fields .ParseSelector ("spec.poolRef.name=" + poolRef .Name )
375379 if err != nil {
376380 return nil , err
@@ -383,6 +387,7 @@ func (h *Helper) GetIPAddressByPool(ctx context.Context, poolRef corev1.TypedLoc
383387 return nil , err
384388 }
385389
390+ out := make ([]ipamv1.IPAddress , 0 , len (addresses .Items ))
386391 for _ , addr := range addresses .Items {
387392 groupVersion , _ := schema .ParseGroupVersion (addr .APIVersion )
388393 if groupVersion .Group != "ipam.cluster.x-k8s.io" {
0 commit comments