fixed missing location config from annotation
added e2e test
This commit is contained in:
parent
ae2d6d4220
commit
0a5708bdeb
3 changed files with 87 additions and 4 deletions
|
@ -30,13 +30,13 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
||||||
return proxyInterceptErrors{r}
|
return proxyInterceptErrors{r}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s proxyInterceptErrors) Parse(ing *networking.Ingress) (interface{}, error) {
|
func (pie proxyInterceptErrors) Parse(ing *networking.Ingress) (interface{}, error) {
|
||||||
defBackend := s.r.GetDefaultBackend()
|
|
||||||
|
|
||||||
val, err := parser.GetBoolAnnotation("proxy-intercept-errors", ing)
|
val, err := parser.GetBoolAnnotation("proxy-intercept-errors", ing)
|
||||||
|
|
||||||
// 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 {
|
||||||
return defBackend.ProxyInterceptErrors, nil
|
return true, nil
|
||||||
|
// default is true and only matters when "custom-http-errors" is also set
|
||||||
}
|
}
|
||||||
|
|
||||||
return val, nil
|
return val, nil
|
||||||
|
|
|
@ -1426,6 +1426,7 @@ func locationApplyAnnotations(loc *ingress.Location, anns *annotations.Ingress)
|
||||||
loc.BackendProtocol = anns.BackendProtocol
|
loc.BackendProtocol = anns.BackendProtocol
|
||||||
loc.FastCGI = anns.FastCGI
|
loc.FastCGI = anns.FastCGI
|
||||||
loc.CustomHTTPErrors = anns.CustomHTTPErrors
|
loc.CustomHTTPErrors = anns.CustomHTTPErrors
|
||||||
|
loc.ProxyInterceptErrors = anns.ProxyInterceptErrors
|
||||||
loc.ModSecurity = anns.ModSecurity
|
loc.ModSecurity = anns.ModSecurity
|
||||||
loc.Satisfy = anns.Satisfy
|
loc.Satisfy = anns.Satisfy
|
||||||
loc.Mirror = anns.Mirror
|
loc.Mirror = anns.Mirror
|
||||||
|
|
82
test/e2e/annotations/proxyintercepterrors.go
Normal file
82
test/e2e/annotations/proxyintercepterrors.go
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package annotations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/onsi/ginkgo/v2"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
networking "k8s.io/api/networking/v1"
|
||||||
|
|
||||||
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = framework.DescribeAnnotation("proxy-intercept-errors", func() {
|
||||||
|
f := framework.NewDefaultFramework("proxy-intercept-errors")
|
||||||
|
|
||||||
|
ginkgo.BeforeEach(func() {
|
||||||
|
f.NewEchoDeployment()
|
||||||
|
})
|
||||||
|
|
||||||
|
ginkgo.It("configures Nginx correctly", func() {
|
||||||
|
pieState := "true"
|
||||||
|
host := "pie.foo.com"
|
||||||
|
|
||||||
|
errorCodes := []string{"404"}
|
||||||
|
|
||||||
|
annotations := map[string]string{
|
||||||
|
"nginx.ingress.kubernetes.io/custom-http-errors": strings.Join(errorCodes, ","),
|
||||||
|
"nginx.ingress.kubernetes.io/proxy-intercept-errors": pieState,
|
||||||
|
}
|
||||||
|
|
||||||
|
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||||
|
f.EnsureIngress(ing)
|
||||||
|
|
||||||
|
var serverConfig string
|
||||||
|
f.WaitForNginxServer(host, func(sc string) bool {
|
||||||
|
serverConfig = sc
|
||||||
|
return strings.Contains(serverConfig, fmt.Sprintf("server_name %s", host))
|
||||||
|
})
|
||||||
|
|
||||||
|
ginkgo.By("turning on proxy_intercept_errors directive")
|
||||||
|
assert.Contains(ginkgo.GinkgoT(), serverConfig, "proxy_intercept_errors on;")
|
||||||
|
|
||||||
|
// --
|
||||||
|
pieState = "false"
|
||||||
|
|
||||||
|
ginkgo.By("updating configuration when only proxy-intercept-errors value changes")
|
||||||
|
err := framework.UpdateIngress(f.KubeClientSet, f.Namespace, host, func(ingress *networking.Ingress) error {
|
||||||
|
ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/proxy-intercept-errors"] = pieState
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
assert.Nil(ginkgo.GinkgoT(), err)
|
||||||
|
|
||||||
|
f.WaitForNginxServer(host, func(sc string) bool {
|
||||||
|
if serverConfig != sc {
|
||||||
|
serverConfig = sc
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
ginkgo.By("turning off proxy_intercept_errors directive")
|
||||||
|
assert.NotContains(ginkgo.GinkgoT(), serverConfig, "proxy_intercept_errors on;")
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue