2016-11-10 22:56:29 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 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 proxy
|
|
|
|
|
|
|
|
import (
|
2017-07-16 19:19:59 +00:00
|
|
|
extensions "k8s.io/api/extensions/v1beta1"
|
2016-11-10 22:56:29 +00:00
|
|
|
|
2017-11-07 22:02:12 +00:00
|
|
|
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
|
|
|
"k8s.io/ingress-nginx/internal/ingress/resolver"
|
2016-11-10 22:56:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-09-01 15:43:11 +00:00
|
|
|
bodySize = "ingress.kubernetes.io/proxy-body-size"
|
|
|
|
connect = "ingress.kubernetes.io/proxy-connect-timeout"
|
|
|
|
send = "ingress.kubernetes.io/proxy-send-timeout"
|
|
|
|
read = "ingress.kubernetes.io/proxy-read-timeout"
|
|
|
|
bufferSize = "ingress.kubernetes.io/proxy-buffer-size"
|
|
|
|
cookiePath = "ingress.kubernetes.io/proxy-cookie-path"
|
|
|
|
cookieDomain = "ingress.kubernetes.io/proxy-cookie-domain"
|
|
|
|
nextUpstream = "ingress.kubernetes.io/proxy-next-upstream"
|
|
|
|
passParams = "ingress.kubernetes.io/proxy-pass-params"
|
|
|
|
requestBuffering = "ingress.kubernetes.io/proxy-request-buffering"
|
2016-11-10 22:56:29 +00:00
|
|
|
)
|
|
|
|
|
2017-11-07 16:36:51 +00:00
|
|
|
// Config returns the proxy timeout to use in the upstream server/s
|
|
|
|
type Config struct {
|
2017-09-01 15:43:11 +00:00
|
|
|
BodySize string `json:"bodySize"`
|
|
|
|
ConnectTimeout int `json:"connectTimeout"`
|
|
|
|
SendTimeout int `json:"sendTimeout"`
|
|
|
|
ReadTimeout int `json:"readTimeout"`
|
|
|
|
BufferSize string `json:"bufferSize"`
|
|
|
|
CookieDomain string `json:"cookieDomain"`
|
|
|
|
CookiePath string `json:"cookiePath"`
|
|
|
|
NextUpstream string `json:"nextUpstream"`
|
|
|
|
PassParams string `json:"passParams"`
|
|
|
|
RequestBuffering string `json:"requestBuffering"`
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 03:07:59 +00:00
|
|
|
// Equal tests for equality between two Configuration types
|
2017-11-07 16:36:51 +00:00
|
|
|
func (l1 *Config) Equal(l2 *Config) bool {
|
2017-06-14 21:33:12 +00:00
|
|
|
if l1 == l2 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if l1 == nil || l2 == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l1.BodySize != l2.BodySize {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l1.ConnectTimeout != l2.ConnectTimeout {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l1.SendTimeout != l2.SendTimeout {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l1.ReadTimeout != l2.ReadTimeout {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l1.BufferSize != l2.BufferSize {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l1.CookieDomain != l2.CookieDomain {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l1.CookiePath != l2.CookiePath {
|
|
|
|
return false
|
|
|
|
}
|
2017-08-31 13:09:23 +00:00
|
|
|
if l1.NextUpstream != l2.NextUpstream {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l1.PassParams != l2.PassParams {
|
|
|
|
return false
|
|
|
|
}
|
2017-06-14 21:33:12 +00:00
|
|
|
|
2017-09-01 15:43:11 +00:00
|
|
|
if l1.RequestBuffering != l2.RequestBuffering {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-06-14 21:33:12 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-12-29 20:02:06 +00:00
|
|
|
type proxy struct {
|
|
|
|
backendResolver resolver.DefaultBackend
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewParser creates a new reverse proxy configuration annotation parser
|
|
|
|
func NewParser(br resolver.DefaultBackend) parser.IngressAnnotation {
|
|
|
|
return proxy{br}
|
|
|
|
}
|
|
|
|
|
2016-11-10 22:56:29 +00:00
|
|
|
// ParseAnnotations parses the annotations contained in the ingress
|
|
|
|
// rule used to configure upstream check parameters
|
2016-12-29 20:02:06 +00:00
|
|
|
func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
|
|
|
defBackend := a.backendResolver.GetDefaultBackend()
|
2016-11-10 22:56:29 +00:00
|
|
|
ct, err := parser.GetIntAnnotation(connect, ing)
|
|
|
|
if err != nil {
|
2016-12-29 20:02:06 +00:00
|
|
|
ct = defBackend.ProxyConnectTimeout
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
st, err := parser.GetIntAnnotation(send, ing)
|
|
|
|
if err != nil {
|
2016-12-29 20:02:06 +00:00
|
|
|
st = defBackend.ProxySendTimeout
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rt, err := parser.GetIntAnnotation(read, ing)
|
|
|
|
if err != nil {
|
2016-12-29 20:02:06 +00:00
|
|
|
rt = defBackend.ProxyReadTimeout
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 21:53:32 +00:00
|
|
|
bufs, err := parser.GetStringAnnotation(bufferSize, ing)
|
|
|
|
if err != nil || bufs == "" {
|
|
|
|
bufs = defBackend.ProxyBufferSize
|
|
|
|
}
|
|
|
|
|
2016-12-27 09:52:04 +00:00
|
|
|
cp, err := parser.GetStringAnnotation(cookiePath, ing)
|
|
|
|
if err != nil || cp == "" {
|
|
|
|
cp = defBackend.ProxyCookiePath
|
|
|
|
}
|
|
|
|
|
|
|
|
cd, err := parser.GetStringAnnotation(cookieDomain, ing)
|
2017-02-24 21:46:39 +00:00
|
|
|
if err != nil || cd == "" {
|
|
|
|
cd = defBackend.ProxyCookieDomain
|
2016-12-27 09:52:04 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 21:53:32 +00:00
|
|
|
bs, err := parser.GetStringAnnotation(bodySize, ing)
|
2016-11-10 22:56:29 +00:00
|
|
|
if err != nil || bs == "" {
|
2017-01-20 21:53:32 +00:00
|
|
|
bs = defBackend.ProxyBodySize
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 19:39:24 +00:00
|
|
|
nu, err := parser.GetStringAnnotation(nextUpstream, ing)
|
|
|
|
if err != nil || nu == "" {
|
|
|
|
nu = defBackend.ProxyNextUpstream
|
|
|
|
}
|
|
|
|
|
2017-08-31 13:09:23 +00:00
|
|
|
pp, err := parser.GetStringAnnotation(passParams, ing)
|
|
|
|
if err != nil || pp == "" {
|
|
|
|
pp = defBackend.ProxyPassParams
|
|
|
|
}
|
|
|
|
|
2017-09-01 15:43:11 +00:00
|
|
|
rb, err := parser.GetStringAnnotation(requestBuffering, ing)
|
|
|
|
if err != nil || rb == "" {
|
|
|
|
rb = defBackend.ProxyRequestBuffering
|
|
|
|
}
|
|
|
|
|
2017-11-07 16:36:51 +00:00
|
|
|
return &Config{bs, ct, st, rt, bufs, cd, cp, nu, pp, rb}, nil
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|