Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl committed Oct 21, 2024
1 parent 6dfdaec commit 3831db9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 205 deletions.
4 changes: 3 additions & 1 deletion charts/keep/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ keywords:
dependencies:
- name: ingress-nginx
repository: https://kubernetes.github.io/ingress-nginx
version: 4.11.3
version: ~4.11.3
condition: ingress-nginx.enabled
tags:
- ingress
home: https://platform.keephq.dev/
sources:
- https://github.com/keephq/helm-charts
Expand Down
36 changes: 33 additions & 3 deletions charts/keep/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ Helper function to find an environment variable in the list
Helper function for websocket host (relative)
*/}}
{{- define "keep.websocketPrefix" -}}
{{- coalesce .Values.websocket.ingress.prefix .Values.global.ingress.websocketPrefix "/websocket" -}}
{{- coalesce .Values.global.ingress.websocketPrefix "/websocket" -}}
{{- end -}}

{{/*
Helper function for backend host (relative)
*/}}
{{- define "keep.backendPrefix" -}}
{{- coalesce .Values.backend.ingress.prefix .Values.global.ingress.backendPrefix "/api" -}}
{{- coalesce .Values.global.ingress.backendPrefix "/api" -}}
{{- end -}}

{{/*
Helper function for frontend host (relative)
*/}}
{{- define "keep.frontendPrefix" -}}
{{- coalesce .Values.frontend.ingress.prefix .Values.global.ingress.frontendPrefix "/" -}}
{{- coalesce .Values.global.ingress.frontendPrefix "/" -}}
{{- end -}}

{{/*
Expand All @@ -119,4 +119,34 @@ Helper function for API_URL for the frontend
{{- else -}}
{{- include "keep.backendPrefix" . -}}
{{- end -}}
{{- end -}}


{{/*
Determine if ingress-nginx should be installed
*/}}
{{- define "keep.shouldInstallIngressNginx" -}}
{{- if .Release.IsInstall -}}
{{- if .Values.preInstallJob.enabled -}}
{{- $jobName := printf "%s-nginx-ingress-check" .Release.Name -}}
{{- $job := (lookup "batch/v1" "Job" .Release.Namespace $jobName) -}}
{{- if $job -}}
{{- if $job.status -}}
{{- if eq (int $job.status.succeeded) 0 -}}
{{- printf "false" -}}
{{- else -}}
{{- printf "true" -}}
{{- end -}}
{{- else -}}
{{- printf "true" -}}
{{- end -}}
{{- else -}}
{{- printf "true" -}}
{{- end -}}
{{- else -}}
{{- printf "true" -}}
{{- end -}}
{{- else -}}
{{- printf "false" -}}
{{- end -}}
{{- end -}}
61 changes: 0 additions & 61 deletions charts/keep/templates/backend-ingress.yaml

This file was deleted.

101 changes: 55 additions & 46 deletions charts/keep/templates/nginx-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{{- if and (or .Values.frontend.enabled .Values.backend.enabled) .Values.frontend.ingress.enabled }}
{{- if .Values.global.ingress.enabled }}
{{- $fullName := include "keep.fullname" . }}
{{- $frontendPort := .Values.frontend.service.port }}
{{- $backendPort := .Values.backend.service.port }}
{{- $websocketPort := .Values.websocket.service.port }}

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
Expand All @@ -19,23 +15,36 @@ metadata:
nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
nginx.ingress.kubernetes.io/use-http2: "false"
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
nginx.ingress.kubernetes.io/server-snippets: |
location {{ include "keep.websocketPrefix" . }}/ {
proxy_pass http://{{ $fullName }}-websocket:{{ .Values.websocket.service.port }};
nginx.ingress.kubernetes.io/configuration-snippet: |
if ($request_uri ~* ^({{ .Values.global.ingress.websocketPrefix }}|{{ .Values.global.ingress.backendPrefix }}|{{ .Values.global.ingress.frontendPrefix }})(/|$)(.*)) {
rewrite ^({{ .Values.global.ingress.websocketPrefix }}|{{ .Values.global.ingress.backendPrefix }}|{{ .Values.global.ingress.frontendPrefix }})(/|$)(.*) /$3 break;
}
nginx.ingress.kubernetes.io/server-snippet: |
{{- if $.Values.websocket.enabled }}
location ^~ {{ .Values.global.ingress.websocketPrefix }} {
rewrite ^{{ .Values.global.ingress.websocketPrefix }}(/|$)(.*) /$2 break;
proxy_pass http://{{ $fullName }}-websocket:{{ $.Values.websocket.service.port }};
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_cache_bypass $http_upgrade;
}
{{- with .Values.frontend.ingress.annotations }}
{{- end }}
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/use-regex: "true"
{{- with .Values.global.ingress.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: nginx
{{- if .Values.frontend.ingress.tls }}
ingressClassName: {{ .Values.global.ingress.className }}
{{- if .Values.global.ingress.tls }}
tls:
{{- range .Values.frontend.ingress.tls }}
{{- range .Values.global.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
Expand All @@ -44,64 +53,64 @@ spec:
{{- end }}
{{- end }}
rules:
{{- if or .Values.frontend.ingress.hosts .Values.backend.ingress.hosts }}
{{- range $host := (concat .Values.frontend.ingress.hosts .Values.backend.ingress.hosts) }}
- host: {{ $host | quote }}
{{- if .Values.global.ingress.hosts }}
{{- range .Values.global.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- if and $.Values.websocket.enabled $websocketPort }}
- path: {{ include "keep.websocketPrefix" $ }}
pathType: Prefix
{{- if $.Values.websocket.enabled }}
- path: {{ $.Values.global.ingress.websocketPrefix }}(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}-websocket
port:
number: {{ $websocketPort }}
number: {{ $.Values.websocket.service.port }}
{{- end }}
- path: {{ include "keep.frontendPrefix" $ }}
pathType: Prefix
{{- if $.Values.backend.enabled }}
- path: {{ $.Values.global.ingress.backendPrefix }}(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}-frontend
name: {{ $fullName }}-backend
port:
number: {{ $frontendPort }}
{{- if and $.Values.backend $.Values.backend.enabled }}
- path: {{ include "keep.backendPrefix" $ }}
pathType: Prefix
number: {{ $.Values.backend.service.port }}
{{- end }}
- path: {{ $.Values.global.ingress.frontendPrefix }}(.*)
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}-backend
name: {{ $fullName }}-frontend
port:
number: {{ $backendPort }}
{{- end }}
number: {{ $.Values.frontend.service.port }}
{{- end }}
{{- else }}
- http:
paths:
{{- if and $.Values.websocket.enabled $websocketPort }}
- path: {{ include "keep.websocketPrefix" . }}
pathType: Prefix
{{- if $.Values.websocket.enabled }}
- path: {{ $.Values.global.ingress.websocketPrefix }}(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}-websocket
port:
number: {{ $websocketPort }}
number: {{ $.Values.websocket.service.port }}
{{- end }}
- path: {{ include "keep.frontendPrefix" . }}
pathType: Prefix
{{- if $.Values.backend.enabled }}
- path: {{ $.Values.global.ingress.backendPrefix }}(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}-frontend
name: {{ $fullName }}-backend
port:
number: {{ $frontendPort }}
{{- if and $.Values.backend $.Values.backend.enabled }}
- path: {{ include "keep.backendPrefix" . }}
pathType: Prefix
number: {{ $.Values.backend.service.port }}
{{- end }}
- path: {{ $.Values.global.ingress.frontendPrefix }}(.*)
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}-backend
name: {{ $fullName }}-frontend
port:
number: {{ $backendPort }}
{{- end }}
number: {{ $.Values.frontend.service.port }}
{{- end }}
{{- end }}
{{- end }}
64 changes: 0 additions & 64 deletions charts/keep/templates/websocket-ingress.yaml

This file was deleted.

Loading

0 comments on commit 3831db9

Please sign in to comment.