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

Enable setting custom objectSelector for webhook #2407

Merged
merged 5 commits into from
Dec 18, 2021

Conversation

Shreya027
Copy link
Contributor

Issue

#2363

Description

Currently when we install the aws load balancer controller via Helm chart, the objectSelector for Pod Readiness Gate is hard coded without any option to extend it. I have added code to allow custom additions using a template format in webhook.yaml with additional custom values fetched from values.yaml

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

I have Tested 4 sample scenarios:

Test Scenario 1:
One entry added for matchLabels besides matchExpressions default entry.

webhook config snippet:

  namespaceSelector:
    matchExpressions:
    - key: elbv2.k8s.aws/pod-readiness-gate-inject
      operator: In
      values:
      - enabled
  objectSelector:
    matchExpressions:
    - key: app.kubernetes.io/name
      operator: NotIn
      values:
      - aws-load-balancer-controller
    matchLabels:
      testlabel: testvalue

Sample deployment 2048-pods.yaml snippet

apiVersion: apps/v1
kind: Deployment
...
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: app-2048
  replicas: 5
  template:
    metadata:
      labels:
        app.kubernetes.io/name: app-2048
        ...
...        

Corresponding output with no readiness gates configured:

% kubectl apply  -f 2048-pods.yaml        
deployment.apps/deployment-2048 created
% kubectl get pods -owide -A -w                
NAMESPACE     NAME                                            READY   STATUS    RESTARTS   AGE     IP               NODE                                           NOMINATED NODE   READINESS GATES
game-2048     deployment-2048-xxx             1/1     Running   0          9s      xxx  ip-xxx.us-west-2.compute.internal    <none>           <none>
game-2048     deployment-2048-xxx             1/1     Running   0          9s      xxx  ip-xxx.us-west-2.compute.internal    <none>           <none>
game-2048     deployment-2048-xxx             1/1     Running   0          9s      xxx  ip-xxx.us-west-2.compute.internal    <none>           <none>
game-2048     deployment-2048-xxx             1/1     Running   0          9s      xxx  ip-xxx.us-west-2.compute.internal    <none>           <none>
game-2048     deployment-2048-xxx             1/1     Running   0          9s      xxx  ip-xxx.us-west-2.compute.internal    <none>           <none>

Sample deployment 2048-pods-labels.yaml snippet

apiVersion: apps/v1
kind: Deployment
...
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: app-2048
  replicas: 5
  template:
    metadata:
      labels:
        app.kubernetes.io/name: app-2048
        testlabel: testvalue
        ...
...        

Corresponding output with readiness gates configured:

% kubectl apply  -f 2048-pods-labels.yaml        
deployment.apps/deployment-2048 created
% kubectl get pods -owide -A -w                  
NAMESPACE     NAME                                            READY   STATUS    RESTARTS   AGE    IP               NODE                                           NOMINATED NODE   READINESS GATES
game-2048     deployment-xxx                1/1     Running   0          9s     xxx  ip-xxx.us-west-2.compute.internal   <none>           0/1
game-2048     deployment-xxx                1/1     Running   0          9s     xxx  ip-xxx.us-west-2.compute.internal   <none>           0/1
game-2048     deployment-xxx                1/1     Running   0          9s     xxx  ip-xxx.us-west-2.compute.internal   <none>           0/1
game-2048     deployment-xxx                1/1     Running   0          9s     xxx  ip-xxx.us-west-2.compute.internal   <none>           0/1
game-2048     deployment-xxx                1/1     Running   0          9s     xxx  ip-xxx.us-west-2.compute.internal   <none>           0/1

Test Scenario 2:
One entry added for matchLabels and additional entry added to matchExpressions besides default entry.

webhook config snippet :

  namespaceSelector:
    matchExpressions:
    - key: elbv2.k8s.aws/pod-readiness-gate-inject
      operator: In
      values:
      - enabled
  objectSelector:
    matchExpressions:
    - key: app.kubernetes.io/name
      operator: NotIn
      values:
      - aws-load-balancer-controller
    - key: app.kubernetes.io/name
      operator: In
      values:
      - app-2048
    matchLabels:
      testlabel: testvalue

Test Scenario 3:
No entry added for matchLabels and additional entry added to matchExpressions besides default entry.

webhook config snippet:

  namespaceSelector:
    matchExpressions:
    - key: elbv2.k8s.aws/pod-readiness-gate-inject
      operator: In
      values:
      - enabled
  objectSelector:
    matchExpressions:
    - key: app.kubernetes.io/name
      operator: NotIn
      values:
      - aws-load-balancer-controller
    - key: app.kubernetes.io/name
      operator: In
      values:
      - app-2048

Test Scenario 4:
No addition entry added to matchLabels or matchExpressions besides matchExpressions default entry.

webhook config snippet

  namespaceSelector:
    matchExpressions:
    - key: elbv2.k8s.aws/pod-readiness-gate-inject
      operator: In
      values:
      - enabled
  objectSelector:
    matchExpressions:
    - key: app.kubernetes.io/name
      operator: NotIn
      values:
      - aws-load-balancer-controller

I was able to observe the correct behaviour for all the 4 scenarios listed

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 8, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @Shreya027. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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 the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 8, 2021
@codecov-commenter
Copy link

codecov-commenter commented Dec 8, 2021

Codecov Report

Merging #2407 (a693256) into main (2f525fd) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2407   +/-   ##
=======================================
  Coverage   53.35%   53.35%           
=======================================
  Files         140      140           
  Lines        7962     7962           
=======================================
  Hits         4248     4248           
  Misses       3397     3397           
  Partials      317      317           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f525fd...a693256. Read the comment docs.

Copy link
Collaborator

@kishorj kishorj left a comment

Choose a reason for hiding this comment

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

Need to update the README.md as well documenting objectSelector

@@ -232,3 +232,13 @@ backendSecurityGroup:

# disableRestrictedSecurityGroupRules specifies whether to disable creating port-range restricted security group rules for traffic
disableRestrictedSecurityGroupRules:

#objectSelector for webhook
Copy link
Collaborator

@kishorj kishorj Dec 8, 2021

Choose a reason for hiding this comment

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

nit: space after #

#objectSelector for webhook
objectSelector:
matchExpressions:
#- key: <key>
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: space after #

Copy link
Collaborator

Choose a reason for hiding this comment

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

add proper indentation

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 9, 2021
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 9, 2021
@Shreya027
Copy link
Contributor Author

@kishorj Hi have added section in README for the change. I'm guessing doc will be updated separately.

@kishorj kishorj added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Dec 16, 2021
@@ -214,3 +214,5 @@ The default values set by the application itself can be confirmed [here](https:/
| `enableBackendSecurityGroup` | If enabled, controller uses shared security group for backend traffic | `true` |
| `backendSecurityGroup` | Backend security group to use instead of auto created one if the feature is enabled | `` |
| `disableRestrictedSecurityGroupRules` | If disabled, controller will not specify port range restriction in the backend security group rules | `false` |
| `objectSelector.matchExpressions` | Webhook configuration to select specific pods by specifying the expression to be matched | `app.kubernetes.io/name NotIn {{ include "aws-load-balancer-controller.name" . }}` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

The default should be None in this case. The load balancer controller name is currently hardcoded in the template and not configurable.

@@ -214,3 +214,5 @@ The default values set by the application itself can be confirmed [here](https:/
| `enableBackendSecurityGroup` | If enabled, controller uses shared security group for backend traffic | `true` |
| `backendSecurityGroup` | Backend security group to use instead of auto created one if the feature is enabled | `` |
| `disableRestrictedSecurityGroupRules` | If disabled, controller will not specify port range restriction in the backend security group rules | `false` |
| `objectSelector.matchExpressions` | Webhook configuration to select specific pods by specifying the expression to be matched | `app.kubernetes.io/name NotIn {{ include "aws-load-balancer-controller.name" . }}` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
| `objectSelector.matchExpressions` | Webhook configuration to select specific pods by specifying the expression to be matched | `app.kubernetes.io/name NotIn {{ include "aws-load-balancer-controller.name" . }}` |
| `objectSelector.matchExpressions` | Webhook configuration to select specific pods by specifying the expression to be matched | None |

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kishorj, Shreya027

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

@kishorj
Copy link
Collaborator

kishorj commented Dec 17, 2021

/ok-to-test

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. 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 Dec 17, 2021
@Shreya027
Copy link
Contributor Author

/retest

1 similar comment
@kishorj
Copy link
Collaborator

kishorj commented Dec 17, 2021

/retest

@kishorj
Copy link
Collaborator

kishorj commented Dec 18, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 18, 2021
@k8s-ci-robot k8s-ci-robot merged commit d1a22e0 into kubernetes-sigs:main Dec 18, 2021
Timothy-Dougherty pushed a commit to adammw/aws-load-balancer-controller that referenced this pull request Nov 9, 2023
* Enable setting custom objectSelector for webhook kubernetes-sigs#650

* Add formatting changes

* Add webhook changes to README

* Read update suggestion

* Update READ table header to original
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 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.

None yet

4 participants