Skip to content

Commit 17cea03

Browse files
committed
Fixes to the lib and migrate mfr chart to use the lib
1 parent b57c39e commit 17cea03

31 files changed

+842
-1167
lines changed

angular-osf/values.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ main:
158158

159159

160160
# ------- Pod Annotations -------
161-
# Checksum for configmap and secret will be added automatically
162-
podAnnotations: []
161+
podAnnotations:
162+
checksum/main-config: '{{ include "cos-common.componentChecksum" (dict "root" . "name" "" "values" .Values.main "resource" "configmap") }}'
163+
checksum/main-config-env: '{{ include "cos-common.componentChecksum" (dict "root" . "name" "env" "values" .Values.main "resource" "configmap") }}'
163164

164165

165166
# ------- Service configuration -------

cos-common/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ app:
143143
- **NetworkPolicy**: defaults to namespace-local ingress allow; egress only if `allowEgress: true` or `extraEgressRules` present. Use `componentScoped: false` to drop the component label when you want one policy to cover multiple components. `additionalNetworkPolicies[]` supported.
144144
- **Certificates**: renders cert-manager `Certificate`; `issuerRef` required when enabled. `certificate.acmeConfig` maps to `spec.acme.config[]` (defaults `http01.ingress` to the chart fullname when not set). `additionalCertificates[]` available.
145145
- **Persistence**: component-level `persistence` or `volumes[].persistence` can auto-create PVCs (unless `existingClaim`); per-volume persistence forbids `emptyDir` and wires the volume to the claim automatically.
146+
- **Additional containers**: `sidecars`/`additionalContainers` can inherit mounts or resources from another container in the same component via `inheritVolumeMountsFrom` / `inheritResourcesFrom` (explicit fields on the child override inherited ones).
146147
- **CronJob**: `schedule` is required; job-spec knobs (`parallelism`, `backoffLimit`, `podFailurePolicy`, etc.) live directly under the component block.
147148
- **Annotations**: `annotations` apply broadly by default; set `annotationsWorkloadOnly: true` or use `workloadAnnotations` to scope/override annotations on the workload resources only (deployment/statefulset/job/cronjob), e.g., for Helm hooks.
148149
- **StatefulSet**: define `serviceName` and `volumeClaimTemplates` as needed; supports `persistentVolumeClaimRetentionPolicy`.

cos-common/templates/_deployment.tpl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,8 @@ spec:
3535
{{ end }}
3636
template:
3737
metadata:
38-
labels:
39-
{{- include "cos-common.podLabels" . | nindent 8 }}
40-
{{- with $vals.podLabels }}
41-
{{- tpl (toYaml .) $.root | nindent 8 }}
42-
{{- end }}
43-
annotations:
44-
{{- with $vals.podAnnotations }}
45-
{{- tpl (toYaml .) $.root | nindent 8 }}
46-
{{- end }}
47-
{{- include "cos-common.podChecksums" . | nindent 8 }}
38+
{{- /* Pod labels/annotations stay aligned with selectors. */}}
39+
{{- include "cos-common.podMetadata" . | nindent 6 }}
4840
spec:
4941
{{- /* Shared pod spec helper wires containers, volumes, TLS, affinities, etc. */}}
5042
{{- include "cos-common.podSpec" . | nindent 6 }}

cos-common/templates/_helpers.tpl

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -235,51 +235,26 @@ workload-specific additions via `workloadAnnotations`.
235235
{{- end }}
236236
{{- end }}
237237

238-
{{/*
239-
Compute pod checksum annotations for resources that affect runtime.
240-
Currently:
241-
- ConfigMap
242-
- Secret
243-
*/}}
244-
{{- define "cos-common.podChecksums" -}}
245-
246-
{{- /* ConfigMap checksum */ -}}
247-
{{- if and .values.configMap (default false .values.configMap.enabled) }}
248-
checksum/configmap: {{ include "cos-common.componentChecksum" (dict
249-
"root" .root
250-
"name" .name
251-
"values" .values
252-
"resource" "configmap"
253-
) }}
254-
{{- end }}
255-
256-
{{- /* Secret checksum */ -}}
257-
{{- if and .values.secret (default false .values.secret.enabled) }}
258-
checksum/secret: {{ include "cos-common.componentChecksum" (dict
259-
"root" .root
260-
"name" .name
261-
"values" .values
262-
"resource" "secret"
263-
) }}
264-
{{- end }}
265-
266-
{{- end }}
267-
268238
{{/*
269239
Render pod metadata labels and annotations.
270240
*/}}
271241
{{- define "cos-common.podMetadata" -}}
272242
labels:
273243
{{- include "cos-common.podLabels" . | nindent 2 }}
274244
{{- with .values.podLabels }}
275-
{{ tpl (toYaml .) .root | nindent 2 }}
276-
{{ end }}
245+
{{- range $k, $v := . }}
246+
{{ $k }}: {{ tpl (printf "%s" $v) $.root | quote }}
247+
{{- end }}
248+
{{- end }}
249+
277250
{{- with .values.podAnnotations }}
278251
annotations:
279-
{{- $podAnns := tpl (toYaml .) .root | trimSuffix "\n" }}
280-
{{ $podAnns | nindent 2 }}
281-
{{ end }}
282-
{{ end }}
252+
{{- range $k, $v := . }}
253+
{{ $k }}: {{ tpl (printf "%s" $v) $.root | quote }}
254+
{{- end }}
255+
{{- end }}
256+
{{- end }}
257+
283258

284259
{{/*
285260
Helper to render list values with tpl evaluation.
@@ -462,7 +437,7 @@ resources:
462437

463438
{{/*
464439
Render additional containers (sidecars/extra).
465-
Merges sidecars and additionalContainers, lets you inherit mounts from another container,
440+
Merges sidecars and additionalContainers, lets you inherit mounts/resources from another container,
466441
adds TLS mounts, normalizes ports/probes, and strips helper-only keys before render.
467442
*/}}
468443
{{- define "cos-common.additionalContainers" -}}
@@ -480,6 +455,7 @@ adds TLS mounts, normalizes ports/probes, and strips helper-only keys before ren
480455
{{- $c := deepCopy . -}}
481456
{{- $name := default "" $c.name -}}
482457
{{- $volumeMounts := list -}}
458+
{{- $inheritedResources := dict -}}
483459
{{- if $c.inheritVolumeMountsFrom }}
484460
{{- /* copy mounts from another named container section (e.g., main.daphne) */ -}}
485461
{{- $inheritFrom := tpl (toString $c.inheritVolumeMountsFrom) $.root -}}
@@ -493,8 +469,18 @@ adds TLS mounts, normalizes ports/probes, and strips helper-only keys before ren
493469
{{- end }}
494470
{{- end }}
495471
{{- end }}
472+
{{- if $c.inheritResourcesFrom }}
473+
{{- $inheritResourcesFrom := tpl (toString $c.inheritResourcesFrom) $.root -}}
474+
{{- $src := index $vals $inheritResourcesFrom -}}
475+
{{- if kindIs "map" $src }}
476+
{{- with $src.resources }}
477+
{{- $inheritedResources = merge (dict) $inheritedResources . -}}
478+
{{- end }}
479+
{{- end }}
480+
{{- end }}
496481
{{- /* remove helper-only key so it doesn't reach k8s */ -}}
497482
{{- $_ := unset $c "inheritVolumeMountsFrom" -}}
483+
{{- $_ := unset $c "inheritResourcesFrom" -}}
498484
{{- $volumeMounts = concat $volumeMounts (default (list) $c.volumeMounts) -}}
499485
{{- if $tlsConfigs }}
500486
{{- range $app, $cfg := $tlsConfigs }}
@@ -506,6 +492,10 @@ adds TLS mounts, normalizes ports/probes, and strips helper-only keys before ren
506492
{{- if gt (len $volumeMounts) 0 }}
507493
{{- $_ := set $c "volumeMounts" $volumeMounts -}}
508494
{{- end }}
495+
{{- $resources := merge (dict) $inheritedResources (default (dict) $c.resources) -}}
496+
{{- if gt (len $resources) 0 }}
497+
{{- $_ := set $c "resources" $resources -}}
498+
{{- end }}
509499
{{- if $c.ports }}
510500
{{- $ports := list }}
511501
{{- range $c.ports }}

cos-common/values.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@
262262
"type": "object",
263263
"additionalProperties": true
264264
},
265+
"inheritResourcesFrom": {
266+
"type": "string",
267+
"description": "Name of another container entry in this component whose resources should be merged into this container."
268+
},
265269
"securityContext": {
266270
"type": "object",
267271
"additionalProperties": true
@@ -272,6 +276,10 @@
272276
"$ref": "#/definitions/volumeMount"
273277
}
274278
},
279+
"inheritVolumeMountsFrom": {
280+
"type": "string",
281+
"description": "Name of another container entry in this component whose volumeMounts should be copied into this container."
282+
},
275283
"livenessProbe": {
276284
"$ref": "#/definitions/probe"
277285
},

mfr/Chart.yaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
apiVersion: v1
2-
description: A Helm chart for Kubernetes
1+
apiVersion: v2
32
name: mfr
4-
version: 0.9.3
3+
description: Modular File Renderer
4+
type: application
5+
version: 1.0.0
56
keywords:
67
- renderer
78
sources:
@@ -10,5 +11,18 @@ maintainers:
1011
- name: Matt Frazier
1112
email: matt@cos.io
1213
url: https://github.com/mfraezz
13-
engine: gotpl
14-
tillerVersion: '>=2.7.0'
14+
dependencies:
15+
- name: cos-common
16+
version: 1.0.0
17+
repository: https://centerforopenscience.github.io/helm-charts/
18+
# - name: cos-common
19+
# version: 1.0.0
20+
# repository: "file://../cos-common"
21+
- name: maintenance
22+
version: 0.2.0
23+
repository: https://centerforopenscience.github.io/helm-charts/
24+
condition: maintenance.enabled, global.maintenance.enabled
25+
- name: rabbitmq
26+
version: 6.9.1
27+
repository: https://centerforopenscience.github.io/helm-charts/
28+
condition: rabbitmq.enabled, global.rabbitmq.enabled

mfr/files/nginx.conf

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
user nginx;
2+
worker_processes {{ .Values.nginx.workerCount }};
3+
4+
load_module /usr/lib/nginx/modules/ngx_http_brotli_filter_module.so;
5+
{{- if .Values.nginx.vts.enabled }}
6+
load_module /usr/lib/nginx/modules/ngx_http_geoip_module.so;
7+
load_module /usr/lib/nginx/modules/ngx_http_vhost_traffic_status_module.so;
8+
{{- end }}
9+
10+
error_log /var/log/nginx/error.log warn;
11+
pid /var/run/nginx.pid;
12+
13+
events {
14+
worker_connections 1024;
15+
}
16+
17+
http {
18+
include /etc/nginx/mime.types;
19+
default_type application/octet-stream;
20+
21+
log_format main '$remote_addr - $upstream_cache_status $remote_user [$time_local] '
22+
'"$request" $status $body_bytes_sent '
23+
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for" '
24+
'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';
25+
access_log /var/log/nginx/access.log main;
26+
27+
real_ip_header {{ .Values.nginx.realIpHeader }};
28+
real_ip_recursive {{ .Values.nginx.realIpRecursive }};
29+
{{- range .Values.nginx.proxySourceRanges }}
30+
set_real_ip_from {{ . }};
31+
{{- end }}
32+
33+
{{- if .Values.nginx.vts.enabled }}
34+
geoip_country /etc/nginx/GeoIP.dat;
35+
geoip_city /etc/nginx/GeoLiteCity.dat;
36+
geoip_proxy_recursive on;
37+
{{- range .Values.nginx.proxySourceRanges }}
38+
geoip_proxy {{ . }};
39+
{{- end }}
40+
41+
vhost_traffic_status_zone shared:vhost_traffic_status:{{ .Values.nginx.vts.statusZoneSize }};
42+
vhost_traffic_status_filter_by_set_key {{ .Values.nginx.vts.defaultFilterKey }};
43+
{{- end }}
44+
45+
sendfile on;
46+
tcp_nopush on;
47+
tcp_nodelay on;
48+
keepalive_timeout 620s;
49+
keepalive_requests 10000;
50+
types_hash_max_size 2048;
51+
server_tokens off;
52+
53+
gzip on;
54+
gzip_proxied any;
55+
gzip_disable "msie6";
56+
gzip_min_length 1400;
57+
gzip_vary on;
58+
gzip_buffers 4 32k;
59+
gzip_types text/plain text/css image/svg+xml application/javascript application/x-javascript text/xml text/javascript application/json application/vnd.api+json;
60+
61+
brotli on;
62+
brotli_types text/plain text/css image/svg+xml application/javascript application/x-javascript text/xml text/javascript application/json application/vnd.api+json;
63+
64+
{{- if .Values.nginx.vts.enabled }}
65+
server {
66+
listen {{ .Values.nginx.vts.internalPort }};
67+
server_name _;
68+
69+
location /healthz {
70+
access_log off;
71+
return 200;
72+
}
73+
74+
location /nginx_status {
75+
vhost_traffic_status_display;
76+
vhost_traffic_status_display_format html;
77+
}
78+
}
79+
{{- end }}
80+
81+
server {
82+
listen {{ .Values.main.http.containers.nginx.internalPort }};
83+
keepalive_timeout 620s;
84+
client_max_body_size 25M;
85+
server_name _;
86+
87+
if ($http_x_forwarded_proto = "http") {
88+
return 301 https://$host$request_uri;
89+
}
90+
91+
location = /healthz {
92+
access_log off;
93+
return 200;
94+
}
95+
96+
location = /robots.txt {
97+
alias /usr/share/nginx/html/robots.txt;
98+
}
99+
100+
location / {
101+
# Disable caching of application requests
102+
add_header Cache-Control "no-cache, no-store, max-age=0, must-revalidate";
103+
add_header Expires "-1";
104+
add_header Pragma "no-cache";
105+
106+
# Mitigate HTTPoxy Vulnerability
107+
# https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/
108+
proxy_set_header Proxy "";
109+
110+
proxy_buffering off;
111+
proxy_request_buffering off;
112+
proxy_set_header Host $host;
113+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
114+
proxy_pass http://127.0.0.1:{{ .Values.main.http.containers.nginx.externalPort }};
115+
}
116+
}
117+
}

mfr/requirements.lock

Lines changed: 0 additions & 9 deletions
This file was deleted.

mfr/requirements.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

mfr/templates/NOTES.txt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
1. Get the application URL by running these commands:
2-
{{- if .Values.ingress.hostname }}
3-
http://{{- .Values.ingress.hostname }}
4-
{{- else if contains "NodePort" .Values.service.type }}
5-
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "mfr.fullname" . }})
6-
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
7-
echo http://$NODE_IP:$NODE_PORT
8-
{{- else if contains "LoadBalancer" .Values.service.type }}
9-
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
10-
You can watch the status of by running 'kubectl get svc -w {{ template "mfr.fullname" . }}'
11-
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "mfr.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
12-
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
13-
{{- else if contains "ClusterIP" .Values.service.type }}
14-
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "mfr.fullname" . }}" -o jsonpath="{.items[0].metadata.name}")
15-
echo "Visit http://127.0.0.1:8080 to use your application"
16-
kubectl port-forward $POD_NAME 8080:{{ .Values.service.externalPort }}
1+
{{- $fullname := include "cos-common.fullname" (dict "root" . "name" "") | trim -}}
2+
{{- $service := .Values.main.service -}}
3+
{{- $externalPort := .Values.main.http.containers.nginx.externalPort -}}
4+
{{- $internalPort := .Values.main.http.containers.nginx.internalPort -}}
5+
6+
1. Main service: {{ $fullname }}
7+
{{- if and $service (eq $service.enabled true) }}
8+
{{- if contains "LoadBalancer" $service.type }}
9+
Wait for the external IP, then:
10+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ $fullname }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
11+
echo http://$SERVICE_IP:{{ $externalPort }}
12+
{{- else if contains "NodePort" $service.type }}
13+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ $fullname }})
14+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
15+
echo http://$NODE_IP:$NODE_PORT
16+
{{- else }}
17+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "cos-common.chartName" (dict "root" .) }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
18+
echo "Visit http://127.0.0.1:8080 to use your application"
19+
kubectl port-forward $POD_NAME 8080:{{ $internalPort }}
20+
{{- end }}
21+
{{- else }}
22+
Service disabled.
1723
{{- end }}

0 commit comments

Comments
 (0)