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

mount nginx.conf as a volume to the frontend container #244

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
93 changes: 93 additions & 0 deletions charts/opencost/templates/configmap-frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{{- if .Values.opencost.ui.enabled }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this specific configmap always necessary if opencost ui is enabled? My initial reaction is this should be a separate setting, but as long as its not going to be a breaking change for users I'm ok enabling it by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This configmap is added during runtime in opencost-ui image. Which has write permission issues in openshift environment. This change will not break with opencost-ui v1.114.0 in which @kastl-ars added an if condition in the entrypoint script there. We can get this in after bumping opencost-ui image to 1.114.0 . But as it can break for lower versions, should we keep it under a separate setting, considering that we can release it with ui image bump.

{{- $serviceName := include "opencost.fullname" . -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: opencost-ui-nginx-conf
namespace: {{ .Release.Namespace }}
data:
nginx.conf: |
gzip_static on;
gzip on;
gzip_min_length 50000;
gzip_proxied expired no-cache no-store private auth;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/vnd.ms-fontobject
application/wasm
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/bmp
image/svg+xml
text/cache-manifest
text/calendar
text/css
text/javascript
text/markdown
text/plain
text/xml
text/x-component
text/x-cross-domain-policy;

upstream model {
{{- if .Values.opencost.ui.useDefaultFqdn }}
server {{ $serviceName }}.{{ .Release.Namespace }}.svc.cluster.local:9003;
{{- else if .Values.opencost.ui.modelFqdn }}
server {{ .Values.opencost.ui.modelFqdn }};
{{- else }}
server {{ $serviceName }}.{{ .Release.Namespace }}:9003;
{{- end }}
}

server {
server_name _;
root /var/www;
index index.html;
large_client_header_buffers 4 32k;
add_header Cache-Control "must-revalidate";

error_page 504 /custom_504.html;
location = /custom_504.html {
internal;
}

add_header Cache-Control "max-age=300";
location / {
root /var/www;
index index.html index.htm;
try_files $uri /index.html;
}

add_header ETag "1.96.0";
listen {{ .Values.opencost.ui.uiPort }};
listen [::]:{{ .Values.opencost.ui.uiPort }};
resolver 127.0.0.1 valid=5s;
location /healthz {
access_log /dev/null;
return 200 'OK';
}
location /model/ {
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_pass http://model/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
{{- end }}
16 changes: 14 additions & 2 deletions charts/opencost/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,13 @@ spec:
{{- with .Values.opencost.ui.securityContext }}
securityContext: {{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
{{- with .Values.opencost.ui.extraVolumeMounts }}
volumeMounts: {{- toYaml . | nindent 12 }}
{{- toYaml . | nindent 12 }}
{{- end }}
- name: nginx-conf
mountPath: /etc/nginx/conf.d/default.nginx.conf
subPath: default.nginx.conf
{{- end }}
{{- with .Values.opencost.extraContainers }}
{{- toYaml . | nindent 8 }}
Expand Down Expand Up @@ -352,7 +356,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret}}
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret .Values.opencost.ui.enabled }}
volumes:
{{- if .Values.plugins.enabled }}
{{- if .Values.plugins.install.enabled}}
Expand Down Expand Up @@ -389,6 +393,14 @@ spec:
- key: cloud-integration.json
path: cloud-integration.json
{{- end }}
{{- if .Values.opencost.ui.enabled }}
- name: nginx-conf
configMap:
name: nginx-conf
items:
- key: nginx.conf
path: default.nginx.conf
{{- end }}
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
6 changes: 6 additions & 0 deletions charts/opencost/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ opencost:
# -- A list of volume mounts to be added to the pod
extraVolumeMounts: []

# set to true to set upstream to use <service>.<namespace>.svc.cluster.local instead of just <service>.<namespace>
useDefaultFqdn: false

# Set the model fqdn to use for the upstream
# modelFqdn: opencost.opencost.svc.cluster.local:9003

ingress:
# -- Ingress for OpenCost UI
enabled: false
Expand Down
Loading