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:
parent
897783557a
commit
1282345be2
4 changed files with 177 additions and 0 deletions
|
|
@ -256,6 +256,54 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetWarnings returns a list of warnings an Ingress gets when being created.
|
||||
// The warnings are going to be used in an admission webhook, and they represent
|
||||
// a list of messages that users need to be aware (like deprecation notices)
|
||||
// when creating a new ingress object
|
||||
func (n *NGINXController) CheckWarning(ing *networking.Ingress) ([]string, error) {
|
||||
warnings := make([]string, 0)
|
||||
|
||||
var deprecatedAnnotations = sets.NewString()
|
||||
deprecatedAnnotations.Insert(
|
||||
"enable-influxdb",
|
||||
"influxdb-measurement",
|
||||
"influxdb-port",
|
||||
"influxdb-host",
|
||||
"influxdb-server-name",
|
||||
"secure-verify-ca-secret",
|
||||
"fastcgi-params-configmap",
|
||||
"fastcgi-index",
|
||||
)
|
||||
|
||||
// Skip checks if the ingress is marked as deleted
|
||||
if !ing.DeletionTimestamp.IsZero() {
|
||||
return warnings, nil
|
||||
}
|
||||
|
||||
anns := ing.GetAnnotations()
|
||||
for k := range anns {
|
||||
trimmedkey := strings.TrimPrefix(k, parser.AnnotationsPrefix+"/")
|
||||
if deprecatedAnnotations.Has(trimmedkey) {
|
||||
warnings = append(warnings, fmt.Sprintf("annotation %s is deprecated", k))
|
||||
}
|
||||
}
|
||||
|
||||
// Add each validation as a single warning
|
||||
// rikatz: I know this is somehow a duplicated code from CheckIngress, but my goal was to deliver fast warning on this behavior. We
|
||||
// can and should, tho, simplify this in the near future
|
||||
if err := inspector.ValidatePathType(ing); err != nil {
|
||||
if errs, is := err.(interface{ Unwrap() []error }); is {
|
||||
for _, errW := range errs.Unwrap() {
|
||||
warnings = append(warnings, errW.Error())
|
||||
}
|
||||
} else {
|
||||
warnings = append(warnings, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return warnings, nil
|
||||
}
|
||||
|
||||
// CheckIngress returns an error in case the provided ingress, when added
|
||||
// to the current configuration, generates an invalid configuration
|
||||
func (n *NGINXController) CheckIngress(ing *networking.Ingress) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue