Skip to content
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 10 commits into from Jun 7, 2023

Conversation

tklauser
Copy link
Member

@tklauser tklauser commented Jun 1, 2023

This PR introduces the CiliumPodIPPool CRD and adds support to use it to define IP pools in Cilium's multi-pool IPAM mode (ref. #22762).

An example CiliumPodIPPool CRD definition of the pool named jupiter with the IPv4 CIDRs 10.10.0.0/16 and 10.20.0.0/16, an IPv4 mask size of 27 bits, the IPv6 CIDR fd00:100::/80 and an IPv6 mask size of 96 bits looks as follows:

apiVersion: cilium.io/v2alpha1
kind: CiliumPodIPPool
metadata:
  name: jupiter
spec:
  ipv4:
    cidrs:
      - 10.10.0.0/16
      - 10.20.0.0/16
    maskSize: 27
  ipv6:
    cidrs:
      - fd00:100::/80
    maskSize: 96

These CRDs are watched by cilium-operator. Deletion and update of existing pools are supported, however updates changing mask sizes on existing pools are rejected.

Please see individual commits for details.

Manually tested on kind as follows:

$ WORKERS=2 make kind
$ make kind-image
$ helm upgrade --install cilium ./install/kubernetes/cilium --namespace kube-system \
    --set debug.enabled=true \
    --set image.override=localhost:5000/cilium/cilium-dev:local \
    --set image.pullPolicy=IfNotPresent \
    --set operator.image.override=localhost:5000/cilium/operator-generic:local \
    --set operator.image.pullPolicy=IfNotPresent \
    --set operator.replicas=1 \
    --set hubble.relay.enabled=true \
    --set ipam.mode=multi-pool \
    --set "ipam.operator.multiPoolMap.default.ipv4CIDRs[0]=10.10.0.0/16" \
    --set "ipam.operator.multiPoolMap.default.ipv4MaskSize=27" \
    --set tunnel=disabled \
    --set autoDirectNodeRoutes=true \
    --set ipv4NativeRoutingCIDR=10.0.0.0/8 \
    --set endpointRoutes.enabled=true \
    --set-string extraConfig.enable-local-node-route=false \
    --set kubeProxyReplacement=strict \
    --set bpf.masquerade=true
$ cat <<EOF | k apply -f -
apiVersion: cilium.io/v2alpha1
kind: CiliumPodIPPool
metadata:
  name: mars
spec:
  ipv4:
    cidrs:
      - 10.20.0.0/16
    maskSize: 24
EOF
$ k get ciliumpodippools
NAME      AGE
mars      10s
$ # note that the default pool was configured using the operator flag and doesn't show up here (yet). This will be addressed in a follow-up PR.
$ k create -f https://raw.githubusercontent.com/cilium/cilium/1.13.3/examples/minikube/http-sw-app.yaml
$ k -n default get pods -o wide
NAME                         READY   STATUS    RESTARTS   AGE   IP           NODE           NOMINATED NODE   READINESS GATES
deathstar-8464cdd4d9-9bc24   1/1     Running   0          12s   10.10.0.42   kind-worker2   <none>           <none>
deathstar-8464cdd4d9-s5nfm   1/1     Running   0          12s   10.10.0.29   kind-worker    <none>           <none>
tiefighter                   1/1     Running   0          12s   10.10.0.20   kind-worker    <none>           <none>
xwing                        1/1     Running   0          12s   10.10.0.3    kind-worker    <none>           <none>
$ # note that all pods have IPs from the default pool's CIDRs
$ k create ns cilium-test
$ k annotate ns cilium-test ipam.cilium.io/ip-pool=mars
$ cilium connectivity test
...
✅ All 42 tests (295 actions) successful, 13 tests skipped, 0 scenarios skipped.
$ k -n cilium-test get pods -o wide
NAME                                  READY   STATUS    RESTARTS   AGE     IP            NODE                 NOMINATED NODE   READINESS GATES
client-6f6788d7cc-7fw9w               1/1     Running   0          8m56s   10.20.0.238   kind-worker          <none>           <none>
client2-bc59f56d5-hsv2g               1/1     Running   0          8m56s   10.20.0.193   kind-worker          <none>           <none>
echo-external-node-787c859b66-zrblr   0/1     Pending   0          8m55s   <none>        <none>               <none>           <none>
echo-other-node-646976b7dd-5zlr4      2/2     Running   0          8m56s   10.20.1.145   kind-worker2         <none>           <none>
echo-same-node-58f99d79f4-4k5v4       2/2     Running   0          8m56s   10.20.0.202   kind-worker          <none>           <none>
...
$ # note the different IP range (from pool mars) for the cilium-test pods

The following will be added in a separate follow-up PR, see meta issue #25470:

  • Creation of CiliumPodIPPools from operator ipam.operator.multiPoolMap helm flags
  • CI coverage
  • Documentation

Extends #24764

@tklauser tklauser added sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. area/operator Impacts the cilium-operator component sig/ipam IP address management, including cloud IPAM sig/agent Cilium agent related. area/ipam Impacts IP address management functionality. labels Jun 1, 2023
@tklauser tklauser requested a review from gandro June 1, 2023 12:39
@tklauser tklauser mentioned this pull request Jun 1, 2023
29 tasks
@tklauser tklauser added the release-blocker/1.14 This issue will prevent the release of the next version of Cilium. label Jun 1, 2023
Copy link
Member

@gandro gandro left a comment

Choose a reason for hiding this comment

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

Awesome work! Left a bit of early feedback

pkg/k8s/watchers/watcher.go Outdated Show resolved Hide resolved
pkg/ipam/allocator/multipool/allocator.go Show resolved Hide resolved
pkg/ipam/allocator/multipool/pool_allocator.go Outdated Show resolved Hide resolved
pkg/ipam/allocator/multipool/pool_allocator.go Outdated Show resolved Hide resolved
pkg/ipam/allocator/multipool/pool_allocator.go Outdated Show resolved Hide resolved
@tklauser tklauser force-pushed the pr/tklauser/ippool-crd branch 3 times, most recently from af5a6c1 to 950d4ca Compare June 5, 2023 09:41
@tklauser tklauser changed the title Support defining IPAM pools using CiliumIPPool CRD Support defining IPAM pools using CiliumPodIPPool CRD Jun 5, 2023
@tklauser tklauser force-pushed the pr/tklauser/ippool-crd branch 2 times, most recently from 51f0a51 to b8050d8 Compare June 5, 2023 15:20
@tklauser tklauser marked this pull request as ready for review June 5, 2023 15:37
@tklauser tklauser requested review from a team as code owners June 5, 2023 15:37
@tklauser
Copy link
Member Author

tklauser commented Jun 5, 2023

/test

@tklauser
Copy link
Member Author

tklauser commented Jun 5, 2023

/test

Copy link
Contributor

@joamaki joamaki left a comment

Choose a reason for hiding this comment

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

LGTM. A nice to have would be to start modularizing operator's IPAM related code as we're touching these parts.

DeletePool(ctx context.Context, pool *cilium_v2alpha1.CiliumPodIPPool) error
}

func StartIPPoolAllocator(
Copy link
Contributor

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 make alloc.Start depend on IPPoolAllocator to make sure it's started first?

Copy link
Member Author

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 on IPPoolAllocator unconditionally, since only once specific implementation (namely ipam/allocator/multipool.Allocator) requires the pooled allocator, while all the others don't. Initially, I wanted to include IPPoolAllocator into ipam/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?

Copy link
Member

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

@tklauser tklauser requested a review from gandro June 6, 2023 22:07
@tklauser tklauser mentioned this pull request Jun 6, 2023
8 tasks
Copy link
Member

@gandro gandro left a comment

Choose a reason for hiding this comment

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

Awesome work!

@gandro gandro removed the request for review from youngnick June 7, 2023 09:38
@gandro
Copy link
Member

gandro commented Jun 7, 2023

Merge button is green! 🚢

@gandro gandro merged commit f3a88e4 into cilium:main Jun 7, 2023
62 checks passed
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 7, 2023
@tklauser tklauser deleted the pr/tklauser/ippool-crd branch June 7, 2023 15:02
tklauser added a commit that referenced this pull request Jun 14, 2023
In (*PoolAllocator).updateCIDRSets the CIDRs are currently parsed twice,
once using netip.ParsePrefix and once using net.ParseCIDR. Avoid this
and pass the CIDRs as []netip.Prefix and at the same time also convert
downstream functions in ipam/cidrset to take a netip.Prefix instead of
*net.IPNet.

Ref. #25824 (comment)
Ref. #25991 (comment)

Signed-off-by: Tobias Klauser <tobias@cilium.io>
tklauser added a commit that referenced this pull request Jun 14, 2023
In (*PoolAllocator).updateCIDRSets the CIDRs are currently parsed twice,
once using netip.ParsePrefix and once using net.ParseCIDR. Avoid this
and pass the CIDRs as []netip.Prefix and at the same time also convert
downstream functions in ipam/cidrset to take a netip.Prefix instead of
*net.IPNet.

Ref. #25824 (comment)
Ref. #25991 (comment)

Signed-off-by: Tobias Klauser <tobias@cilium.io>
tklauser added a commit to cilium/cilium-cli that referenced this pull request Jun 15, 2023
These were introduced in cilium/cilium#25824 and
are used to define pod IP pools in the multi-pool IPAM mode. See
cilium/cilium#24764 for more information.

Updates cilium/cilium#25470

Signed-off-by: Tobias Klauser <tobias@cilium.io>
tklauser added a commit to cilium/cilium-cli that referenced this pull request Jun 15, 2023
The CiliumPodIPPool resource was introduced in cilium/cilium#25824 and
is used to define pod IP pools in the multi-pool IPAM mode. See
cilium/cilium#24764 for more information.

Updates cilium/cilium#25470

Signed-off-by: Tobias Klauser <tobias@cilium.io>
tklauser added a commit to cilium/cilium-cli that referenced this pull request Jun 15, 2023
The CiliumPodIPPool resource was introduced in cilium/cilium#25824 and
is used to define pod IP pools in the multi-pool IPAM mode. See
cilium/cilium#24764 for more information.

Updates cilium/cilium#25470

Signed-off-by: Tobias Klauser <tobias@cilium.io>
tklauser added a commit to cilium/cilium-cli that referenced this pull request Jun 16, 2023
The CiliumPodIPPool resource was introduced in cilium/cilium#25824 and
is used to define pod IP pools in the multi-pool IPAM mode. See
cilium/cilium#24764 for more information.

Updates cilium/cilium#25470

Signed-off-by: Tobias Klauser <tobias@cilium.io>
tklauser added a commit to cilium/cilium-cli that referenced this pull request Jun 19, 2023
The CiliumPodIPPool resource was introduced in cilium/cilium#25824 and
is used to define pod IP pools in the multi-pool IPAM mode. See
cilium/cilium#24764 for more information.

Updates cilium/cilium#25470

Signed-off-by: Tobias Klauser <tobias@cilium.io>
tklauser added a commit to cilium/cilium-cli that referenced this pull request Jun 19, 2023
The CiliumPodIPPool resource was introduced in cilium/cilium#25824 and
is used to define pod IP pools in the multi-pool IPAM mode. See
cilium/cilium#24764 for more information.

Updates cilium/cilium#25470

Signed-off-by: Tobias Klauser <tobias@cilium.io>
romanspb80 pushed a commit to romanspb80/cilium that referenced this pull request Jun 22, 2023
In (*PoolAllocator).updateCIDRSets the CIDRs are currently parsed twice,
once using netip.ParsePrefix and once using net.ParseCIDR. Avoid this
and pass the CIDRs as []netip.Prefix and at the same time also convert
downstream functions in ipam/cidrset to take a netip.Prefix instead of
*net.IPNet.

Ref. cilium#25824 (comment)
Ref. cilium#25991 (comment)

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ipam Impacts IP address management functionality. area/operator Impacts the cilium-operator component ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-blocker/1.14 This issue will prevent the release of the next version of Cilium. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. sig/agent Cilium agent related. sig/ipam IP address management, including cloud IPAM sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants