diff --git a/nginx-redirect/nginx-templates/default.conf.template b/nginx-redirect/nginx-templates/default.conf.template deleted file mode 100644 index 3188d06..0000000 --- a/nginx-redirect/nginx-templates/default.conf.template +++ /dev/null @@ -1,38 +0,0 @@ -map $host$request_uri $redir_to { - default "not-found"; -{{- range $src, $dst := .Values.redirects }} -{{- if hasPrefix "^" $src }} - {{ printf "~%s" $src }} {{ quote $dst }}; -{{- end }} -{{- end }} -} - -map $host $redir_host_to { - default "not-found"; -{{- range $src, $dst := .Values.redirects }} -{{- if not (hasPrefix "^" $src) }} - {{ quote $src }} {{ quote $dst }}; -{{- end }} -{{- end }} -} - -server { - listen 80; - server_name localhost default_server; - - {{- range .Values.proxy_real_ip_from }} - set_real_ip_from {{ quote . }}; - {{- end }} - - location / { - if ($redir_to != "not-found") { - return 301 $redir_to; - } - - if ($redir_host_to != "not-found") { - return 301 $redir_host_to; - } - - return 404; - } -} diff --git a/nginx-redirect/templates/configmap.yaml b/nginx-redirect/templates/configmap.yaml index 008aa45..5746b3b 100644 --- a/nginx-redirect/templates/configmap.yaml +++ b/nginx-redirect/templates/configmap.yaml @@ -1,10 +1,103 @@ -{{- $files := .Files.Glob "nginx-templates/*" }} --- apiVersion: v1 kind: ConfigMap metadata: - name: {{ include "common.names.fullname" . }}-templates + name: {{ include "common.names.fullname" . }}-config data: -{{- range $filename, $content := $files }} - {{ base $filename }}: | {{- tpl ($content | toString) $ | nindent 4 }} -{{- end }} + nginx.conf: | + {{- if .Values.otel.enabled }} + load_module modules/ngx_otel_module.so; + {{- end }} + + user nginx; + worker_processes auto; + + error_log /var/log/nginx/error.log notice; + pid /var/run/nginx.pid; + + events { + worker_connections 1024; + } + + http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + {{- with .Values.otel }} + {{- if .enabled }} + otel_exporter { + endpoint {{ or .endpoint (fail "otel.endpoint required") }}; + interval {{ .interval }}; + batch_size {{ .batchSize }}; + batch_count {{ .batchCount }}; + } + + otel_trace on; + otel_trace_context {{ .context }}; + otel_service_name {{ .serviceName | default $.Release.Name | quote }}; + + {{- with .spanName }} + otel_span_name {{ quote . }}; + {{- end }} + {{- range $name, $value := .spanAttributes }} + otel_span_attr {{ quote $name }} {{ quote $value }}; + {{- end }} + + {{- end }} + {{- end }} + + map $host$request_uri $redir_to { + default "not-found"; + {{- range $src, $dst := .Values.redirects }} + {{- if hasPrefix "^" $src }} + {{ printf "~%s" $src }} {{ quote $dst }}; + {{- end }} + {{- end }} + } + + map $host $redir_host_to { + default "not-found"; + {{- range $src, $dst := .Values.redirects }} + {{- if not (hasPrefix "^" $src) }} + {{ quote $src }} {{ quote $dst }}; + {{- end }} + {{- end }} + } + + server { + listen 80; + + {{- range .Values.proxy_real_ip_from }} + set_real_ip_from {{ quote . }}; + {{- end }} + + location / { + resolver {{ .Values.resolver }} valid=30s; + + if ($redir_to != "not-found") { + return 301 $redir_to; + } + + if ($redir_host_to != "not-found") { + return 301 $redir_host_to; + } + + return 404; + } + } + + include /etc/nginx/conf.d/*.conf; + } diff --git a/nginx-redirect/templates/deployment.yaml b/nginx-redirect/templates/deployment.yaml index 792aa03..3ccbd4a 100644 --- a/nginx-redirect/templates/deployment.yaml +++ b/nginx-redirect/templates/deployment.yaml @@ -1,4 +1,7 @@ {{- $defaultImageTag := printf "%s-alpine" .Chart.AppVersion }} +{{- if .Values.otel.enabled }} +{{- $defaultImageTag = printf "%s-otel" $defaultImageTag }} +{{- end }} --- apiVersion: apps/v1 kind: Deployment @@ -11,7 +14,7 @@ spec: template: metadata: annotations: - checksum/templates: {{ include "common.utils.checksumTemplate" (dict "path" "/configmap.yaml" "context" $) | quote }} + checksum/config: {{ include "common.utils.checksumTemplate" (dict "path" "/configmap.yaml" "context" $) | quote }} {{- with .Values.deployment.annotations }} {{- toYaml . | nindent 8 }} {{- end }} @@ -40,15 +43,16 @@ spec: securityContext: {{- toYaml . | nindent 12 }} {{- end }} volumeMounts: - - name: nginx-templates - mountPath: /etc/nginx/templates + - name: nginx-config + mountPath: /etc/nginx/nginx.conf + subPath: nginx.conf {{- with .Values.deployment.volumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} volumes: - - name: nginx-templates + - name: nginx-config configMap: - name: {{ include "common.names.fullname" . }}-templates + name: {{ include "common.names.fullname" . }}-config {{- with .Values.deployment.volumes }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/nginx-redirect/values.yaml b/nginx-redirect/values.yaml index fd79b36..49fc0a0 100644 --- a/nginx-redirect/values.yaml +++ b/nginx-redirect/values.yaml @@ -1,3 +1,4 @@ +--- redirects: {} # redirect.host: https://redirect/url # ^redirect.host/path$: https://redirect/url @@ -5,6 +6,34 @@ redirects: {} proxy_real_ip_from: [] # - 192.168.0.0/16 +resolver: kube-dns.kube-system.svc.cluster.local + +otel: + enabled: false + # -- the address of OTLP/gRPC endpoint that will accept telemetry data. + endpoint: "" + # -- the maximum interval between two exports. + interval: 5s + # -- the maximum number of spans to be sent in one batch per worker. + batchSize: 512 + # -- the number of pending batches per worker, spans exceeding the limit are dropped. + batchCount: 4 + # -- sets the "service.name" attribute of the OTel resource. + # @default -- .Release.Name + serviceName: "" + # -- specifies how to propagate trace context. + # Options: + # - `extract` uses an existing trace context from the request, so that the identifiers of a trace and the parent span are inherited from the incoming request. + # - `inject` adds a new context to the request, overwriting existing headers, if any. + # - `propagate` updates the existing context (combines extract and i nject). + # - `ignore` skips context headers processing. + context: inject + # -- defines the name of the OTel span. + spanName: "" + # -- defines additional attributes on the span. + spanAttributes: + http.referer: $http_referer + nameOverride: "" fullnameOverride: ""