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

Validate Ingress condition annotations #2735

Conversation

r-erema
Copy link
Contributor

@r-erema r-erema commented Jul 24, 2022

Issue

#2042

Description

Earlier if at least 1 ingress in the group has an invalid annotation the rest of the ingresses in the group aren't took into account during building listener rules.

I've handled the condition validation error separately to prevent the termination of the process of the building listener rules for valid ingresses if such an error occurs.

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 🌟

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 24, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: r-erema / name: Roma Erema (c3cf11f973f16c81703cda5549dcc766c484f7d0)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 24, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @r-erema!

It looks like this is your first PR to kubernetes-sigs/aws-load-balancer-controller 🎉. 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-sigs/aws-load-balancer-controller 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 k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 24, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @r-erema. 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 24, 2022
@k8s-ci-robot k8s-ci-robot requested review from kishorj and M00nF1sh July 24, 2022 13:41
@r-erema r-erema force-pushed the 2042-stuck-cintroller-ingress-invalid-condition branch from e316b31 to c3cf11f Compare July 25, 2022 06:25
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 25, 2022
@r-erema r-erema force-pushed the 2042-stuck-cintroller-ingress-invalid-condition branch from c3cf11f to bb0b89d Compare July 25, 2022 07:46
@kishorj kishorj added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 25, 2022
@r-erema
Copy link
Contributor Author

r-erema commented Jul 26, 2022

/assign @M00nF1sh

@r-erema
Copy link
Contributor Author

r-erema commented Sep 8, 2022

@M00nF1sh @kishorj Hi, kindly reminder about PR. Please, estimate when it can get to the review. Thanks!

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 7, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 6, 2023
@r-erema
Copy link
Contributor Author

r-erema commented Jan 7, 2023

/remove-lifecycle

Copy link
Contributor

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

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

/remove-lifecycle rotten

@@ -238,7 +240,7 @@ type HTTPRequestMethodConditionConfig struct {

func (c *HTTPRequestMethodConditionConfig) validate() error {
if len(c.Values) == 0 {
return errors.New("values cannot be empty")
return errors.Wrap(errConditionValidation, "values cannot be empty")
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer fmt.Errorf() and %w for wrapping errors.

But this isn't the use case for wrapping; one should probably use a custom error type and a constructor.

Copy link
Contributor Author

@r-erema r-erema Jan 19, 2023

Choose a reason for hiding this comment

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

@johngmyers Agree regarding to fmt.Errorf().

But this isn't the use case for wrapping

What are cases for wrapping and what for creation custom type? It will be good to understand for me to make it properly in the future. Thanks!

Copy link
Contributor

@johngmyers johngmyers Jan 20, 2023

Choose a reason for hiding this comment

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

The canonical case for wrapping is when you received an error from doing a call and you want to add information about the context in which the error occurred before passing it up to your caller. I tend to start the wrapping message with a gerund, for example "writing file %q".

A custom error type is for when the caller needs to programmatically check if a particular error condition occurred. In this case, the caller wants to know if there was an invalid rule condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johngmyers Thanks a lot!

Comment on lines 37 to 42
t.logger.Error(err, "Ingress has invalid annotation for service, thus will be ignored",
"Ingress",
ing,
"Service name",
path.Backend.Service.Name,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't the clearest error message. And logging an entire ClassifiedIngress is noisy.

Perhaps something like "Ignoring Ingress NAMESPACE/NAME: alb.ingress.kubernetes.io/conditions.SERVICE annotation: ERROR"

Copy link
Contributor Author

@r-erema r-erema Jan 19, 2023

Choose a reason for hiding this comment

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

@johngmyers Sticking the same style of logging error in that project, where I noticed first go a common error message at the beggining and then entities involved in the error in key-values format, e.g.

h.logger.Error(err, "failed to get nodeSelector", "TargetGroupBinding", tgb)

r.logger.Error(err, "ignore pod Endpoint without non-exist nodeInfo", "podKey", podKey.String())

I'll change your suggested error format a little, but anyway make it less noisy

t.logger.Error(err, "Ignoring Ingress invalid annotation",
  "Ingress", fmt.Sprintf("%s/%s", ing.Ing.Namespace, ing.Ing.Name),
  "Service", path.Backend.Service.Name,
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider logging the annotation key. It might not be obvious that it's the actions. annotation this is referring to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might not be obvious that it's the actions.

@johngmyers Probably you've meant conditions., I'll add that info to error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems I unintentionally proved my point:-)

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Jan 10, 2023
@johngmyers
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 10, 2023
@johngmyers
Copy link
Contributor

Would it be possible to put these checks in the validating admission webhook so such ingresses don't get created in the first place?

@johngmyers
Copy link
Contributor

johngmyers commented Jan 20, 2023

If you want to explore the validating admission webhook path, the code is in webhooks/networking/ingress_validator.go.

Although the existing ingress_validator code uses generic errors, it would be better to return API validation errors from apimachinery. Examples of this can be found in my PR #2945.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 20, 2023
annotationParser: annotationParser,
classAnnotationMatcher: classAnnotationMatcher,
disableIngressGroupAnnotation: tt.fields.disableIngressGroupAnnotation,
logger: &log.NullLogger{},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger: &log.NullLogger{},
logger: logr.New(&log.NullLogSink{}),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue was in depricated &log.NullLogger{}, need to be used logr.Discard() instead. Thanks anyway!

@johngmyers
Copy link
Contributor

You should change the title of the PR. Something like "Validate Ingress condition annotations".

@r-erema r-erema force-pushed the 2042-stuck-cintroller-ingress-invalid-condition branch from 17a5cc3 to 5841971 Compare January 28, 2023 09:49
@r-erema r-erema changed the title Ignoring ingresses in the group with invalid conditions in the annotation Validate Ingress condition annotations Jan 28, 2023
@r-erema
Copy link
Contributor Author

r-erema commented Jan 28, 2023

You should change the title of the PR. Something like "Validate Ingress condition annotations".

@johngmyers Done

I have the failed job "pull-aws-load-balancer-controller-unit-test"

Fixed as well

@r-erema r-erema requested review from johngmyers and removed request for kishorj and M00nF1sh January 28, 2023 10:20
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.

Thanks for your contribution. We still need the validation block in buildConditions(). I'm fine with the changes otherwise.

@@ -164,11 +164,7 @@ func (b *defaultEnhancedBackendBuilder) buildConditions(_ context.Context, ingAn
if err != nil {
return nil, err
}
for _, condition := range conditions {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please keep this validation block in place. We've seen feature requests to optionally disable validation webhook for ingress. There would also be a case where the invalid ingress already exists before the controller got updated. We still want to error out from model builder if validation fails.

Copy link
Contributor

@johngmyers johngmyers Feb 4, 2023

Choose a reason for hiding this comment

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

I do not think we should support disabling our validation webhook for ingress. If someone disables it, they can deal with the fallout of configurations the webhook would have prevented.

We should not add unnecessary complexity.

Copy link
Contributor Author

@r-erema r-erema Feb 5, 2023

Choose a reason for hiding this comment

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

As for me I'm not a fan of duplication of logic/checkings etc, so I'd prefer to keep validation in 1 place. @kishorj @johngmyers can we meet consolidate decision(maybe by community voting, etc.)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We discussed further on this matter in the provider-aws meeting. Since there is a possibility of having ingress resources from a prior version (before the webhook validation), we still do these validation for 2.5.0. We can clean up the validation in future releases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Validation returned back

@r-erema r-erema force-pushed the 2042-stuck-cintroller-ingress-invalid-condition branch from 5841971 to d8ec5c3 Compare February 19, 2023 05:44
@r-erema r-erema requested review from kishorj and removed request for johngmyers February 19, 2023 07:04
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kishorj, r-erema

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 20, 2023
@kishorj
Copy link
Collaborator

kishorj commented Feb 20, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 20, 2023
@k8s-ci-robot k8s-ci-robot merged commit 4530894 into kubernetes-sigs:main Feb 21, 2023
johngmyers pushed a commit to johngmyers/aws-load-balancer-controller that referenced this pull request Aug 21, 2023
Merge in DEL/aws-load-balancer-controller-fork from DELIVERY-8202_pull_upstream to main

* commit '49805eac72ec533acdbc2580d6f57c68a9cad45c':
  update the default base image (kubernetes-sigs#3075)
  update recommended IAM policy template (kubernetes-sigs#3068)
  update to discovery.k8s.io/v1 (kubernetes-sigs#3072)
  validation ingress condition annotation in validation webhook (kubernetes-sigs#2735)
  Fix conciseLogger's incorrect call to variadic func (kubernetes-sigs#3066)
  Verify CRDs are up to date in merge check (kubernetes-sigs#3022)
  Refactor model builder test (kubernetes-sigs#3024)
@johngmyers johngmyers mentioned this pull request Aug 23, 2023
12 tasks
Timothy-Dougherty pushed a commit to adammw/aws-load-balancer-controller that referenced this pull request Nov 9, 2023
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/L Denotes a PR that changes 100-499 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.

6 participants