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

Add finalizer for AddressPool #168

Merged
merged 3 commits into from
Jul 27, 2021
Merged

Add finalizer for AddressPool #168

merged 3 commits into from
Jul 27, 2021

Conversation

morimoto-cybozu
Copy link
Contributor

@morimoto-cybozu morimoto-cybozu commented Jul 19, 2021

This PR adds a finalizer for an AddressPool. The finalizer is kept while the AddressPool is used by some AddressBlock.

Signed-off-by: morimoto-cybozu kenji_morimoto@cybozu.co.jp
Fixes: #132

@morimoto-cybozu morimoto-cybozu self-assigned this Jul 19, 2021
@morimoto-cybozu morimoto-cybozu marked this pull request as ready for review July 19, 2021 08:13
v2/pkg/ipam/pool.go Show resolved Hide resolved
// IsUsed returns true if the pool is used by some AddressBlock.
func (p *pool) IsUsed(ctx context.Context) (bool, error) {
blocks := &coilv2.AddressBlockList{}
err := p.reader.List(ctx, blocks, client.MatchingLabels{
Copy link
Contributor

Choose a reason for hiding this comment

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

Let me make sure. isUsed uses the direct API client, because AddressPool can be removed in the situation that a client returns no AddressBlock, but informer cache is staled(some AddressPools exists in fact). Is my understanding correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ysksuzuki
The primary reason of using p.reader is that it is used in pool.SyncBlocks(). I don't want to increase cached resources.

Typically the finalizer of AddressPool would be invoked in response to the deletion of the final AddressBlock. IsUsed() should certainly return false, or else the finalizer will be delayed until the next forced reconcilliation. So using cache in IsUsed() would be inappropriate.

ysksuzuki
ysksuzuki previously approved these changes Jul 27, 2021
@@ -41,6 +51,7 @@ var _ = Describe("AddressPool Webhook", func() {
ap := &AddressPool{}
err = k8sClient.Get(ctx, client.ObjectKey{Name: "test"}, ap)
Expect(err).NotTo(HaveOccurred())
Expect(controllerutil.ContainsFinalizer(ap, constants.FinCoil))
Copy link
Member

Choose a reason for hiding this comment

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

To be true?

@@ -51,6 +53,28 @@ func (r *AddressPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

logger.Info("synchronized")

if !ap.ObjectMeta.DeletionTimestamp.IsZero() {
Copy link
Member

@ymmt2005 ymmt2005 Jul 27, 2021

Choose a reason for hiding this comment

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

DeletionTimestamp should be compared to nil.
Also, ObjectMeta is embedded so can be omitted.

Copy link
Member

Choose a reason for hiding this comment

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

and it is simpler to negate the logic:

if ap.DeletionTimpstamp == nil {
    return ctrl.Result{}, nil
}

...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, this line is copied from the kubebuilder book.
Though the book uses IsZero(), it seems unnatural, so I'll fix it.

A failure in eviction may leave the zero value in the deletion timestamp, but I'm not sure this is meaningful.
kubernetes/kubernetes#54525

Signed-off-by: morimoto-cybozu <kenji_morimoto@cybozu.co.jp>
Signed-off-by: morimoto-cybozu <kenji_morimoto@cybozu.co.jp>
Signed-off-by: morimoto-cybozu <kenji_morimoto@cybozu.co.jp>
Copy link
Member

@ymmt2005 ymmt2005 left a comment

Choose a reason for hiding this comment

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

LGTM

@ymmt2005 ymmt2005 merged commit a68ea5c into main Jul 27, 2021
@ymmt2005 ymmt2005 deleted the addresspool-finalizer branch July 27, 2021 08:13
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.

AddressPool should have a finalizer
3 participants