2016-05-16 20:29:33 +00:00
|
|
|
/*
|
2016-09-08 11:02:39 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
2016-05-16 20:29:33 +00:00
|
|
|
|
|
|
|
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 healthcheck
|
|
|
|
|
|
|
|
import (
|
2017-04-01 14:39:42 +00:00
|
|
|
extensions "k8s.io/client-go/pkg/apis/extensions/v1beta1"
|
2016-05-16 20:29:33 +00:00
|
|
|
|
2016-11-10 22:56:29 +00:00
|
|
|
"k8s.io/ingress/core/pkg/ingress/annotations/parser"
|
2016-12-29 20:02:06 +00:00
|
|
|
"k8s.io/ingress/core/pkg/ingress/resolver"
|
2016-05-16 20:29:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2016-05-31 16:22:04 +00:00
|
|
|
upsMaxFails = "ingress.kubernetes.io/upstream-max-fails"
|
|
|
|
upsFailTimeout = "ingress.kubernetes.io/upstream-fail-timeout"
|
2016-05-16 20:29:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Upstream returns the URL and method to use check the status of
|
|
|
|
// the upstream server/s
|
|
|
|
type Upstream struct {
|
2016-11-16 18:24:26 +00:00
|
|
|
MaxFails int `json:"maxFails"`
|
|
|
|
FailTimeout int `json:"failTimeout"`
|
2016-05-16 20:29:33 +00:00
|
|
|
}
|
|
|
|
|
2016-12-29 20:02:06 +00:00
|
|
|
type healthCheck struct {
|
|
|
|
backendResolver resolver.DefaultBackend
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewParser creates a new health check annotation parser
|
|
|
|
func NewParser(br resolver.DefaultBackend) parser.IngressAnnotation {
|
|
|
|
return healthCheck{br}
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:29:33 +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 healthCheck) Parse(ing *extensions.Ingress) (interface{}, error) {
|
|
|
|
defBackend := a.backendResolver.GetDefaultBackend()
|
2016-05-16 20:29:33 +00:00
|
|
|
if ing.GetAnnotations() == nil {
|
2016-12-29 20:02:06 +00:00
|
|
|
return &Upstream{defBackend.UpstreamMaxFails, defBackend.UpstreamFailTimeout}, nil
|
2016-05-16 20:29:33 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 22:56:29 +00:00
|
|
|
mf, err := parser.GetIntAnnotation(upsMaxFails, ing)
|
2016-05-16 20:29:33 +00:00
|
|
|
if err != nil {
|
2016-12-29 20:02:06 +00:00
|
|
|
mf = defBackend.UpstreamMaxFails
|
2016-05-16 20:29:33 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 22:56:29 +00:00
|
|
|
ft, err := parser.GetIntAnnotation(upsFailTimeout, ing)
|
2016-05-16 20:29:33 +00:00
|
|
|
if err != nil {
|
2016-12-29 20:02:06 +00:00
|
|
|
ft = defBackend.UpstreamFailTimeout
|
2016-05-16 20:29:33 +00:00
|
|
|
}
|
|
|
|
|
2016-12-29 20:02:06 +00:00
|
|
|
return &Upstream{mf, ft}, nil
|
2016-05-16 20:29:33 +00:00
|
|
|
}
|