Skip to content

feat: add basic auth gateway to helm chart #4318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions operations/pyroscope/helm/pyroscope/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,78 @@ behavior:
scaleDown: {}
scaleUp: {}
{{- end }}


{{/* Allow KubeVersion to be overridden. */}}
{{- define "pyroscope.kubeVersion" -}}
{{- default .Capabilities.KubeVersion.Version .Values.kubeVersionOverride -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for ingress.
*/}}
{{- define "pyroscope.ingress.apiVersion" -}}
{{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" (include "pyroscope.kubeVersion" .)) -}}
{{- print "networking.k8s.io/v1" -}}
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
{{- print "networking.k8s.io/v1beta1" -}}
{{- else -}}
{{- print "extensions/v1beta1" -}}
{{- end -}}
{{- end -}}

{/*
Return if ingress is stable.
*/}}
{{- define "pyroscope.ingress.isStable" -}}
{{- eq (include "pyroscope.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
{{- end -}}

{{/*
Return if ingress supports ingressClassName.
*/}}
{{- define "pyroscope.ingress.supportsIngressClassName" -}}
{{- or (eq (include "pyroscope.ingress.isStable" .) "true") (and (eq (include "pyroscope.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" (include "pyroscope.kubeVersion" .))) -}}
{{- end -}}

{{/*
Return if ingress supports pathType.
*/}}
{{- define "pyroscope.ingress.supportsPathType" -}}
{{- or (eq (include "pyroscope.ingress.isStable" .) "true") (and (eq (include "pyroscope.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" (include "pyroscope.kubeVersion" .))) -}}
{{- end -}}

{{/*
compute a ConfigMap or Secret checksum only based on its .data content.
This function needs to be called with a context object containing the following keys:
- ctx: the current Helm context (what '.' is at the call site)
- name: the file name of the ConfigMap or Secret
*/}}
{{- define "pyroscope.configMapOrSecretContentHash" -}}
{{ get (include (print .ctx.Template.BasePath .name) .ctx | fromYaml) "data" | toYaml | sha256sum }}
{{- end }}

{{/* Configure enableServiceLinks in pod */}}
{{- define "pyroscope.enableServiceLinks" -}}
{{- if semverCompare ">=1.13-0" (include "pyroscope.kubeVersion" .) -}}
{{- if or (.Values.pyroscope.enableServiceLinks) (ne .Values.pyroscope.enableServiceLinks false) -}}
enableServiceLinks: true
{{- else -}}
enableServiceLinks: false
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Base template for building docker image reference
*/}}
{{- define "pyroscope.baseImage" }}
{{- $registry := .service.registry | default "" -}}
{{- $repository := .service.repository | default "" -}}
{{- $ref := ternary (printf ":%s" (.service.tag | default .defaultVersion | toString)) (printf "@%s" .service.digest) (empty .service.digest) -}}
{{- if and $registry $repository -}}
{{- printf "%s/%s%s" $registry $repository $ref -}}
{{- else -}}
{{- printf "%s%s%s" $registry $repository $ref -}}
{{- end -}}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{/*
gateway fullname
*/}}
{{- define "pyroscope.gatewayFullname" -}}
{{ include "pyroscope.fullname" . }}-gateway
{{- end }}

{{/*
gateway common labels
*/}}
{{- define "pyroscope.gatewayLabels" -}}
{{ include "pyroscope.labels" . }}
app.kubernetes.io/component: pyroscope-gateway
{{- end }}

{{/*
gateway selector labels
*/}}
{{- define "pyroscope.gatewaySelectorLabels" -}}
{{ include "pyroscope.selectorLabels" . }}
app.kubernetes.io/component: pyroscope-gateway
{{- end }}

{{/*
gateway auth secret name
*/}}
{{- define "pyroscope.gatewayAuthSecret" -}}
{{ .Values.gateway.basicAuth.existingSecret | default (include "pyroscope.gatewayFullname" . ) }}
{{- end }}

{{/*
gateway Docker image
*/}}
{{- define "pyroscope.gatewayImage" -}}
{{- $dict := dict "service" .Values.gateway.image -}}
{{- include "pyroscope.baseImage" $dict -}}
{{- end }}

{{/*
gateway priority class name
*/}}
{{- define "pyroscope.gatewayPriorityClassName" -}}
{{- $pcn := .Values.gateway.priorityClassName -}}
{{- if $pcn }}
priorityClassName: {{ $pcn }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.gateway.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "pyroscope.gatewayFullname" . }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "pyroscope.gatewayLabels" . | nindent 4 }}
data:
nginx.conf: |
{{- tpl .Values.gateway.nginxConfig.file . | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{{- if .Values.gateway.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "pyroscope.gatewayFullname" . }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "pyroscope.gatewayLabels" . | nindent 4 }}
{{- if or (not (empty .Values.pyroscope.annotations)) (not (empty .Values.gateway.annotations))}}
annotations:
{{- with .Values.pyroscope.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.gateway.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
spec:
{{- if not .Values.gateway.autoscaling.enabled }}
replicas: {{ .Values.gateway.replicas }}
{{- end }}
{{- with .Values.gateway.deploymentStrategy }}
strategy:
{{ toYaml . | trim | indent 4 }}
{{- end }}
revisionHistoryLimit: {{ .Values.pyroscope.revisionHistoryLimit }}
selector:
matchLabels:
{{- include "pyroscope.gatewaySelectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ include "pyroscope.configMapOrSecretContentHash" (dict "ctx" . "name" "/gateway/configmap-gateway.yaml") }}
{{- with .Values.gateway.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- with .Values.pyroscope.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.gateway.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "pyroscope.gatewaySelectorLabels" . | nindent 8 }}
spec:
serviceAccountName: {{ include "pyroscope.serviceAccountName" . }}
{{ include "pyroscope.enableServiceLinks" . }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end -}}
{{- include "pyroscope.gatewayPriorityClassName" . | nindent 6 }}
securityContext:
{{- toYaml .Values.gateway.podSecurityContext | nindent 8 }}
terminationGracePeriodSeconds: {{ .Values.gateway.terminationGracePeriodSeconds }}
containers:
- name: nginx
image: {{ include "pyroscope.gatewayImage" . }}
imagePullPolicy: {{ .Values.gateway.image.pullPolicy }}
ports:
- name: http-metrics
containerPort: {{ .Values.gateway.containerPort }}
protocol: TCP
{{- with .Values.gateway.extraEnv }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.gateway.extraEnvFrom }}
envFrom:
{{- toYaml . | nindent 12 }}
{{- end }}
readinessProbe:
{{- toYaml .Values.gateway.readinessProbe | nindent 12 }}
securityContext:
{{- toYaml .Values.gateway.containerSecurityContext | nindent 12 }}
{{- with .Values.gateway.lifecycle }}
lifecycle:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: config
mountPath: /etc/nginx
{{- if .Values.gateway.basicAuth.enabled }}
- name: auth
mountPath: /etc/nginx/secrets
{{- end }}
- name: tmp
mountPath: /tmp
- name: docker-entrypoint-d-override
mountPath: /docker-entrypoint.d
{{- if .Values.gateway.extraVolumeMounts }}
{{- toYaml .Values.gateway.extraVolumeMounts | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.gateway.resources | nindent 12 }}
{{- if .Values.gateway.extraContainers }}
{{- toYaml .Values.gateway.extraContainers | nindent 8}}
{{- end }}
{{- with .Values.gateway.affinity }}
affinity:
{{- tpl . $ | nindent 8 }}
{{- end }}
{{- with .Values.gateway.dnsConfig }}
dnsConfig:
{{- tpl . $ | nindent 8 }}
{{- end }}
{{- with .Values.gateway.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.gateway.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.gateway.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: config
configMap:
name: {{ include "pyroscope.gatewayFullname" . }}
{{- if .Values.gateway.basicAuth.enabled }}
- name: auth
secret:
secretName: {{ include "pyroscope.gatewayAuthSecret" . }}
{{- end }}
- name: tmp
emptyDir: {}
- name: docker-entrypoint-d-override
emptyDir: {}
{{- if .Values.gateway.extraVolumes }}
{{- toYaml .Values.gateway.extraVolumes | nindent 8 }}
{{- end }}
{{- end }}
50 changes: 50 additions & 0 deletions operations/pyroscope/helm/pyroscope/templates/gateway/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- $autoscalingv2 := .Capabilities.APIVersions.Has "autoscaling/v2" -}}
{{- if .Values.gateway.autoscaling.enabled }}
{{- if $autoscalingv2 }}
apiVersion: autoscaling/v2
{{- else }}
apiVersion: autoscaling/v2beta1
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "pyroscope.gatewayFullname" . }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "pyroscope.gatewayLabels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "pyroscope.gatewayFullname" . }}
minReplicas: {{ .Values.gateway.autoscaling.minReplicas }}
maxReplicas: {{ .Values.gateway.autoscaling.maxReplicas }}
{{- with .Values.gateway.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
metrics:
{{- with .Values.gateway.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
{{- if $autoscalingv2 }}
target:
type: Utilization
averageUtilization: {{ . }}
{{- else }}
targetAverageUtilization: {{ . }}
{{- end }}
{{- end }}
{{- with .Values.gateway.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
{{- if $autoscalingv2 }}
target:
type: Utilization
averageUtilization: {{ . }}
{{- else }}
targetAverageUtilization: {{ . }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{{- if and .Values.gateway.enabled -}}
{{- if .Values.gateway.ingress.enabled -}}
{{- $ingressApiIsStable := eq (include "pyroscope.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "pyroscope.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "pyroscope.ingress.supportsPathType" .) "true" -}}
apiVersion: {{ include "pyroscope.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: {{ include "pyroscope.gatewayFullname" . }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "pyroscope.gatewayLabels" . | nindent 4 }}
{{- range $labelKey, $labelValue := .Values.gateway.ingress.labels }}
{{ $labelKey }}: {{ $labelValue | toYaml }}
{{- end }}
{{- with .Values.gateway.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and $ingressSupportsIngressClassName .Values.gateway.ingress.ingressClassName }}
ingressClassName: {{ .Values.gateway.ingress.ingressClassName }}
{{- end -}}
{{- if .Values.gateway.ingress.tls }}
tls:
{{- range .Values.gateway.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ tpl . $ | quote }}
{{- end }}
{{- with .secretName }}
secretName: {{ . }}
{{- end }}
{{- end }}
{{- end }}
rules:
{{- range .Values.gateway.ingress.hosts }}
- host: {{ tpl .host $ | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if $ingressSupportsPathType }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if $ingressApiIsStable }}
service:
name: {{ include "pyroscope.gatewayFullname" $ }}
port:
number: {{ $.Values.gateway.service.port }}
{{- else }}
serviceName: {{ include "pyroscope.gatewayFullname" $ }}
servicePort: {{ $.Values.gateway.service.port }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Loading
Loading