Skip to content

fix: ensure boolean flags are only passed when their corresponding Helm chart value is true #467

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 1 commit into from
Sep 14, 2023

Conversation

a-hilaly
Copy link
Member

Issue: aws-controllers-k8s/community#1893

In this commit, we address the issue of passing boolean flags in a more
solid way.

We've observed an odd obehaviour when a user attempts to
disabled a feature (e.g leaderElection/developmentLogging), which
causes the flag to be enabled instead.

The main root cause of this issue was, using environment vairables with
the pflag library, combined with the fact that spf13/cobra library
conciders passed boolean flags with no values (no =<value>) as true

The fix consists of

  1. Avoid using environment variables for boolean flags.
  2. Updating the helm template to only pass boolean flags when their
    respctive helm chat values are present.

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

…rt value is true

In this commit, we address the issue of passing boolean flags in a more
solid way. We've observed an odd obehaviour when a user attempts to
disabled a feature (e.g `leaderElection/developmentLogging`), which
causes the flag to be enabled instead.

The main root cause of this issue was, using environment vairables with
the `pflag` library, combined with the fact that `spf13/cobra` library
conciders passed boolean flags with no values (no `=<value>`) as `true`

The fix consists of
1. Avoid using environment variables for boolean flags.
2. Updating the helm template to only pass boolean flags when their
   respctive helm chat values are present.

Signed-off-by: Amine <[email protected]>
@ack-prow ack-prow bot requested review from jaypipes and vijtrip2 September 13, 2023 23:58
@ack-prow ack-prow bot added the approved label Sep 13, 2023
@a-hilaly
Copy link
Member Author

a-hilaly commented Sep 14, 2023

Manually tested these cases:

helm upgrade -n ack-system -f helm/values.yaml kayak ./helm --set=aws.region=us-west-2 \
  --set=leaderElection.enabled=true --set=leaderElection.namespace=ack-system

helm upgrade -n ack-system -f helm/values.yaml kayak ./helm --set=aws.region=us-west-2 \
  --set=leaderElection.enabled=false
helm upgrade -n ack-system -f helm/values.yaml kayak ./helm --set=aws.region=us-west-2 --set=leaderElection.enabled=false --dry-run > disabled.yaml

helm upgrade -n ack-system -f helm/values.yaml kayak ./helm --set=aws.region=us-west-2 --set=leaderElection.enabled=true --set=leaderElection.namespace=ack-system --dry-run > enabled.yaml

diff enabled.yaml disabled.yaml                                                                                ✔ 
3c3
< LAST DEPLOYED: Wed Sep 13 18:59:33 2023
---
> LAST DEPLOYED: Wed Sep 13 18:59:48 2023
139,167d138
< # Source: s3-chart/templates/leader-election-role.yaml
< apiVersion: rbac.authorization.k8s.io/v1
< kind: Role
< metadata:
<   name: s3-leader-election-role
< 
<   namespace: ack-system
< 
< rules:
< - apiGroups:
<   - coordination.k8s.io
<   resources:
<   - leases
<   verbs:
<   - get
<   - list
<   - watch
<   - create
<   - update
<   - patch
<   - delete
< - apiGroups:
<   - ""
<   resources:
<   - events
<   verbs:
<   - create
<   - patch
< ---
215,231d185
< # Source: s3-chart/templates/leader-election-role-binding.yaml
< apiVersion: rbac.authorization.k8s.io/v1
< kind: RoleBinding
< metadata:
<   name: s3-leader-election-rolebinding
< 
<   namespace: ack-system
< 
< roleRef:
<   apiGroup: rbac.authorization.k8s.io
<   kind: Role
<   name: s3-leader-election-role
< subjects:
< - kind: ServiceAccount
<   name: ack-s3-controller
<   namespace: ack-system
< ---
276,278d229
<         - --enable-leader-election
<         - --leader-election-namespace
<         - "$(LEADER_ELECTION_NAMESPACE)"
307,310d257
<         - name: ENABLE_LEADER_ELECTION
<           value: "true"
<         - name: LEADER_ELECTION_NAMESPACE
<           value: "ack-system"

@jljaco
Copy link
Contributor

jljaco commented Sep 14, 2023

/lgtm

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

ack-prow bot commented Sep 14, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a-hilaly, acornett21, jljaco

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

@a-hilaly
Copy link
Member Author

/retest

@ack-prow ack-prow bot merged commit 2fce204 into aws-controllers-k8s:main Sep 14, 2023
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