-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft: adding support for proxy cache
- Loading branch information
AnchorArray
committed
Nov 16, 2024
1 parent
075bdef
commit d298b90
Showing
6 changed files
with
169 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{{- if .Values.cache.enable }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ .Release.Name }}-cache | ||
data: | ||
nginx.conf: | | ||
pid /tmp/nginx.pid; | ||
events { | ||
worker_connections 1024; | ||
} | ||
http { | ||
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=my_cache:10m max_size=1g | ||
inactive=60m use_temp_path=off; | ||
client_body_temp_path /tmp/client_temp; | ||
proxy_temp_path /tmp/proxy_temp_path; | ||
fastcgi_temp_path /tmp/fastcgi_temp; | ||
uwsgi_temp_path /tmp/uwsgi_temp; | ||
scgi_temp_path /tmp/scgi_temp; | ||
server { | ||
listen 8080; | ||
server_name localhost; | ||
location /v1/policy/list { | ||
include cache_config.conf; | ||
include common_proxy.conf; | ||
proxy_cache_key "$request_uri|$http_x_whylabs_organization"; | ||
} | ||
location /v1/organizations/managed-organizations { | ||
include cache_config.conf; | ||
include common_proxy.conf; | ||
proxy_cache_key "$request_uri|$http_x_whylabs_organization"; | ||
} | ||
location /v1/policy { | ||
include cache_config.conf; | ||
include common_proxy.conf; | ||
proxy_cache_key "$request_uri|$http_x_whylabs_organization"; | ||
} | ||
location /v1/api-key/validate { | ||
include cache_config.conf; | ||
include common_proxy.conf; | ||
proxy_cache_key "$request_uri|$http_x_api_key"; | ||
} | ||
location / { | ||
include common_proxy.conf; | ||
} | ||
} | ||
} | ||
cache_config.conf: | | ||
proxy_cache my_cache; | ||
proxy_cache_valid 200 403 1m; | ||
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; | ||
add_header X-Cache-Status $upstream_cache_status always; | ||
common_proxy.conf: | | ||
proxy_pass https://songbird.development.whylabsdev.com; | ||
proxy_set_header Host songbird.development.whylabsdev.com; | ||
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 Accept $http_accept; | ||
proxy_set_header Accept-Encoding $http_accept_encoding; | ||
proxy_set_header X-API-Key $http_x_api_key; | ||
proxy_set_header X-WhyLabs-Organization $http_x_whylabs_organization; | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{{- if .Values.cache.enable }} | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ .Release.Name }}-cache | ||
labels: | ||
{{- include "guardrails.labels" . | nindent 4 }} | ||
spec: | ||
replicas: {{ .Values.cache.replicaCount }} | ||
selector: | ||
matchLabels: | ||
app: {{ .Release.Name }}-cache | ||
template: | ||
metadata: | ||
{{- with .Values.cache.annotations }} | ||
annotations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "guardrails.labels" . | nindent 8 }} | ||
app: {{ .Release.Name }}-cache | ||
spec: | ||
serviceAccountName: {{ include "guardrails.serviceAccountName" . }} | ||
containers: | ||
- name: nginx | ||
securityContext: | ||
privileged: false | ||
allowPrivilegeEscalation: false | ||
readOnlyRootFilesystem: true | ||
runAsNonRoot: true | ||
runAsUser: 101 | ||
runAsGroup: 101 | ||
fsGroup: 101 | ||
capabilities: | ||
drop: ["ALL"] | ||
image: "nginxinc/nginx-unprivileged:latest" | ||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
protocol: TCP | ||
volumeMounts: | ||
- name: nginx-config | ||
mountPath: /etc/nginx/nginx.conf | ||
subPath: nginx.conf | ||
- name: nginx-config | ||
mountPath: /etc/nginx/cache_config.conf | ||
subPath: cache_config.conf | ||
- name: nginx-config | ||
mountPath: /etc/nginx/common_proxy.conf | ||
subPath: common_proxy.conf | ||
- name: nginx-temp | ||
mountPath: /tmp | ||
- name: nginx-cache | ||
mountPath: /var/cache/nginx | ||
volumes: | ||
- name: nginx-temp | ||
emptyDir: {} | ||
- name: nginx-cache | ||
emptyDir: {} | ||
- name: nginx-config | ||
configMap: | ||
name: {{ include "guardrails.fullname" . }}-cache | ||
{{- with .Values.nodeSelector }} | ||
nodeSelector: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.affinity }} | ||
affinity: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.tolerations }} | ||
tolerations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{- if .Values.cache.enable }} | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ .Release.Name }}-cache | ||
spec: | ||
type: ClusterIP | ||
ports: | ||
- name: http | ||
protocol: TCP | ||
port: 80 | ||
targetPort: 8080 | ||
selector: | ||
app: {{ .Release.Name }}-cache | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters