diff --git a/pkg/resourcecreator/ingress/ingress.go b/pkg/resourcecreator/ingress/ingress.go index 768cf297..1b7b56aa 100644 --- a/pkg/resourcecreator/ingress/ingress.go +++ b/pkg/resourcecreator/ingress/ingress.go @@ -100,8 +100,12 @@ func createIngressBase(source Source, ingressClass string) (*networkingv1.Ingres objectMeta := resource.CreateObjectMeta(source) objectMeta.Name = shortName - objectMeta.Annotations["prometheus.io/scrape"] = "true" - objectMeta.Annotations["prometheus.io/path"] = source.GetLiveness().Path + + liveness := source.GetLiveness() + if liveness != nil && liveness.Path != "" { + objectMeta.Annotations["prometheus.io/scrape"] = "true" + objectMeta.Annotations["prometheus.io/path"] = liveness.Path + } return &networkingv1.Ingress{ TypeMeta: metav1.TypeMeta{ diff --git a/pkg/resourcecreator/testdata/ingress_haproxy_migrate_empty_strings.yaml b/pkg/resourcecreator/testdata/ingress_haproxy_migrate_empty_strings.yaml index 0c1c3ff7..c004df44 100644 --- a/pkg/resourcecreator/testdata/ingress_haproxy_migrate_empty_strings.yaml +++ b/pkg/resourcecreator/testdata/ingress_haproxy_migrate_empty_strings.yaml @@ -39,5 +39,3 @@ tests: metadata: annotations: nais.io/deploymentCorrelationID: "" - prometheus.io/path: "" - prometheus.io/scrape: "true" diff --git a/pkg/resourcecreator/testdata/ingress_migrate_to_haproxy.yaml b/pkg/resourcecreator/testdata/ingress_migrate_to_haproxy.yaml index 4beb129c..519a51d4 100644 --- a/pkg/resourcecreator/testdata/ingress_migrate_to_haproxy.yaml +++ b/pkg/resourcecreator/testdata/ingress_migrate_to_haproxy.yaml @@ -44,8 +44,6 @@ tests: haproxy.org/timeout-client: "101s" haproxy.org/timeout-connect: "102s" haproxy.org/path-rewrite: "some" - prometheus.io/path: "" - prometheus.io/scrape: "true" spec: ingressClassName: very-haproxy rules: diff --git a/pkg/resourcecreator/testdata/ingress_on_premises.yaml b/pkg/resourcecreator/testdata/ingress_on_premises.yaml index 022e6e7c..68882301 100644 --- a/pkg/resourcecreator/testdata/ingress_on_premises.yaml +++ b/pkg/resourcecreator/testdata/ingress_on_premises.yaml @@ -35,8 +35,6 @@ tests: nais.io/deploymentCorrelationID: "" nginx.ingress.kubernetes.io/backend-protocol: HTTP nginx.ingress.kubernetes.io/use-regex: "true" - prometheus.io/path: "" - prometheus.io/scrape: "true" spec: ingressClassName: very-nginx rules: diff --git a/pkg/resourcecreator/testdata/ingress_probe.yaml b/pkg/resourcecreator/testdata/ingress_probe.yaml new file mode 100644 index 00000000..3bd29993 --- /dev/null +++ b/pkg/resourcecreator/testdata/ingress_probe.yaml @@ -0,0 +1,54 @@ +testconfig: + description: application with liveness path results in ingress resource with prometheus annotations +config: + features: + haproxy: true + domain-ingressclass-mapping: + - domainSuffix: .bar + ingressClass: very-haproxy +input: + kind: Application + apiVersion: nais.io/v1alpha1 + metadata: + name: myapplication + namespace: mynamespace + uid: "123456" + spec: + ingresses: + - https://foo.bar/baz + liveness: + path: "liveness" +tests: + - apiVersion: networking.k8s.io/v1 + kind: Ingress + name: myapplication-very-haproxy-efe42262 + operation: CreateOrUpdate + match: + - type: exact + name: "ingress created with correct config" + exclude: + - .status + - .metadata.creationTimestamp + - .metadata.ownerReferences + - .metadata.labels + - .metadata.name + - .metadata.namespace + resource: + metadata: + annotations: + nais.io/deploymentCorrelationID: "" + prometheus.io/path: "liveness" + prometheus.io/scrape: "true" + spec: + ingressClassName: very-haproxy + rules: + - host: foo.bar + http: + paths: + - backend: + service: + name: myapplication + port: + number: 80 + path: /baz + pathType: Prefix