Admission warning (#9975)

* Add warning feature in admission code

* Apply suggestions from code review

Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com>

* Add deprecation and validation path notice

---------

Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
This commit is contained in:
Ricardo Katz 2023-05-25 11:56:52 -03:00 committed by GitHub
parent 897783557a
commit 1282345be2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 177 additions and 0 deletions

View file

@ -33,6 +33,7 @@ import (
// contains invalid instructions
type Checker interface {
CheckIngress(ing *networking.Ingress) error
CheckWarning(ing *networking.Ingress) ([]string, error)
}
// IngressAdmission implements the AdmissionController interface
@ -85,6 +86,15 @@ func (ia *IngressAdmission) HandleAdmission(obj runtime.Object) (runtime.Object,
return review, nil
}
// Adds the warnings regardless of operation being allowed or not
warning, err := ia.Checker.CheckWarning(&ingress)
if err != nil {
klog.ErrorS(err, "failed to get ingress warnings")
}
if len(warning) > 0 {
status.Warnings = warning
}
if err := ia.Checker.CheckIngress(&ingress); err != nil {
klog.ErrorS(err, "invalid ingress configuration", "ingress", fmt.Sprintf("%v/%v", review.Request.Namespace, review.Request.Name))
status.Allowed = false