Skip to content

Implement ip pool selector logic for service#1693

Merged
fedepaol merged 2 commits intometallb:mainfrom
pperiyasamy:ippool-selector-impl
Dec 13, 2022
Merged

Implement ip pool selector logic for service#1693
fedepaol merged 2 commits intometallb:mainfrom
pperiyasamy:ippool-selector-impl

Conversation

@pperiyasamy
Copy link
Contributor

This changes ip allocation logic when ip pools are configured with namespace, service/namespace label selectors so that ip are allocated from desired pools based on its priority before it tries to allocate from other ip pools.

Signed-off-by: Periyasamy Palanisamy pepalani@redhat.com

@pperiyasamy pperiyasamy marked this pull request as draft November 8, 2022 12:59
@pperiyasamy pperiyasamy marked this pull request as ready for review November 21, 2022 09:31
pools map[string]*config.Pool
ips *allocator.Allocator
client service
pools map[string]*config.Pool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a local higher level struct that wraps all the pools (pools itself plus the selectors)? In that way, we can have it expose methods too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, moved this higher level struct into config and consuming it in every places.

return ips, nil
}

pinnedPriorityPools, pinnedNoPriorityPools := c.getPinnedPools(svc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move all this logic to allocator's Allocate()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is a cleaner solution. moved the logic into Allocate().

For(&metallbv1beta1.IPAddressPool{}).
Watches(&source.Kind{Type: &metallbv1beta1.AddressPool{}}, &handler.EnqueueRequestForObject{}).
Watches(&source.Kind{Type: &metallbv1beta1.Community{}}, &handler.EnqueueRequestForObject{}).
Watches(&source.Kind{Type: &corev1.Namespace{}}, &handler.EnqueueRequestForObject{}).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a predicate that discard events on the namespace that do not involve changing labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, done.

@pperiyasamy pperiyasamy force-pushed the ippool-selector-impl branch 3 times, most recently from 9d79fbb to e847f37 Compare November 28, 2022 12:08
@yuvalk
Copy link
Contributor

yuvalk commented Nov 29, 2022

hint for static-security-analysis,
see my fixes for older code here:
b3e8e24
and a nice explanation here:
https://medium.com/swlh/use-pointer-of-for-range-loop-variable-in-go-3d3481f7ffc9

@pperiyasamy
Copy link
Contributor Author

hint for static-security-analysis,

Can you also make this available from inv command via tasks.py ?

@pperiyasamy pperiyasamy force-pushed the ippool-selector-impl branch 2 times, most recently from e1aee19 to dea0efb Compare December 2, 2022 09:19
@pperiyasamy pperiyasamy force-pushed the ippool-selector-impl branch 2 times, most recently from b67ff14 to 943c04c Compare December 6, 2022 10:08
@pperiyasamy pperiyasamy force-pushed the ippool-selector-impl branch 3 times, most recently from 6f51119 to 2f4e14d Compare December 7, 2022 11:41
This changes ip allocation logic when ip pools are configured with
namespace, service/namespace label selectors so that ip are allocated
from desired pools based on its priority before it tries to allocate
from other ip pools.

Signed-off-by: Periyasamy Palanisamy <pepalani@redhat.com>
This adds relevant e2e tests covering functionality of ip pools
pinned with specific namespace and/or service labels.

Signed-off-by: Periyasamy Palanisamy <pepalani@redhat.com>
@fedepaol
Copy link
Member

LGTM!

@fedepaol fedepaol merged commit 4b236c7 into metallb:main Dec 13, 2022
@pperiyasamy pperiyasamy deleted the ippool-selector-impl branch December 13, 2022 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants