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

⚠️ Generic claim reconciler #203

Conversation

p-strusiewiczsurmacki-mobica
Copy link
Contributor

What this PR does / why we need it:

This PR introduces generic claim reconcile - an interface that makes underlying IP address pools transparent for the controller and therefore can be used for easy integration of other IPAM providers.

Changes in this PR were created with @schrej

Copy link

linux-foundation-easycla bot commented Nov 9, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot requested review from rikatz and srm09 November 9, 2023 14:05
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Nov 9, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @p-strusiewiczsurmacki-mobica!

It looks like this is your first PR to kubernetes-sigs/cluster-api-ipam-provider-in-cluster 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api-ipam-provider-in-cluster has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 9, 2023
@p-strusiewiczsurmacki-mobica
Copy link
Contributor Author

/retest

@k8s-ci-robot
Copy link
Contributor

@p-strusiewiczsurmacki-mobica: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Dec 4, 2023
@schrej schrej added this to the v1.0.0 milestone Dec 6, 2023
@schrej schrej mentioned this pull request Dec 7, 2023
@schrej schrej force-pushed the generic-claim-reconciler branch from 1e5d03c to 6775a51 Compare January 5, 2024 10:13
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 5, 2024
@schrej schrej force-pushed the generic-claim-reconciler branch from 6775a51 to 3e7a3e7 Compare January 5, 2024 11:12
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 5, 2024
@@ -21,23 +21,16 @@ import (
"fmt"

"github.com/pkg/errors"
"golang.org/x/exp/slices"
Copy link
Contributor

Choose a reason for hiding this comment

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

If we bump to go v1.21 we can use the builtin slices: https://pkg.go.dev/slices#ContainsFunc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated go to 1.21

pkg/ipamutil/address.go Outdated Show resolved Hide resolved
pkg/ipamutil/reconciler.go Outdated Show resolved Hide resolved
}),
)

if err := r.Adapter.SetupWithManager(ctx, b); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

If SetupWithManager is not set, this will panic. Same for adapter.
Probably it is worth to check if both are null before calling them

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if Adapter is required, this SetupWithManager should return an error if Adapter is null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added check for adapter == nil.
Adapter is an interface, so I think that anything passed has to define SetupWithManager, as it won't fulfill interface otherwise. Or is there something I am missing here?

Comment on lines 157 to 172
if res, err := handler.FetchPool(ctx); err != nil || res != nil {
if apierrors.IsNotFound(err) {
err := errors.New("pool not found")
log.Error(err, "the referenced pool could not be found")
if !claim.ObjectMeta.DeletionTimestamp.IsZero() {
return r.reconcileDelete(ctx, claim)
}
return ctrl.Result{}, nil
}
return ctrl.Result{}, errors.Wrap(err, "failed to fetch pool")
}

if pool := handler.GetPool(); pool != nil && annotations.HasPaused(pool) {
log.Info("IPAddressClaim references Pool which is paused, skipping reconciliation.", "IPAddressClaim", claim.GetName(), "Pool", pool.GetName())
return ctrl.Result{}, nil
}
Copy link
Contributor

@rikatz rikatz Jan 10, 2024

Choose a reason for hiding this comment

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

Is there a reason for FetchPool and IPPool being separate operations? IIUC you reconcile the Pool on one, then gets the reconciled Pool. Why not just get the pool?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, the FetchPool() could be called once, return an IPPool and then you use it. Unless the concern is like, people calling FetchPool on a crazy way and always forcing its reconciliation.

Copy link
Member

Choose a reason for hiding this comment

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

iirc this just evolved this way. The idea was that the handler stores the pool on it's own and directly accesses it when it's needed. That way we don't need generics or type conversions. But since the reconciler needs to access the pools metadata in some cases I added that GetPool() method as well.
I think we can change FetchPool() to return the pool as well, and remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed FetchPool to return pool, res and err. Deleted GetPool.

pkg/ipamutil/reconciler.go Outdated Show resolved Hide resolved
@rikatz
Copy link
Contributor

rikatz commented Jan 10, 2024

sorry for the amount of comments and the delay!!!
I've left mostly some concerns and some nits, overall this is great!! Happy to see this moving on!!

"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

const (
Copy link
Contributor

Choose a reason for hiding this comment

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

the finalizer usage here is a bit confusing to me.

When is ReleaseAddress used? At which time? And Protect?

Usually it helps me to describe on a more verbose way at some comment something like

"When a new claim arrives, it will do X, then Y, then add a finalizer to guarantee this or that"

But this can be a followup!!!! No need to sweat on it

Copy link
Member

Choose a reason for hiding this comment

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

I think there is a lot of disagreement around Finalizer Naming. To me a Finalizer takes care of a specific action/function, and is removed after that task is done. When the same controller handles multiple Finalizers it's technically not necessary to have more than one. I think that's the reason while there is often just some generic finalizer to prevent deletion which gets removed after everything is done.
In this case the Finalizers serve different purposes though. The ProtectAddress one prevents deletion until the Claim is deleted. The ReleaseAddress one cleans up the allocated address after the claim was deleted. With the in-cluster provider this of course happens immediately, with e.g. Infoblox this can be asynchronous.
Whether this approach makes sense is debatable, especially since the ProtectAddress finalizer should also prevent the ReleaseAddress finalizer from executing, as we don't want to deallocate the address while it is still in use.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, makes sense. I was looking into the perspective of incluster and keep forgetting that at some points the deletion may be an async operation

@schrej
Copy link
Member

schrej commented Jan 10, 2024

sorry for the amount of comments

Please don't apologise for a thorough review, thanks for making time for it!

Signed-off-by: Patryk Strusiewicz-Surmacki <[email protected]>
Signed-off-by: Patryk Strusiewicz-Surmacki <[email protected]>
@p-strusiewiczsurmacki-mobica
Copy link
Contributor Author

@rikatz Thank you for your thorough review! It really helped to find issues I didn't notice before. :)

@@ -19,25 +19,18 @@ package controllers
import (
"context"
"fmt"
"slices"
Copy link
Contributor

Choose a reason for hiding this comment

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

@rikatz
Copy link
Contributor

rikatz commented Jan 12, 2024

/lgtm
(I know this lgtm will be gone once you fix the CI, but I can re-add it). Will leave final approval for @schrej

I think as a next thing (I can help with it!) I would like to add an e2e test here, that compiles the container and keeps adding globalincluster, localincluster, ipaddress, etc so we can do a request/response and are sure that what we expect to happen really happens :D

Thank you very very very much @p-strusiewiczsurmacki-mobica and @schrej this is great!!!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 12, 2024
@rikatz
Copy link
Contributor

rikatz commented Jan 24, 2024

@schrej anything else I'm missing?

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 29, 2024
@schrej
Copy link
Member

schrej commented Jan 29, 2024

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 29, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: p-strusiewiczsurmacki-mobica, schrej

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 29, 2024
@k8s-ci-robot k8s-ci-robot merged commit 30e5e33 into kubernetes-sigs:main Jan 29, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants