-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Validate Ingress condition annotations #2735
Conversation
Welcome @r-erema! |
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 Once the patch is verified, the new status will be reflected by the 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. |
e316b31
to
c3cf11f
Compare
c3cf11f
to
bb0b89d
Compare
/assign @M00nF1sh |
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:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
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:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/remove-lifecycle rotten
pkg/ingress/config_types.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johngmyers Thanks a lot!
t.logger.Error(err, "Ingress has invalid annotation for service, thus will be ignored", | ||
"Ingress", | ||
ing, | ||
"Service name", | ||
path.Backend.Service.Name, | ||
) |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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,
)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:-)
/ok-to-test |
Would it be possible to put these checks in the validating admission webhook so such ingresses don't get created in the first place? |
If you want to explore the validating admission webhook path, the code is in 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. |
annotationParser: annotationParser, | ||
classAnnotationMatcher: classAnnotationMatcher, | ||
disableIngressGroupAnnotation: tt.fields.disableIngressGroupAnnotation, | ||
logger: &log.NullLogger{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger: &log.NullLogger{}, | |
logger: logr.New(&log.NullLogSink{}), |
There was a problem hiding this comment.
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!
You should change the title of the PR. Something like "Validate Ingress condition annotations". |
17a5cc3
to
5841971
Compare
@johngmyers Done
Fixed as well |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validation returned back
5841971
to
d8ec5c3
Compare
[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 |
/lgtm |
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)
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
README.md
, or thedocs
directory)BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯