Skip to content

Commit ec1f20f

Browse files
zarbismikhail-klimkodmaizel
authored
feat: internal-gateway: add njs scripts (#92)
Co-authored-by: Mikhail Klimko <[email protected]> Co-authored-by: Daniel Maizel <[email protected]>
1 parent 7854b58 commit ec1f20f

File tree

13 files changed

+159
-99
lines changed

13 files changed

+159
-99
lines changed

.github/workflows/lint-test.yaml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ concurrency:
2222
permissions:
2323
contents: read
2424

25-
env:
26-
HELM_VERSION: 3.9.2 # Also update in release.yaml
27-
2825
jobs:
2926
lint-charts:
3027
runs-on: ubuntu-latest
@@ -37,9 +34,7 @@ jobs:
3734
fetch-depth: 0
3835

3936
- name: Set up Helm
40-
uses: azure/setup-helm@v3
41-
with:
42-
version: ${{ env.HELM_VERSION }}
37+
uses: azure/[email protected]
4338

4439
- name: Set up Python
4540
uses: actions/setup-python@v4
@@ -50,7 +45,7 @@ jobs:
5045
uses: dcarbone/[email protected]
5146

5247
- name: Set up chart-testing
53-
uses: helm/chart-testing-action@v2.1.0
48+
uses: helm/chart-testing-action@v2.7.0
5449

5550
- name: Run chart-testing (list-changed)
5651
id: list-changed
@@ -124,9 +119,7 @@ jobs:
124119
fetch-depth: 0
125120

126121
- name: Set up Helm
127-
uses: azure/setup-helm@v3
128-
with:
129-
version: ${{ env.HELM_VERSION }}
122+
uses: azure/[email protected]
130123

131124
- name: Run unit tests
132125
run: |
@@ -151,9 +144,7 @@ jobs:
151144
fetch-depth: 0
152145

153146
- name: Set up Helm
154-
uses: azure/setup-helm@v3
155-
with:
156-
version: v3.8.2
147+
uses: azure/[email protected]
157148

158149
- name: Set up yq
159150
uses: chrisdickinson/setup-yq@latest

.github/workflows/release.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ on:
1010
concurrency:
1111
group: helm-release
1212

13-
env:
14-
HELM_VERSION: 3.9.2 # Also update in lint-test.yaml
15-
1613
jobs:
1714
publish:
1815
permissions:
@@ -25,9 +22,7 @@ jobs:
2522
fetch-depth: 0
2623

2724
- name: Set up Helm
28-
uses: azure/setup-helm@v3
29-
with:
30-
version: ${{ env.HELM_VERSION }}
25+
uses: azure/[email protected]
3126

3227
- name: Configure Git
3328
run: |

charts/internal-gateway/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: A Helm chart for Codefresh Internal Gateway
44
name: internal-gateway
5-
version: 0.9.0
5+
version: 0.10.0
66
home: https://github.com/codefresh-io/helm-charts
77
keywords:
88
- codefresh
@@ -13,4 +13,4 @@ maintainers:
1313
dependencies:
1414
- name: cf-common
1515
repository: oci://quay.io/codefresh/charts
16-
version: "0.16.0"
16+
version: "0.21.0"

charts/internal-gateway/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# internal-gateway
22

3-
![Version: 0.9.0](https://img.shields.io/badge/Version-0.9.0-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
3+
![Version: 0.10.0](https://img.shields.io/badge/Version-0.10.0-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
44

55
A Helm chart for Codefresh Internal Gateway
66

@@ -16,7 +16,7 @@ A Helm chart for Codefresh Internal Gateway
1616

1717
| Repository | Name | Version |
1818
|------------|------|---------|
19-
| oci://quay.io/codefresh/charts | cf-common | 0.16.0 |
19+
| oci://quay.io/codefresh/charts | cf-common | 0.21.0 |
2020

2121
## Values
2222

@@ -33,7 +33,8 @@ A Helm chart for Codefresh Internal Gateway
3333
| global.dnsService | string | `"kube-dns"` | configures DNS service name |
3434
| hpa | object | See below | HPA parameters |
3535
| ingress | object | See below | Ingress parameters |
36-
| libraryMode | bool | `true` | |
36+
| keda.enabled | bool | `false` | |
37+
| libraryMode | bool | `false` | |
3738
| nginx.config.accessLogEnabled | bool | `true` | Enables NGINX access logs |
3839
| nginx.config.errorLogLevel | string | `"error"` | Sets the log level of the NGINX error log. One of `debug`, `info`, `notice`, `warn`, `error`, `crit`, `alert`, or `emerg` |
3940
| nginx.config.file | string | See below | Config file contents for Nginx. Passed through the `tpl` function to allow templating. !! Moved into separate template at `templates/nginx/configmap.yaml` |
@@ -44,12 +45,16 @@ A Helm chart for Codefresh Internal Gateway
4445
| nginx.config.locations | object | `{}` | Allow add custom locations |
4546
| nginx.config.logFormat | string | `"main escape=json '{ \"time\": \"$time_iso8601\", \"remote_addr\": \"$proxy_protocol_addr\", \"x-forward-for\": \"$proxy_add_x_forwarded_for\", \"remote_user\": \"$remote_user\", \"bytes_sent\": $bytes_sent, \"request_time\": $request_time, \"status\": $status, \"vhost\": \"$host\", \"request_proto\": \"$server_protocol\", \"path\": \"$uri\", \"request_query\": \"$args\", \"request_length\": $request_length, \"duration\": $request_time, \"method\": \"$request_method\", \"http_referrer\": \"$http_referer\", \"http_user_agent\": \"$http_user_agent\", \"http_x_github_delivery\": \"$http_x_github_delivery\", \"http_x_hook_uuid\": \"$http_x_hook_uuid\", \"metadata\": { \"correlationId\": \"$request_id\", \"service\": \"ingress\", \"time\": \"$time_iso8601\" } }';"` | NGINX log format |
4647
| nginx.config.resolver | string | `nil` | Allows to set a custom resolver |
48+
| nginx.config.rootDirectives | object | `{"load_module":"modules/ngx_http_js_module.so"}` | Allows appending custom directives to the root block (map) |
49+
| nginx.config.rootSnippet | string | `""` | Allows appending custom directives to the root block (string) |
4750
| nginx.config.serverDirectives | object | `{}` | Allows appending custom directives to the server block (map) |
4851
| nginx.config.serverSnippet | string | `""` | Allows appending custom configuration to the server block (string) |
4952
| nginx.config.verboseLogging | bool | `false` | Enable logging of 2xx and 3xx HTTP requests |
5053
| nginx.config.workerConnections | string | `"16384"` | Sets the maximum number of simultaneous connections that can be opened by a worker process. |
5154
| nginx.config.workerProcesses | string | `"8"` | Defines the number of worker processes. |
5255
| nginx.config.workerRlimitNofile | string | `"1047552"` | Changes the limit on the largest size of a core file (RLIMIT_CORE) for worker processes. Used to increase the limit without restarting the main process. |
56+
| nginx.extraConfigsPatterns[0] | string | `"files/conf.d/**"` | |
57+
| nginx.scriptFilesPatterns | list | `["files/njs/**"]` | Path to NJS scripts |
5358
| pdb | object | See below | PDB parameters |
5459
| podAnnotations | object | See below | Pod annotations |
5560
| podSecurityContext | object | See below | Pod Security Context parameters |
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{{- $vals := include "internal-gateway.default-values" . | fromYaml -}}
2+
{{- $mergedValues := mergeOverwrite $vals .Values -}}
3+
{{- $_ := set . "Values" $mergedValues -}}
4+
server {
5+
listen 8080;
6+
server_name {{ index $vals "codefresh" "serviceEndpoints" "workflow-logs-s3-proxy" "domain" }};
7+
8+
js_import scripts/auth.js;
9+
location ~ /(.+) {
10+
client_body_buffer_size 32k;
11+
client_max_body_size 10M;
12+
proxy_buffer_size 128k;
13+
proxy_buffers 4 128k;
14+
proxy_connect_timeout 5s;
15+
proxy_read_timeout 60s;
16+
proxy_send_timeout 60s;
17+
18+
auth_request /api/auth/authenticate;
19+
auth_request_set $auth_entity $upstream_http_x_cf_auth_entity;
20+
21+
js_set $account_id auth.account_id;
22+
23+
proxy_pass http://{{ index $vals "codefresh" "serviceEndpoints" "workflow-logs-s3-proxy" "svc" }}:{{ index $vals "codefresh" "serviceEndpoints" "workflow-logs-s3-proxy" "port" }}/logs/$account_id/$1;
24+
}
25+
26+
location = /api/auth/authenticate {
27+
client_body_buffer_size 32k;
28+
client_max_body_size 10M;
29+
proxy_buffer_size 128k;
30+
proxy_buffers 4 128k;
31+
proxy_connect_timeout 5s;
32+
proxy_read_timeout 60s;
33+
proxy_send_timeout 60s;
34+
35+
js_set $auth_header auth.setAuthHeader;
36+
37+
proxy_set_header Authorization $auth_header;
38+
39+
proxy_pass http://{{ index $vals "codefresh" "serviceEndpoints" "cfapi-auth" "svc" }}:{{ index $vals "codefresh" "serviceEndpoints" "cfapi-auth" "port" }};
40+
}
41+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function account_id(r) {
2+
try {
3+
const auth_entity = r.variables["auth_entity"];
4+
const b64decoded = Buffer.from(auth_entity, 'base64');
5+
const json = JSON.parse(b64decoded);
6+
const account_id = json.account.id;
7+
8+
return account_id;
9+
} catch (e) {
10+
r.error('Failed to extract account id', e);
11+
return "";
12+
}
13+
}
14+
15+
16+
function setAuthHeader(r) {
17+
let auth = r.headersIn['authorization'];
18+
if (auth) {
19+
// Look for the pattern: Credential=<value>/...
20+
let matches = auth.match(/Credential=([^\/]+)\//);
21+
if (matches && matches.length > 1) {
22+
return matches[1];
23+
}
24+
}
25+
return "";
26+
}
27+
28+
export default { account_id, setAuthHeader };

charts/internal-gateway/templates/_components/_configmap.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ data:
1919
pid /tmp/nginx.pid;
2020
worker_rlimit_nofile {{ $nginxConfig.workerRlimitNofile }};
2121

22+
{{- with $nginxConfig.rootSnippet }}
23+
{{ . | nindent 4 }}
24+
{{- end }}
25+
26+
{{- range $key, $val := $nginxConfig.rootDirectives }}
27+
{{ printf "%s %s;" $key $val }}
28+
{{- end }}
29+
2230
events {
2331
worker_connections {{ $nginxConfig.workerConnections }};
2432
}
@@ -117,5 +125,6 @@ data:
117125
{{- end }}
118126
{{- end }}
119127
}
128+
include /etc/nginx/conf.d/*.conf;
120129
}
121130
{{- end }}

charts/internal-gateway/templates/_default_values.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ codefresh:
5858
jira-addon:
5959
svc: '{{ .Release.Name }}-{{ index .Values.codefresh "jira-addon-svc" }}.{{ .Release.Namespace }}.svc.{{ .Values.global.clusterDomain }}'
6060
port: {{ index .Values.codefresh "jira-addon-port" }}
61+
workflow-logs-s3-proxy:
62+
domain: logs.sandbox-1.codefresh.io
63+
svc: '{{ .Release.Name }}-{{ index .Values.codefresh "workflow-logs-s3-proxy-svc" }}.{{ .Release.Namespace }}.svc.{{ .Values.global.clusterDomain }}'
64+
port: {{ index .Values.codefresh "workflow-logs-s3-proxy-port" }}
6165
{{- end }}

charts/internal-gateway/templates/_location_map.tpl

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -26,78 +26,8 @@ locationDirectives:
2626
proxy_read_timeout: "60s"
2727
{{- end }}
2828

29-
{{- define "internal-gateway.platform-endpoints-defaults" }}
30-
serviceEndpoints:
31-
cfapi-auth:
32-
svc: cfapi-auth
33-
port: 80
34-
cfapi-endpoints:
35-
svc: cfapi-endpoints
36-
port: 80
37-
cfapi-environments:
38-
svc: cfapi-environments
39-
port: 80
40-
cfapi-downloadlogmanager:
41-
svc: cfapi-downloadlogmanager
42-
port: 80
43-
cfapi-gitops-resource-receiver:
44-
svc: cfapi-gitops-resource-receiver
45-
port: 80
46-
cfapi-test-reporting:
47-
svc: cfapi-test-reporting
48-
port: 80
49-
cfapi-kubernetesresourcemonitor:
50-
svc: cfapi-kubernetesresourcemonitor
51-
port: 80
52-
cfapi-kubernetes-endpoints:
53-
svc: cfapi-kubernetes-endpoints
54-
port: 80
55-
cfapi-admin:
56-
svc: cfapi-admin
57-
port: 80
58-
cfapi-teams:
59-
svc: cfapi-teams
60-
port: 80
61-
cfapi-ws:
62-
svc: cfapi-ws
63-
port: 80
64-
cfui:
65-
svc: cfui
66-
port: 80
67-
argo-platform-api-graphql:
68-
svc: argo-platform-api-graphql
69-
port: 80
70-
argo-platform-api-events:
71-
svc: argo-platform-api-events
72-
port: 80
73-
argo-platform-broadcaster:
74-
svc: argo-platform-broadcaster
75-
port: 80
76-
argo-platform-ui:
77-
svc: argo-platform-ui
78-
port: 4200
79-
argo-hub:
80-
svc: argo-hub-platform
81-
port: 80
82-
nomios:
83-
svc: nomios
84-
port: 80
85-
jira-addon:
86-
svc: cf-jira-addon
87-
port: 9000
88-
{{- end }}
89-
90-
{{- define "internal-gateway.platform-endpoints" }}
91-
{{- $endpointDefaults := include "internal-gateway.platform-endpoints-defaults" . | fromYaml}}
92-
{{- $mergedEndpoints := deepCopy $endpointDefaults }}
93-
{{- if .Values.codefresh.serviceEndpoints }}
94-
{{- $mergedEndpoints = mergeOverwrite $endpointDefaults .Values.codefresh }}
95-
{{- end }}
96-
{{ $mergedEndpoints | toYaml }}
97-
{{- end }}
98-
99-
{{- define "internal-gateway.nginx-config-defaults"}}
100-
{{- $endpoints := include "internal-gateway.platform-endpoints" . | fromYaml }}
29+
{{- define "internal-gateway.nginx-config-defaults" }}
30+
{{- $endpoints := .Values.codefresh }}
10131
{{- $presets := include "internal-gateway.location-presets" . | fromYaml }}
10232
{{- $_ := set $presets "locationDirectives" (mergeOverwrite $presets.locationDirectives .Values.nginx.config.locationDirectives) }}
10333
nginx:
@@ -353,7 +283,7 @@ nginx:
353283
{{- end }}
354284

355285
{{- define "internal-gateway.nginx-config" }}
356-
{{- $configDefaults := include "internal-gateway.nginx-config-defaults" . | fromYaml}}
286+
{{- $configDefaults := include "internal-gateway.nginx-config-defaults" . | fromYaml }}
357287
{{- $mergedConfig := deepCopy $configDefaults }}
358288
{{- if .Values.nginx }}
359289
{{- $mergedConfig = mergeOverwrite $configDefaults .Values }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if not .Values.libraryMode }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ include "internal-gateway.fullname" . }}-extra-configs
6+
data:
7+
{{- $rootContext := $ }}
8+
{{- range $globPattern := $rootContext.Values.nginx.extraConfigsPatterns }}
9+
{{- range $path, $_ := $rootContext.Files.Glob $globPattern }}
10+
{{ base $path }}: {{ tpl ($rootContext.Files.Get $path) $rootContext | toYaml | nindent 4 }}
11+
{{- end }}
12+
{{- end }}
13+
{{- end }}

0 commit comments

Comments
 (0)