Support networking.k8s.io/v1beta1 Ingresses

Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
This commit is contained in:
Mikkel Oscar Lyderik Larsen 2019-10-08 16:55:49 +02:00
parent 0de5042d3d
commit 5e6d304ecd
No known key found for this signature in database
GPG Key ID: 50AD98B2A0D8D4EF

View File

@ -125,21 +125,40 @@ func getWeights(ingressAnnotations map[string]string, backendAnnotations []strin
// getCollector returns a collector for getting the metrics. // getCollector returns a collector for getting the metrics.
func (c *SkipperCollector) getCollector() (Collector, error) { func (c *SkipperCollector) getCollector() (Collector, error) {
ingress, err := c.client.ExtensionsV1beta1().Ingresses(c.objectReference.Namespace).Get(c.objectReference.Name, metav1.GetOptions{}) var annotations map[string]string
if err != nil { var hosts []string
return nil, err
switch c.objectReference.APIVersion {
case "extensions/v1beta1":
ingress, err := c.client.ExtensionsV1beta1().Ingresses(c.objectReference.Namespace).Get(c.objectReference.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}
annotations = ingress.Annotations
for _, rule := range ingress.Spec.Rules {
hosts = append(hosts, rule.Host)
}
case "networking.k8s.io/v1beta1":
ingress, err := c.client.NetworkingV1beta1().Ingresses(c.objectReference.Namespace).Get(c.objectReference.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}
annotations = ingress.Annotations
for _, rule := range ingress.Spec.Rules {
hosts = append(hosts, rule.Host)
}
} }
backendWeight, err := getWeights(ingress.Annotations, c.backendAnnotations, c.backend) backendWeight, err := getWeights(annotations, c.backendAnnotations, c.backend)
if err != nil { if err != nil {
return nil, err return nil, err
} }
config := c.config config := c.config
var collector Collector var collector Collector
collectors := make([]Collector, 0, len(ingress.Spec.Rules)) collectors := make([]Collector, 0, len(hosts))
for _, rule := range ingress.Spec.Rules { for _, host := range hosts {
host := strings.Replace(rule.Host, ".", "_", -1) host := strings.Replace(host, ".", "_", -1)
config.Config = map[string]string{ config.Config = map[string]string{
"query": fmt.Sprintf(rpsQuery, host), "query": fmt.Sprintf(rpsQuery, host),
} }