diff --git a/discovery/kubernetes/ingress.go b/discovery/kubernetes/ingress.go index c649df149f..042fa88705 100644 --- a/discovery/kubernetes/ingress.go +++ b/discovery/kubernetes/ingress.go @@ -147,6 +147,7 @@ const ( ingressSchemeLabel = metaLabelPrefix + "ingress_scheme" ingressHostLabel = metaLabelPrefix + "ingress_host" ingressPathLabel = metaLabelPrefix + "ingress_path" + ingressClassNameLabel = metaLabelPrefix + "ingress_class_name" ) func ingressLabels(ingress *v1beta1.Ingress) model.LabelSet { @@ -154,6 +155,9 @@ func ingressLabels(ingress *v1beta1.Ingress) model.LabelSet { ls := make(model.LabelSet, 2*(len(ingress.Labels)+len(ingress.Annotations))+2) ls[ingressNameLabel] = lv(ingress.Name) ls[namespaceLabel] = lv(ingress.Namespace) + if ingress.Spec.IngressClassName != nil { + ls[ingressClassNameLabel] = lv(*ingress.Spec.IngressClassName) + } for k, v := range ingress.Labels { ln := strutil.SanitizeLabelName(k) diff --git a/discovery/kubernetes/ingress_test.go b/discovery/kubernetes/ingress_test.go index 27c0cf92b8..5ae5d4980c 100644 --- a/discovery/kubernetes/ingress_test.go +++ b/discovery/kubernetes/ingress_test.go @@ -42,7 +42,8 @@ func makeIngress(tls TLSMode) *v1beta1.Ingress { Annotations: map[string]string{"test/annotation": "testannotationvalue"}, }, Spec: v1beta1.IngressSpec{ - TLS: nil, + IngressClassName: classString("testclass"), + TLS: nil, Rules: []v1beta1.IngressRule{ { Host: "example.com", @@ -84,6 +85,10 @@ func makeIngress(tls TLSMode) *v1beta1.Ingress { return ret } +func classString(v string) *string { + return &v +} + func expectedTargetGroups(ns string, tls TLSMode) map[string]*targetgroup.Group { scheme1 := "http" scheme2 := "http" @@ -126,6 +131,7 @@ func expectedTargetGroups(ns string, tls TLSMode) map[string]*targetgroup.Group "__meta_kubernetes_ingress_labelpresent_test_label": "true", "__meta_kubernetes_ingress_annotation_test_annotation": "testannotationvalue", "__meta_kubernetes_ingress_annotationpresent_test_annotation": "true", + "__meta_kubernetes_ingress_class_name": "testclass", }, Source: key, }, diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index ea7b3c01d1..902f08df9c 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -1457,6 +1457,7 @@ Available meta labels: * `__meta_kubernetes_ingress_labelpresent_`: `true` for each label from the ingress object. * `__meta_kubernetes_ingress_annotation_`: Each annotation from the ingress object. * `__meta_kubernetes_ingress_annotationpresent_`: `true` for each annotation from the ingress object. +* `__meta_kubernetes_ingress_class_name`: Class name from ingress spec, if present. * `__meta_kubernetes_ingress_scheme`: Protocol scheme of ingress, `https` if TLS config is set. Defaults to `http`. * `__meta_kubernetes_ingress_path`: Path from ingress spec. Defaults to `/`.