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 cli flag for leader-election-resource-lock #8107

Closed
wants to merge 2 commits into from

Conversation

shafeeqes
Copy link
Contributor

@shafeeqes shafeeqes commented Jan 5, 2022

What this PR does / why we need it:

Support for configmaps lock for leaderelection is removed in K8s 1.24 with kubernetes/kubernetes#106852.
More details about the motivation to switch to leases - ref kubernetes/kubernetes#80289.

ingress-nginx is currently using configmaps . This PR proposes to add a cli flag for leader-election-resource-lock which is defaulted to configmaps. If the operator has updated the necessary RBAC permissions, they should first use configmapsleases for migration purposes and then switch to leases in the next release.

Release Notes:

 A CLI flag `--leader-election-resource-lock` is introduced which defaults to the `configmaps`. If you want to migrate to `configmapsleases` and then `leases` in the future, necessary RBAC should be added in your component. You should atleast be running a release with `configmapsleases` as the resourcelock before setting the flag to `leases`.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

Which issue/s this PR fixes

fixes #8091

How Has This Been Tested?

Tested by creating an image and updating on an existing deployment.
Resourcelocks were created as per set in the container spec of the ingress-nginx-controller deployment manifest.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 5, 2022

CLA Signed

The committers are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 5, 2022
@k8s-ci-robot
Copy link
Contributor

@shafeeqes: This issue is currently awaiting triage.

If Ingress contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jan 5, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @shafeeqes!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. 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/ingress-nginx 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
Copy link
Contributor

Hi @shafeeqes. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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 needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/helm Issues or PRs related to helm charts labels Jan 5, 2022
@ChiefAlexander
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 6, 2022
@shafeeqes
Copy link
Contributor Author

/test pull-ingress-nginx-codegen

@ChiefAlexander
Copy link
Contributor

/assign @rikatz

ConfigMapMeta: metav1.ObjectMeta{Namespace: k8s.IngressPodDetails.Namespace, Name: config.ElectionID},
Client: config.Client.CoreV1(),
LockConfig: resourcelock.ResourceLockConfig{
//TODO: Switch configmapsleases to leases in the next version.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would like to ask for a soft transition here, let me explain:

  • Test if we CAN use Leases, then we use it.
  • If not, test if we can use ConfigMapLeases, then we use it
  • Finally, if everything goes wrong, fallback to ConfigMapLock

This way, users that already rely on ConfigMap wont need to change/break their environment. Forcefully changing to Leases may break environments where the admins just update the image, and not the Roles, etc.

Makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not get completely what you are suggesting. First, leaderelection should try to acquire resourcelock using leases, and if it fails, try configmapleases, and then configmaps?
Please explain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH, admins not updating the Roles does not feel like a reason enough to me. We will be mentioning that in the release notes, so admins should be noticing that and acting accordingly.
And anyways if we delay this too, after we revendor K8s, we have to get rid of the old resourcelocks.
WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

@shafeeqes this is true in theory, but not in practice and we must be empathetic with the admins on this :)

As a previous admin, I know that sometimes in a rush we simply update the image. This is a breaking change from the users perspective. If someone just update the image on a cluster previously created with old manifests (instead of reapplying all the manifests, and well, kubectl set image is here for that!) Ingress wont start, and this may lead into their ingresses being unavailable.

So, my suggestion is:

  • Test if ingress can do a get/update/list/watch on leases. If so, let's use it
  • Otherwise, fallback to the previously working scenario.

Choose a reason for hiding this comment

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

What about exposing a CLI flag similar to --election-id for configuring the lock type? This would prevent this fake call to check whether the nginx-ingress pod has required privilege and it would also decouple the leader election lock migration from nginx-ingress releases. Users of nginx-ingress can configure this as they want when they are ready (i.e., when they have provided the required RBAC privileges).

@rikatz
Copy link
Contributor

rikatz commented Jan 9, 2022

/retest
I've fixed the test. If it fails again, please rebase over main :)

Thanks!

@shafeeqes shafeeqes force-pushed the enhancement/resourcelock branch from 773fc59 to 797b190 Compare January 10, 2022 03:50
@shafeeqes shafeeqes force-pushed the enhancement/resourcelock branch from 797b190 to 8e5cec4 Compare January 21, 2022 11:22
@shafeeqes shafeeqes requested a review from rikatz January 21, 2022 11:23
@shafeeqes shafeeqes force-pushed the enhancement/resourcelock branch from 0190105 to f4b149b Compare January 21, 2022 12:39
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 21, 2022
@shafeeqes shafeeqes force-pushed the enhancement/resourcelock branch from f4b149b to 40327fc Compare January 21, 2022 17:02
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 13, 2022
@shafeeqes
Copy link
Contributor Author

@rikatz I have pushed the code changes as discussed. PTAL.
Will open another PR for the helm chart changes and the tests.

@shafeeqes shafeeqes requested a review from rikatz March 14, 2022 01:28
@shafeeqes shafeeqes changed the title Migrate ingress-nginx resourcelock to configmapleases Add cli flag for leader-election-resource-lock Mar 14, 2022
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2022
@shafeeqes shafeeqes force-pushed the enhancement/resourcelock branch from 075b135 to 2fdaefe Compare April 13, 2022 04:45
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2022
@rikatz
Copy link
Contributor

rikatz commented May 1, 2022

/lgtm
Let's see how this goes
Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 1, 2022
@shafeeqes
Copy link
Contributor Author

/test pull-ingress-nginx-test

@k8s-ci-robot
Copy link
Contributor

@shafeeqes: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-ingress-nginx-test 2fdaefe link true /test pull-ingress-nginx-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@shafeeqes
Copy link
Contributor Author

/tide merge-method-squash

@rikatz
Copy link
Contributor

rikatz commented May 2, 2022

/lgtm
/approve
/label tide/merge-method-squash
Thanks

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label May 2, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rikatz, shafeeqes

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

@shafeeqes
Copy link
Contributor Author

@rikatz is there some issue in prow? or should I rebase?

@longwuyuan
Copy link
Contributor

@shafeeqes , can you please help and clarify. Have you decided not to write any tests for this.
@rikatz , if @shafeeqes can not add tests for some reason, we should hold this temporarily until somebody else adds a test for this change.

It will not be fair to make this change and have it run on a real world user's cluster.

@rikatz
Copy link
Contributor

rikatz commented May 2, 2022

I will write the tests. Just need to add to my week todo.

We need this in the next release as k8s v1.25 will remove the old lease way

@bmv126
Copy link

bmv126 commented May 17, 2022

@rikatz @shafeeqes
Is this needed from 1.25 and not from 1.24?

@shafeeqes
Copy link
Contributor Author

@rikatz @shafeeqes Is this needed from 1.25 and not from 1.24?

Support for configmaps lock for leaderelection is removed in K8s 1.24 with kubernetes/kubernetes#106852.

@tao12345666333
Copy link
Member

Sorry, I missed this PR.

I created a new PR #8733 for the migration.
I have cherry-picked your second commit into my PR, thanks

@shafeeqes
Copy link
Contributor Author

/close as #8733 is merged

@k8s-ci-robot
Copy link
Contributor

@shafeeqes: PR needs rebase.

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 the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2022
@shafeeqes shafeeqes closed this Jul 9, 2022
@shafeeqes shafeeqes deleted the enhancement/resourcelock branch July 26, 2022 12:18
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. area/docs area/helm Issues or PRs related to helm charts 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. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate ingress-nginx to use Lease API
8 participants