Merge pull request #8916 from Evesy/main

Add class label to kubernetes ingress discovery
This commit is contained in:
Frederic Branczyk 2021-06-14 13:40:08 +02:00 committed by GitHub
commit 039b651450
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -147,6 +147,7 @@ const (
ingressSchemeLabel = metaLabelPrefix + "ingress_scheme" ingressSchemeLabel = metaLabelPrefix + "ingress_scheme"
ingressHostLabel = metaLabelPrefix + "ingress_host" ingressHostLabel = metaLabelPrefix + "ingress_host"
ingressPathLabel = metaLabelPrefix + "ingress_path" ingressPathLabel = metaLabelPrefix + "ingress_path"
ingressClassNameLabel = metaLabelPrefix + "ingress_class_name"
) )
func ingressLabels(ingress *v1beta1.Ingress) model.LabelSet { 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 := make(model.LabelSet, 2*(len(ingress.Labels)+len(ingress.Annotations))+2)
ls[ingressNameLabel] = lv(ingress.Name) ls[ingressNameLabel] = lv(ingress.Name)
ls[namespaceLabel] = lv(ingress.Namespace) ls[namespaceLabel] = lv(ingress.Namespace)
if ingress.Spec.IngressClassName != nil {
ls[ingressClassNameLabel] = lv(*ingress.Spec.IngressClassName)
}
for k, v := range ingress.Labels { for k, v := range ingress.Labels {
ln := strutil.SanitizeLabelName(k) ln := strutil.SanitizeLabelName(k)

View file

@ -42,7 +42,8 @@ func makeIngress(tls TLSMode) *v1beta1.Ingress {
Annotations: map[string]string{"test/annotation": "testannotationvalue"}, Annotations: map[string]string{"test/annotation": "testannotationvalue"},
}, },
Spec: v1beta1.IngressSpec{ Spec: v1beta1.IngressSpec{
TLS: nil, IngressClassName: classString("testclass"),
TLS: nil,
Rules: []v1beta1.IngressRule{ Rules: []v1beta1.IngressRule{
{ {
Host: "example.com", Host: "example.com",
@ -84,6 +85,10 @@ func makeIngress(tls TLSMode) *v1beta1.Ingress {
return ret return ret
} }
func classString(v string) *string {
return &v
}
func expectedTargetGroups(ns string, tls TLSMode) map[string]*targetgroup.Group { func expectedTargetGroups(ns string, tls TLSMode) map[string]*targetgroup.Group {
scheme1 := "http" scheme1 := "http"
scheme2 := "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_labelpresent_test_label": "true",
"__meta_kubernetes_ingress_annotation_test_annotation": "testannotationvalue", "__meta_kubernetes_ingress_annotation_test_annotation": "testannotationvalue",
"__meta_kubernetes_ingress_annotationpresent_test_annotation": "true", "__meta_kubernetes_ingress_annotationpresent_test_annotation": "true",
"__meta_kubernetes_ingress_class_name": "testclass",
}, },
Source: key, Source: key,
}, },

View file

@ -1457,6 +1457,7 @@ Available meta labels:
* `__meta_kubernetes_ingress_labelpresent_<labelname>`: `true` for each label from the ingress object. * `__meta_kubernetes_ingress_labelpresent_<labelname>`: `true` for each label from the ingress object.
* `__meta_kubernetes_ingress_annotation_<annotationname>`: Each annotation from the ingress object. * `__meta_kubernetes_ingress_annotation_<annotationname>`: Each annotation from the ingress object.
* `__meta_kubernetes_ingress_annotationpresent_<annotationname>`: `true` for each annotation from the ingress object. * `__meta_kubernetes_ingress_annotationpresent_<annotationname>`: `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 * `__meta_kubernetes_ingress_scheme`: Protocol scheme of ingress, `https` if TLS
config is set. Defaults to `http`. config is set. Defaults to `http`.
* `__meta_kubernetes_ingress_path`: Path from ingress spec. Defaults to `/`. * `__meta_kubernetes_ingress_path`: Path from ingress spec. Defaults to `/`.