ingress-nginx-helm/internal/ingress/annotations/healthcheck/main.go

62 lines
1.7 KiB
Go
Raw Normal View History

2016-05-16 20:29:33 +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-07-16 19:19:59 +00:00
extensions "k8s.io/api/extensions/v1beta1"
2016-05-16 20:29:33 +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-05-16 20:29:33 +00:00
)
2017-11-07 16:36:51 +00:00
// Config returns the URL and method to use check the status of
2016-05-16 20:29:33 +00:00
// the upstream server/s
2017-11-07 16:36:51 +00:00
type Config 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
}
type healthCheck struct {
2017-11-08 20:58:57 +00:00
r resolver.Resolver
}
// NewParser creates a new health check annotation parser
2017-11-08 20:58:57 +00:00
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return healthCheck{r}
}
2016-05-16 20:29:33 +00:00
// ParseAnnotations parses the annotations contained in the ingress
// rule used to configure upstream check parameters
2017-11-08 20:58:57 +00:00
func (hc healthCheck) Parse(ing *extensions.Ingress) (interface{}, error) {
defBackend := hc.r.GetDefaultBackend()
2016-05-16 20:29:33 +00:00
if ing.GetAnnotations() == nil {
2017-11-07 16:36:51 +00:00
return &Config{defBackend.UpstreamMaxFails, defBackend.UpstreamFailTimeout}, nil
2016-05-16 20:29:33 +00:00
}
2017-11-08 20:58:57 +00:00
mf, err := parser.GetIntAnnotation("upstream-max-fails", ing, hc.r)
2016-05-16 20:29:33 +00:00
if err != nil {
mf = defBackend.UpstreamMaxFails
2016-05-16 20:29:33 +00:00
}
2017-11-08 20:58:57 +00:00
ft, err := parser.GetIntAnnotation("upstream-fail-timeout", ing, hc.r)
2016-05-16 20:29:33 +00:00
if err != nil {
ft = defBackend.UpstreamFailTimeout
2016-05-16 20:29:33 +00:00
}
2017-11-07 16:36:51 +00:00
return &Config{mf, ft}, nil
2016-05-16 20:29:33 +00:00
}