Skip to content
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

[bitnami/nginx] stream server blocks #29491

Merged
merged 10 commits into from
Sep 20, 2024
4 changes: 3 additions & 1 deletion bitnami/nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cloneStaticSiteFromGit.branch=master

This helm chart supports using custom custom server block for NGINX to use.

You can use the `serverBlock` value to provide a custom server block for NGINX to use. To do this, create a values files with your server block and install the chart using it:
You can use the `serverBlock` or `streamServerBlock` value to provide a custom server block for NGINX to use. To do this, create a values files with your server block and install the chart using it:

```yaml
serverBlock: |-
Expand Down Expand Up @@ -296,7 +296,9 @@ For annotations, please see [this document](https://github.com/kubernetes/ingres
| `cloneStaticSiteFromGit.extraEnvVarsSecret` | Secret with extra environment variables | `""` |
| `cloneStaticSiteFromGit.extraVolumeMounts` | Add extra volume mounts for the Git containers | `[]` |
| `serverBlock` | Custom server block to be added to NGINX configuration | `""` |
| `streamServerBlock` | Custom stream server block to be added to NGINX configuration | `""` |
| `existingServerBlockConfigmap` | ConfigMap with custom server block to be added to NGINX configuration | `""` |
| `existingStreamServerBlockConfigmap` | ConfigMap with custom stream server block to be added to NGINX configuration | `""` |
| `staticSiteConfigmap` | Name of existing ConfigMap with the server static site content | `""` |
| `staticSitePVC` | Name of existing PVC with the server static site content | `""` |

Expand Down
11 changes: 11 additions & 0 deletions bitnami/nginx/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ Return the custom NGINX server block configmap.
{{- end -}}
{{- end -}}

{{/*
Return the custom NGINX stream server block configmap.
*/}}
{{- define "nginx.streamServerBlockConfigmapName" -}}
{{- if .Values.existingStreamServerBlockConfigmap -}}
{{- printf "%s" (tpl .Values.existingStreamServerBlockConfigmap $) -}}
{{- else -}}
{{- printf "%s-stream-server-block" (include "common.names.fullname" .) -}}
{{- end -}}
{{- end -}}

{{/*
Compile all warnings into a single message, and call fail.
*/}}
Expand Down
16 changes: 16 additions & 0 deletions bitnami/nginx/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ spec:
{{- if and .Values.serverBlock (not .Values.existingServerBlockConfigmap) }}
checksum/server-block-configuration: {{ include (print $.Template.BasePath "/server-block-configmap.yaml") . | sha256sum }}
{{- end }}
{{- if and .Values.streamServerBlock (not .Values.existingServerBlockConfigmap) }}
checksum/stream-server-block-configuration: {{ include (print $.Template.BasePath "/stream-server-block-configmap.yaml") . | sha256sum }}
{{- end }}
spec:
{{- include "nginx.imagePullSecrets" . | nindent 6 }}
shareProcessNamespace: {{ .Values.sidecarSingleProcessNamespace }}
Expand Down Expand Up @@ -245,6 +248,10 @@ spec:
{{- if .Values.extraEnvVars }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraEnvVars "context" $) | nindent 12 }}
{{- end }}
{{- if or .Values.streamServerBlock .Values.existingStreamServerBlockConfigmap }}
- name: NGINX_ENABLE_STREAM
value: "true"
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{- if .Values.extraEnvVars }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraEnvVars "context" $) | nindent 12 }}
{{- end }}
{{- if or .Values.streamServerBlock .Values.existingStreamServerBlockConfigmap }}
- name: NGINX_ENABLE_STREAM
value: "true"
{{- end }}
{{- if or .Values.streamServerBlock .Values.existingStreamServerBlockConfigmap }}
- name: NGINX_ENABLE_STREAM
value: "true"
{{- end }}
{{- if .Values.extraEnvVars }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraEnvVars "context" $) | nindent 12 }}
{{- end }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I changed it

envFrom:
{{- if .Values.extraEnvVarsCM }}
- configMapRef:
Expand Down Expand Up @@ -312,6 +319,10 @@ spec:
- name: nginx-server-block
mountPath: /opt/bitnami/nginx/conf/server_blocks
{{- end }}
{{- if or .Values.streamServerBlock .Values.existingStreamServerBlockConfigmap }}
- name: nginx-stream-server-block
mountPath: /opt/bitnami/nginx/conf/stream_server_blocks
{{- end }}
{{- if (include "nginx.useStaticSite" .) }}
- name: staticsite
mountPath: /app
Expand Down Expand Up @@ -390,6 +401,11 @@ spec:
configMap:
name: {{ include "nginx.serverBlockConfigmapName" . }}
{{- end }}
{{- if or .Values.streamServerBlock .Values.existingStreamServerBlockConfigmap }}
- name: nginx-stream-server-block
configMap:
name: {{ include "nginx.streamServerBlockConfigmapName" . }}
{{- end }}
{{- if (include "nginx.useStaticSite" .) }}
- name: staticsite
{{- include "nginx.staticSiteVolume" . | nindent 10 }}
Expand Down
19 changes: 19 additions & 0 deletions bitnami/nginx/templates/stream-server-block-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.streamServerBlock (not .Values.existingStreamServerBlockConfigmap) }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "common.names.fullname" . }}-stream-server-block
namespace: {{ include "common.names.namespace" . | quote }}
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
data:
stream-server-block.conf: |-
{{- include "common.tplvalues.render" ( dict "value" .Values.streamServerBlock "context" $ ) | nindent 4 }}
{{- end }}
6 changes: 6 additions & 0 deletions bitnami/nginx/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
"title": "Custom server block",
"description": "Custom server block to be added to NGINX configuration"
},
"streamServerBlock": {
"type": "string",
"form": true,
"title": "Custom stream server block",
"description": "Custom stream server block to be added to NGINX configuration"
},
"containerSecurityContext": {
"type": "object",
"form": true,
Expand Down
12 changes: 12 additions & 0 deletions bitnami/nginx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,22 @@ cloneStaticSiteFromGit:
## }
##
serverBlock: ""
## @param streamServerBlock Custom stream server block to be added to NGINX configuration
## streamServerBlock: |-
## server {
## listen 0.0.0.0:8080 udp;
## proxy_pass localhost:9000;
## }
##
streamServerBlock: ""
## @param existingServerBlockConfigmap ConfigMap with custom server block to be added to NGINX configuration
## NOTE: This will override serverBlock
##
existingServerBlockConfigmap: ""
## @param existingStreamServerBlockConfigmap ConfigMap with custom stream server block to be added to NGINX configuration
## NOTE: This will override streamServerBlock
##
existingStreamServerBlockConfigmap: ""
## @param staticSiteConfigmap Name of existing ConfigMap with the server static site content
##
staticSiteConfigmap: ""
Expand Down
Loading