From 5e6d304ecddf2a41bfbd5431db5b3e7dd24952f2 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Larsen Date: Tue, 8 Oct 2019 16:55:49 +0200 Subject: [PATCH] Support networking.k8s.io/v1beta1 Ingresses Signed-off-by: Mikkel Oscar Lyderik Larsen --- pkg/collector/skipper_collector.go | 33 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pkg/collector/skipper_collector.go b/pkg/collector/skipper_collector.go index cf7482a..33e1876 100644 --- a/pkg/collector/skipper_collector.go +++ b/pkg/collector/skipper_collector.go @@ -125,21 +125,40 @@ func getWeights(ingressAnnotations map[string]string, backendAnnotations []strin // getCollector returns a collector for getting the metrics. func (c *SkipperCollector) getCollector() (Collector, error) { - ingress, err := c.client.ExtensionsV1beta1().Ingresses(c.objectReference.Namespace).Get(c.objectReference.Name, metav1.GetOptions{}) - if err != nil { - return nil, err + var annotations map[string]string + var hosts []string + + 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 { return nil, err } config := c.config var collector Collector - collectors := make([]Collector, 0, len(ingress.Spec.Rules)) - for _, rule := range ingress.Spec.Rules { - host := strings.Replace(rule.Host, ".", "_", -1) + collectors := make([]Collector, 0, len(hosts)) + for _, host := range hosts { + host := strings.Replace(host, ".", "_", -1) config.Config = map[string]string{ "query": fmt.Sprintf(rpsQuery, host), }