2017-07-16 20:19:45 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 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 serviceupstream
|
|
|
|
|
|
|
|
import (
|
2021-08-21 20:42:00 +00:00
|
|
|
networking "k8s.io/api/networking/v1"
|
2017-07-16 20:19:45 +00:00
|
|
|
|
2017-11-08 20:58:57 +00:00
|
|
|
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
2021-09-07 19:47:15 +00:00
|
|
|
"k8s.io/ingress-nginx/internal/ingress/errors"
|
2017-11-08 20:58:57 +00:00
|
|
|
"k8s.io/ingress-nginx/internal/ingress/resolver"
|
2017-07-16 20:19:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type serviceUpstream struct {
|
2017-11-08 20:58:57 +00:00
|
|
|
r resolver.Resolver
|
2017-07-16 20:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewParser creates a new serviceUpstream annotation parser
|
2017-11-08 20:58:57 +00:00
|
|
|
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
|
|
|
return serviceUpstream{r}
|
2017-07-16 20:19:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-09 22:49:59 +00:00
|
|
|
func (s serviceUpstream) Parse(ing *networking.Ingress) (interface{}, error) {
|
2021-09-07 19:47:15 +00:00
|
|
|
defBackend := s.r.GetDefaultBackend()
|
|
|
|
|
|
|
|
val, err := parser.GetBoolAnnotation("service-upstream", ing)
|
|
|
|
// A missing annotation is not a problem, just use the default
|
|
|
|
if err == errors.ErrMissingAnnotations {
|
|
|
|
return defBackend.ServiceUpstream, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return val, nil
|
2017-07-16 20:19:45 +00:00
|
|
|
}
|