From ea4a764143f43bb75e33096818d3e24b84def6fd Mon Sep 17 00:00:00 2001 From: Trevor Whitney Date: Thu, 24 Nov 2022 02:19:38 -0700 Subject: [PATCH] [helm] Fix incorrect ingress paths when using single binary deployment (#7530) **What this PR does / why we need it**: The helm ingress template was copied over from the simple scalable chart and does not work when deploying the chart in single binary configuration. This fixes that by adding a set of single binary routes, and conditionally configuring the ingress resource based on deployment type. **Which issue(s) this PR fixes**: Fixes #7080 **Special notes for your reviewer**: **Checklist** - [ ] Reviewed the `CONTRIBUTING.md` guide - [ ] Documentation added - [ ] Tests updated - [ ] `CHANGELOG.md` updated - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/upgrading/_index.md` --- docs/Makefile | 2 +- docs/sources/installation/helm/reference.md | 81 +++++++++++++++++++++ production/helm/loki/CHANGELOG.md | 1 + production/helm/loki/templates/_helpers.tpl | 69 ++++++++++++++++++ production/helm/loki/templates/ingress.yaml | 21 +----- production/helm/loki/values.yaml | 11 +++ 6 files changed, 164 insertions(+), 21 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index 9e82cd0ec6..73a3874224 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -19,7 +19,7 @@ docs-test: pull sources/installation/helm/reference.md: ../production/helm/loki/reference.md.gotmpl ifeq ($(BUILD_IN_CONTAINER),true) - docker run --rm --volume "$(realpath ..):/helm-docs:z" -u "$$(id -u)" "docker.io/jnorwood/helm-docs:v1.8.1" \ + docker run --rm --volume "$(realpath ..):/helm-docs:z" -u "$$(id -u)" "docker.io/jnorwood/helm-docs:v1.11.0" \ -c /helm-docs/production/helm/ \ -t reference.md.gotmpl \ -o reference.md diff --git a/docs/sources/installation/helm/reference.md b/docs/sources/installation/helm/reference.md index 1a1a123e5e..3fe6731d04 100644 --- a/docs/sources/installation/helm/reference.md +++ b/docs/sources/installation/helm/reference.md @@ -1083,6 +1083,87 @@ false
 "/prometheus/api/v1/alerts"
 
+ + + + ingress.paths.singleBinary[0] + string + +
+"/api/prom/push"
+
+ + + + ingress.paths.singleBinary[1] + string + +
+"/loki/api/v1/push"
+
+ + + + ingress.paths.singleBinary[2] + string + +
+"/api/prom/tail"
+
+ + + + ingress.paths.singleBinary[3] + string + +
+"/loki/api/v1/tail"
+
+ + + + ingress.paths.singleBinary[4] + string + +
+"/loki/api"
+
+ + + + ingress.paths.singleBinary[5] + string + +
+"/api/prom/rules"
+
+ + + + ingress.paths.singleBinary[6] + string + +
+"/loki/api/v1/rules"
+
+ + + + ingress.paths.singleBinary[7] + string + +
+"/prometheus/api/v1/rules"
+
+ + + + ingress.paths.singleBinary[8] + string + +
+"/prometheus/api/v1/alerts"
+
diff --git a/production/helm/loki/CHANGELOG.md b/production/helm/loki/CHANGELOG.md index 26dc21997a..11ffa80eb2 100644 --- a/production/helm/loki/CHANGELOG.md +++ b/production/helm/loki/CHANGELOG.md @@ -34,6 +34,7 @@ Entries should include a reference to the pull request that introduced the chang ## 3.3.1 - [BUGFIX] Fix invalid ruler config when filesystem storage is being used +- [BUGFIX] Fix ingress template to work with both deployment types (scalable and single binary) ## 3.3.0 diff --git a/production/helm/loki/templates/_helpers.tpl b/production/helm/loki/templates/_helpers.tpl index 99b0a54112..7f268081ae 100644 --- a/production/helm/loki/templates/_helpers.tpl +++ b/production/helm/loki/templates/_helpers.tpl @@ -326,6 +326,75 @@ Return if ingress supports pathType. {{- or (eq (include "loki.ingress.isStable" .) "true") (and (eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}} {{- end -}} +{{/* +Generate list of ingress service paths based on deployment type +*/}} +{{- define "loki.ingress.servicePaths" -}} +{{- if (eq (include "loki.deployment.isScalable" .) "true") -}} +{{- include "loki.ingress.scalableServicePaths" . }} +{{- else -}} +{{- include "loki.ingress.singleBinaryServicePaths" . }} +{{- end -}} +{{- end -}} + +{{/* +Ingress service paths for scalable deployment +*/}} +{{- define "loki.ingress.scalableServicePaths" -}} +{{- include "loki.ingress.servicePath" (dict "ctx" . "svcName" "read" "paths" .Values.ingress.paths.read )}} +{{- include "loki.ingress.servicePath" (dict "ctx" . "svcName" "write" "paths" .Values.ingress.paths.write )}} +{{- end -}} + +{{/* +Ingress service paths for single binary deployment +*/}} +{{- define "loki.ingress.singleBinaryServicePaths" -}} +{{- include "loki.ingress.servicePath" (dict "ctx" . "svcName" "singleBinary" "paths" .Values.ingress.paths.singleBinary )}} +{{- end -}} + +{{/* +Ingress service path helper function +Params: + ctx = . context + svcName = service name without the "loki.fullname" part (ie. read, write) + paths = list of url paths to allow ingress for +*/}} +{{- define "loki.ingress.servicePath" -}} +{{- $ingressApiIsStable := eq (include "loki.ingress.isStable" .ctx) "true" -}} +{{- $ingressSupportsPathType := eq (include "loki.ingress.supportsPathType" .ctx) "true" -}} +{{- range .paths }} +- path: {{ . }} + {{- if $ingressSupportsPathType }} + pathType: Prefix + {{- end }} + backend: + {{- if $ingressApiIsStable }} + {{- $serviceName := include "loki.ingress.serviceName" (dict "ctx" $.ctx "svcName" $.svcName) }} + service: + name: {{ $serviceName }} + port: + number: 3100 + {{- else }} + serviceName: {{ $serviceName }} + servicePort: 3100 +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Ingress service name helper function +Params: + ctx = . context + svcName = service name without the "loki.fullname" part (ie. read, write) +*/}} +{{- define "loki.ingress.serviceName" -}} +{{- if (eq .svcName "singleBinary") }} +{{- printf "%s" (include "loki.fullname" .ctx) }} +{{- else }} +{{- printf "%s-%s" (include "loki.fullname" .ctx) .svcName }} +{{- end -}} +{{- end -}} + {{/* Create the service endpoint including port for MinIO. */}} diff --git a/production/helm/loki/templates/ingress.yaml b/production/helm/loki/templates/ingress.yaml index 4a2fddddd8..49e391191f 100644 --- a/production/helm/loki/templates/ingress.yaml +++ b/production/helm/loki/templates/ingress.yaml @@ -1,7 +1,5 @@ {{- if .Values.ingress.enabled }} -{{- $ingressApiIsStable := eq (include "loki.ingress.isStable" .) "true" -}} {{- $ingressSupportsIngressClassName := eq (include "loki.ingress.supportsIngressClassName" .) "true" -}} -{{- $ingressSupportsPathType := eq (include "loki.ingress.supportsPathType" .) "true" -}} apiVersion: {{ include "loki.ingress.apiVersion" . }} kind: Ingress metadata: @@ -33,23 +31,6 @@ spec: - host: {{ . | quote }} http: paths: - {{- range $svcName, $paths := $.Values.ingress.paths }} - {{- range $paths }} - - path: {{ . }} - {{- if $ingressSupportsPathType }} - pathType: Prefix - {{- end }} - backend: - {{- if $ingressApiIsStable }} - service: - name: {{ include "loki.fullname" $ }}-{{ $svcName }} - port: - number: 3100 - {{- else }} - serviceName: {{ include "loki.fullname" $ }}-{{ $svcName }} - servicePort: 3100 - {{- end }} - {{- end }} - {{- end }} + {{- include "loki.ingress.servicePaths" $ | indent 10}} {{- end }} {{- end }} diff --git a/production/helm/loki/values.yaml b/production/helm/loki/values.yaml index 45e01be603..e0336eec53 100644 --- a/production/helm/loki/values.yaml +++ b/production/helm/loki/values.yaml @@ -948,6 +948,17 @@ ingress: - /loki/api/v1/rules - /prometheus/api/v1/rules - /prometheus/api/v1/alerts + singleBinary: + - /api/prom/push + - /loki/api/v1/push + - /api/prom/tail + - /loki/api/v1/tail + - /loki/api + - /api/prom/rules + - /loki/api/v1/rules + - /prometheus/api/v1/rules + - /prometheus/api/v1/alerts + hosts: - loki.example.com # tls: