Skip to content

Add leader elections flags/values to the deployment manifests #455

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

Merged
merged 3 commits into from
Sep 7, 2023

Conversation

a-hilaly
Copy link
Member

@a-hilaly a-hilaly commented Jul 17, 2023

Issue: aws-controllers-k8s/community#1753 (comment)

ACK controllers use k8s-sigs/controller-runtime behind the scenes, which
support leader election. This feature is not properly working due to a
missing configuration LeaderElectionNamespace which is used by the
manager to create k8s.io/coordination Lease objects.

This patch sets the default LeaderElectionNamespace to ack-system
and adds the capability of enabling leader election using helm values.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Co-authored-by: Adam Cornett [email protected]

@ack-prow ack-prow bot requested review from jljaco and vijtrip2 July 17, 2023 21:05
@ack-prow ack-prow bot added the approved label Jul 17, 2023
LeaderElection: ackCfg.EnableLeaderElection,
LeaderElectionID: awsServiceAPIGroup,
Namespace: ackCfg.WatchNamespace,
LeaderElectionNamespace: ackSystemNamespace,
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 was thinking about adding a --leader-election-namespace flag to allow users to set their own.. thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not the sure what the use case for this flag is, or what it actually does under the covers. operator-sdk only scaffolds with the below options:

        Scheme:                 scheme,
        MetricsBindAddress:     metricsAddr,
        Port:                   9443,
        HealthProbeBindAddress: probeAddr,
        LeaderElection:         enableLeaderElection,
        LeaderElectionID:       leaderElectionID,

Copy link
Member Author

Choose a reason for hiding this comment

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

LeaderElectionNamespace is the namespace where the Lease object is created

Copy link
Member Author

Choose a reason for hiding this comment

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

Without namespace, i'm running into unable to create controller manager {"aws.service": "lambda", "error": "unable to find leader election namespace: not running in-cluster, please specify LeaderElectionNamespace"} - does operator-sdk use leases as well? or maybe configmaps (that's what controller-runtime used before leases introduction)?

@a-hilaly a-hilaly requested a review from RedbackThomson July 17, 2023 21:06
@a-hilaly
Copy link
Member Author

Example logs of a controller acquiring leader lease:

I0717 22:07:29.267656  313484 leaderelection.go:248] attempting to acquire leader lease ack-system/lambda.services.k8s.aws...
I0717 22:07:29.282064  313484 leaderelection.go:258] successfully acquired lease ack-system/lambda.services.k8s.aws
2023-07-17T22:07:29.282+0100	DEBUG	events	ma_ca5abb0a-74fe-45a9-85e1-3b0c3a95e9ac became leader	{"type": "Normal", "object": {"kind":"Lease","namespace":"ack-system","name":"lambda.services.k8s.aws","uid":"a68f0032-2021-436a-b4a2-91fb44f297e9","apiVersion":"coordination.k8s.io/v1","resourceVersion":"383697"}, "reason": "LeaderElection"}

Example logs of a controller waiting for leader lease to be freed:

I0717 22:10:32.402053  314991 leaderelection.go:248] attempting to acquire leader lease ack-system/lambda.services.k8s.aws...

Copy link
Contributor

@acornett21 acornett21 left a comment

Choose a reason for hiding this comment

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

I feel like this change should be duplicated to the kuztomize templates as well.

@a-hilaly a-hilaly changed the title Add missing leader election configuration to the controller manager Add leader elections flags/values to the deployment manifests Jul 19, 2023
@a-hilaly
Copy link
Member Author

/retest

1 similar comment
@a-hilaly
Copy link
Member Author

/retest

Copy link
Contributor

@acornett21 acornett21 left a comment

Choose a reason for hiding this comment

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

A few changes to this are needed. Also, we still need the leader-elect RBAC files and changes that I sent as a patch, otherwise this will not work.

ack-prow bot pushed a commit that referenced this pull request Aug 24, 2023
Issue #, if available:
N/A

Description of changes:
Fixing deployment `args` to have boolean values on a single line. This is needed since the presence of the flag itself is a `truthy` statement, and the next line for the `env` is ignored. See [this](#455 (comment)) comment on `leader-elect` PR for more info.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
@a-hilaly a-hilaly force-pushed the leader-election branch 3 times, most recently from b5a9929 to fb8f197 Compare August 24, 2023 21:21
@a-hilaly
Copy link
Member Author

/test ecr-controller-test

Comment on lines 8 to 18
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
Copy link
Contributor

Choose a reason for hiding this comment

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

I have confirmed that ACK does not need the configmap. This is sort of an either/or thing, where configmap or leases can be used, and the operator developer can choose which to use. For legacy purposes and for operators that might have been developed before leases were created, this is kept in the scaffolding.

Since ACK isn't exposing this flag which allows the choice, we are safe to remove the confimap section from the RBAC.

@a-hilaly I hope all the above makes sense, let me know if there are questions...After this is removed I think we are good to go.

@a-hilaly
Copy link
Member Author

/retest

@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 5, 2023

/hold

need to pin runtime v0.27.1

@ack-prow ack-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 5, 2023
@acornett21
Copy link
Contributor

@a-hilaly Why did you revert the RBAC changes?

@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 5, 2023

@a-hilaly Why did you revert the RBAC changes?

@acornett21 Looks like it's gonna be a bigger change than we expected.. since the feature is disabled by default, it's safe to go with this now and we will address the RBAC matters in a seperate PR

@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 5, 2023

/test dynamodb-controller-test

@acornett21
Copy link
Contributor

since the feature is disabled by default, it's safe to go with this now and we will address the RBAC matters in a seperate PR

@a-hilaly Can you elaborate on this? If someone goes to enable this, the controller will fail to function and throw errors without RBAC changes present.

@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 5, 2023

@a-hilaly Can you elaborate on this? If someone goes to enable this, the controller will fail to function and throw errors without RBAC changes present.

Yes that's correct.

We wanted to make the release quickly today without RBAC support for few reasons:

  • We need to release new images with security patches + fix a panic with controllers running in k8s 1.27
  • The current tests with Leases RBACs were failing
  • It's a bit hard to know what do with cluster scoped vs namepsaced scoped controllers. (this influences whether a controller will use a role vs clusterRole
  • FieldExport currently doesn't come with supported RBAC permissions. Customers set their own (secret/cm) RBACs. Leader election will take similar path at least in the short term.

I still would like to come up with a plan to add those RBACs in a seperate PR, i want to open one as soon as this one is merged.

@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 5, 2023

/test s3-controller-test
/test ecr-controller-test

@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 6, 2023

@acornett21 good points, and thank you for bringing this! I just added few configurations for kustomize and helm chart templates.

ACK controllers use k8s-sigs/controller-runtime behind the scenes, which
support leader election. This feature is not properly working due to a
missing configuration `LeaderElectionNamespace` which is used by the
manager to create `k8s.io/coordination` Lease objects.

This patch sets the default `LeaderElectionNamespace` to `ack-system`
and adds the capability of enabling leader election using helm values.

Co-authored-by: Adam Cornett <[email protected]>
@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 6, 2023

/retest

Copy link
Contributor

@RedbackThomson RedbackThomson left a comment

Choose a reason for hiding this comment

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

/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Sep 6, 2023
@ack-prow ack-prow bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 6, 2023
Copy link
Contributor

@RedbackThomson RedbackThomson left a comment

Choose a reason for hiding this comment

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

/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Sep 6, 2023
@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 6, 2023

/retest

@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 7, 2023

/lgtm cancel

@ack-prow ack-prow bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 7, 2023
@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 7, 2023

/hold

@ack-prow ack-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 7, 2023
@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 7, 2023

/unhold

@ack-prow ack-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 7, 2023
@RedbackThomson
Copy link
Contributor

/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Sep 7, 2023
@ack-prow
Copy link

ack-prow bot commented Sep 7, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acornett21, RedbackThomson

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

@ack-prow ack-prow bot merged commit 2f2b5e9 into aws-controllers-k8s:main Sep 7, 2023
ack-prow bot pushed a commit to aws-controllers-k8s/community that referenced this pull request Sep 7, 2023
…1884)

Issue #, if available:
- Relates: aws-controllers-k8s/code-generator#455

Description of changes:
Adding these env's to the configmap so when leader election code is merged, installs on OpenShift can still function properly.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Vandita2020 pushed a commit to Vandita2020/ack-code-generator that referenced this pull request Sep 25, 2023
…ntrollers-k8s#457)

Issue #, if available:
N/A

Description of changes:
Fixing deployment `args` to have boolean values on a single line. This is needed since the presence of the flag itself is a `truthy` statement, and the next line for the `env` is ignored. See [this](aws-controllers-k8s#455 (comment)) comment on `leader-elect` PR for more info.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants