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 (
|
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
|
|
|
|
|
|
|
"k8s.io/ingress/core/pkg/ingress/annotations/parser"
|
2016-12-29 20:02:06 +00:00
|
|
|
"k8s.io/ingress/core/pkg/ingress/resolver"
|
2016-11-10 22:56:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-01-20 21:53:32 +00:00
|
|
|
bodySize = "ingress.kubernetes.io/proxy-body-size"
|
2016-11-10 22:56:29 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Configuration returns the proxy timeout to use in the upstream server/s
|
|
|
|
type Configuration struct {
|
2017-01-20 21:53:32 +00:00
|
|
|
BodySize string `json:"bodySize"`
|
2016-11-16 18:24:26 +00:00
|
|
|
ConnectTimeout int `json:"conectTimeout"`
|
|
|
|
SendTimeout int `json:"sendTimeout"`
|
|
|
|
ReadTimeout int `json:"readTimeout"`
|
|
|
|
BufferSize string `json:"bufferSize"`
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-20 21:53:32 +00:00
|
|
|
return &Configuration{bs, ct, st, rt, bufs}, nil
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|