updated code to new IngressAnnotation interface
This commit is contained in:
parent
cd5452cf4b
commit
f05d795650
1 changed files with 34 additions and 3 deletions
|
@ -24,17 +24,48 @@ import (
|
||||||
"k8s.io/ingress-nginx/internal/ingress/resolver"
|
"k8s.io/ingress-nginx/internal/ingress/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
disableProxyInterceptErrorsAnnotation = "disable-proxy-intercept-errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var disableProxyInterceptErrorsAnnotations = parser.Annotation{
|
||||||
|
Group: "backend",
|
||||||
|
Annotations: parser.AnnotationFields{
|
||||||
|
disableProxyInterceptErrorsAnnotation: {
|
||||||
|
Validator: parser.ValidateBool,
|
||||||
|
Scope: parser.AnnotationScopeLocation,
|
||||||
|
Risk: parser.AnnotationRiskLow,
|
||||||
|
Documentation: `This annotation allows to disable NGINX proxy-intercept-errors when custom-http-errors are set.
|
||||||
|
If a default backend annotation is specified on the ingress, the errors will be routed to that annotation's default backend service (instead of the global default backend).
|
||||||
|
Different ingresses can specify different sets of errors codes and there are UseCases where NGINX shall not intercept all errors returned from upstream.`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
type disableProxyInterceptErrors struct {
|
type disableProxyInterceptErrors struct {
|
||||||
r resolver.Resolver
|
r resolver.Resolver
|
||||||
|
annotationConfig parser.Annotation
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pie disableProxyInterceptErrors) GetDocumentation() parser.AnnotationFields {
|
||||||
|
return pie.annotationConfig.Annotations
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pie disableProxyInterceptErrors) Validate(anns map[string]string) error {
|
||||||
|
maxrisk := parser.StringRiskToRisk(pie.r.GetSecurityConfiguration().AnnotationsRiskLevel)
|
||||||
|
return parser.CheckAnnotationRisk(anns, maxrisk, disableProxyInterceptErrorsAnnotations.Annotations)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewParser creates a new disableProxyInterceptErrors annotation parser
|
// NewParser creates a new disableProxyInterceptErrors annotation parser
|
||||||
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
||||||
return disableProxyInterceptErrors{r}
|
return disableProxyInterceptErrors{
|
||||||
|
r: r,
|
||||||
|
annotationConfig: disableProxyInterceptErrorsAnnotations,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pie disableProxyInterceptErrors) Parse(ing *networking.Ingress) (interface{}, error) {
|
func (pie disableProxyInterceptErrors) Parse(ing *networking.Ingress) (interface{}, error) {
|
||||||
val, err := parser.GetBoolAnnotation("disable-proxy-intercept-errors", ing)
|
val, err := parser.GetBoolAnnotation(disableProxyInterceptErrorsAnnotation, ing, pie.annotationConfig.Annotations)
|
||||||
|
|
||||||
// A missing annotation is not a problem, just use the default
|
// A missing annotation is not a problem, just use the default
|
||||||
if err == errors.ErrMissingAnnotations {
|
if err == errors.ErrMissingAnnotations {
|
||||||
|
|
Loading…
Reference in a new issue