-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Support defining IPAM pools using CiliumPodIPPool CRD #25824
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6f6c90a
k8s: add CiliumPodIPPool CRD and scaffolding
tklauser 2414fc5
ipam/allocator: add CIDRAllocator.IsClusterCIDR method
tklauser f3bbd89
ipam/allocator: add CIDRAllocator.Prefix method
tklauser 852b3af
ipam/allocator/multipool: remove unused NodeHandler.nodesPendingK8sUp…
tklauser 80d4eda
ipam/allocator/multipool: introduce RWMutex protecting PoolAllocator …
tklauser 9d47412
ipam/allocator/multipool: track mask size in cidrPool
tklauser f315ae1
ipam/allocator/multipool: always delete node from pending allocations
tklauser e5e1489
ipam/allocator/multipool: allow to update and delete pools
tklauser 2079036
ipam/allocator/multipool: retry node allocations on all failures
tklauser f0b170c
operator: add support for CiliumPodIPPool CRD
tklauser File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package watchers | ||
|
||
import ( | ||
"context" | ||
|
||
cilium_v2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1" | ||
"github.com/cilium/cilium/pkg/k8s/client" | ||
"github.com/cilium/cilium/pkg/k8s/resource" | ||
) | ||
|
||
// PooledAllocatorProvider defines the functions of IPAM provider front-end which additionally allow | ||
// definition of IP pools at runtime. | ||
// This is implemented by e.g. pkg/ipam/allocator/multipool | ||
type PooledAllocatorProvider interface { | ||
UpsertPool(ctx context.Context, pool *cilium_v2alpha1.CiliumPodIPPool) error | ||
DeletePool(ctx context.Context, pool *cilium_v2alpha1.CiliumPodIPPool) error | ||
} | ||
|
||
func StartIPPoolAllocator( | ||
ctx context.Context, | ||
clientset client.Clientset, | ||
allocator PooledAllocatorProvider, | ||
ipPools resource.Resource[*cilium_v2alpha1.CiliumPodIPPool], | ||
) { | ||
log.Info("Starting CiliumPodIPPool allocator watcher") | ||
|
||
synced := make(chan struct{}) | ||
|
||
go func() { | ||
for ev := range ipPools.Events(ctx) { | ||
var err error | ||
var action string | ||
|
||
switch ev.Kind { | ||
case resource.Sync: | ||
close(synced) | ||
case resource.Upsert: | ||
err = allocator.UpsertPool(ctx, ev.Object) | ||
action = "upsert" | ||
case resource.Delete: | ||
err = allocator.DeletePool(ctx, ev.Object) | ||
action = "delete" | ||
} | ||
ev.Done(err) | ||
if err != nil { | ||
log.WithError(err).Errorf("failed to %s pool %q", action, ev.Key) | ||
} | ||
} | ||
}() | ||
|
||
// Block until all pools are restored, so callers can safely start node allocation | ||
// right after return. | ||
<-synced | ||
log.Info("All CiliumPodIPPool resources synchronized") | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
How hard would it be to implement this as a hive module instead? I suppose we'd need to pull out
PooledAllocatorProvider
first from the legacy code plus makealloc.Start
depend onIPPoolAllocator
to make sure it's started first?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.
I initially thought about implementing this as a hive cell. Unfortunately, it would require lifting quite a bit of IPAM code around. For example, I think we cannot make
alloc.Start
depend onIPPoolAllocator
unconditionally, since only once specific implementation (namelyipam/allocator/multipool.Allocator
) requires the pooled allocator, while all the others don't. Initially, I wanted to includeIPPoolAllocator
intoipam/allocator.AllocatorProvider
, but IIRC that lead to nasty cyclic dependencies. Also, given this PR is already quite large and should make it into the tree for 1.14, I didn't want to include additional refactoring.Admittedly it's not ideal to introduce new code in a non-modular fashion, but based on the above I'd defer addressing modularization of this code together with the other IPAM bits to a follow-up PR. I'll discuss the specifics with @gandro and @cilium/sig-foundations in a Slack thread or GH issue. Hope that's OK?
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.
Yeah, given the feature freeze coming up in a week, I don't think it's realistic to tackle a larger refactor at the moment unfortunately 😿
The upside is that this is very little and simple code, so it should not make any future refactor more complicated