Skip to content

Commit 33d1ea8

Browse files
committed
CP/DP Split: write configuration to agent
This commit adds functionality to send nginx configuration to the agent. It also adds support for the single nginx Deployment to be scaled, and send configuration to all replicas. This requires tracking all Subscriptions for a particular deployment, and receiving all responses from those replicas to determine the status to write to the Gateway. Right now we do not watch for Pod creation events for the nginx Deployment, so when a Pod first starts up, it will not receive any configuration. Only when the config changes will the nginx Pods get an update.
1 parent f8bbcbe commit 33d1ea8

File tree

47 files changed

+1307
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1307
-395
lines changed

build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ FROM golang:1.23 AS ca-certs-provider
1414
FROM scratch AS common
1515
# CA certs are needed for telemetry report so that NGF can verify the server's certificate.
1616
COPY --from=ca-certs-provider --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
17-
USER 102:1001
17+
USER 101:1001
1818
ARG BUILD_AGENT
1919
ENV BUILD_AGENT=${BUILD_AGENT}
2020
ENTRYPOINT [ "/usr/bin/gateway" ]

charts/nginx-gateway-fabric/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
268268
| `nginx.image.tag` | | string | `"edge"` |
269269
| `nginx.lifecycle` | The lifecycle of the nginx container. | object | `{}` |
270270
| `nginx.plus` | Is NGINX Plus image being used | bool | `false` |
271-
| `nginx.securityContext.allowPrivilegeEscalation` | Some environments may need this set to true in order for the control plane to successfully reload NGINX. | bool | `false` |
272271
| `nginx.usage.caSecretName` | The name of the Secret containing the NGINX Instance Manager CA certificate. Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in (default namespace: nginx-gateway). | string | `""` |
273272
| `nginx.usage.clientSSLSecretName` | The name of the Secret containing the client certificate and key for authenticating with NGINX Instance Manager. Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in (default namespace: nginx-gateway). | string | `""` |
274273
| `nginx.usage.endpoint` | The endpoint of the NGINX Plus usage reporting server. Default: product.connect.nginx.com | string | `""` |

charts/nginx-gateway-fabric/templates/clusterrole.yaml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,21 @@ rules:
1111
- namespaces
1212
- services
1313
- secrets
14+
- pods
1415
{{- if .Values.nginxGateway.gwAPIExperimentalFeatures.enable }}
1516
- configmaps
1617
{{- end }}
1718
verbs:
1819
- get
1920
- list
2021
- watch
21-
{{- if or .Values.nginxGateway.productTelemetry.enable .Values.nginx.plus }}
22-
- apiGroups:
23-
- ""
24-
resources:
25-
- pods
26-
verbs:
27-
- get
2822
- apiGroups:
2923
- apps
3024
resources:
3125
- replicasets
3226
verbs:
3327
- get
34-
{{- end }}
35-
{{- if .Values.nginx.plus }}
36-
- apiGroups:
37-
- apps
38-
resources:
39-
- replicasets
40-
verbs:
4128
- list
42-
{{- end }}
4329
{{- if or .Values.nginxGateway.productTelemetry.enable .Values.nginx.plus }}
4430
- apiGroups:
4531
- ""

charts/nginx-gateway-fabric/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ spec:
140140
drop:
141141
- ALL
142142
readOnlyRootFilesystem: true
143-
runAsUser: 102
143+
runAsUser: 101
144144
runAsGroup: 1001
145145
{{- with .Values.nginxGateway.extraVolumeMounts -}}
146146
{{ toYaml . | nindent 8 }}

charts/nginx-gateway-fabric/templates/scc.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# TODO(sberman): will need an SCC for nginx ServiceAccounts as well.
12
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
23
kind: SecurityContextConstraints
34
apiVersion: security.openshift.io/v1
45
metadata:
56
name: {{ include "nginx-gateway.scc-name" . }}
6-
allowPrivilegeEscalation: {{ .Values.nginx.securityContext.allowPrivilegeEscalation }}
7+
allowPrivilegeEscalation: false
78
allowHostDirVolumePlugin: false
89
allowHostIPC: false
910
allowHostNetwork: false

charts/nginx-gateway-fabric/templates/tmp-nginx-agent-conf.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ data:
1515
- /var/run/nginx
1616
features:
1717
- connection
18+
- configuration
19+
- certificates
20+
- metrics
1821
log:
1922
level: debug

charts/nginx-gateway-fabric/templates/tmp-nginx-deployment.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
command:
2222
- /usr/bin/gateway
2323
- sleep
24-
- --duration=15s
24+
- --duration=5s
2525
- name: init
2626
image: {{ .Values.nginxGateway.image.repository }}:{{ default .Chart.AppVersion .Values.nginxGateway.image.tag }}
2727
imagePullPolicy: {{ .Values.nginxGateway.image.pullPolicy }}
@@ -49,7 +49,7 @@ spec:
4949
drop:
5050
- ALL
5151
readOnlyRootFilesystem: true
52-
runAsUser: 102
52+
runAsUser: 101
5353
runAsGroup: 1001
5454
volumeMounts:
5555
- name: nginx-includes-bootstrap
@@ -72,13 +72,12 @@ spec:
7272
securityContext:
7373
seccompProfile:
7474
type: RuntimeDefault
75-
allowPrivilegeEscalation: {{ .Values.nginx.securityContext.allowPrivilegeEscalation }}
7675
capabilities:
7776
add:
7877
- NET_BIND_SERVICE
7978
drop:
8079
- ALL
81-
readOnlyRootFilesystem: true
80+
# readOnlyRootFilesystem: true
8281
runAsUser: 101
8382
runAsGroup: 1001
8483
volumeMounts:

charts/nginx-gateway-fabric/values.schema.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,6 @@
259259
"title": "plus",
260260
"type": "boolean"
261261
},
262-
"securityContext": {
263-
"properties": {
264-
"allowPrivilegeEscalation": {
265-
"default": false,
266-
"description": "Some environments may need this set to true in order for the control plane to successfully reload NGINX.",
267-
"required": [],
268-
"title": "allowPrivilegeEscalation",
269-
"type": "boolean"
270-
}
271-
},
272-
"required": [],
273-
"title": "securityContext",
274-
"type": "object"
275-
},
276262
"usage": {
277263
"description": "Configuration for NGINX Plus usage reporting.",
278264
"properties": {

charts/nginx-gateway-fabric/values.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ nginx:
131131
# @schema
132132
pullPolicy: Always
133133

134-
securityContext:
135-
# -- Some environments may need this set to true in order for the control plane to successfully reload NGINX.
136-
allowPrivilegeEscalation: false
137-
138134
# -- Is NGINX Plus image being used
139135
plus: false
140136

cmd/gateway/initialize.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"path/filepath"
78
"time"
89

@@ -58,7 +59,7 @@ func initialize(cfg initializeConfig) error {
5859
return fmt.Errorf("failed to generate deployment context file: %w", err)
5960
}
6061

61-
if err := file.Write(cfg.fileManager, depCtxFile); err != nil {
62+
if err := file.Write(cfg.fileManager, file.Convert(depCtxFile)); err != nil {
6263
return fmt.Errorf("failed to write deployment context file: %w", err)
6364
}
6465

@@ -84,5 +85,9 @@ func copyFile(osFileManager file.OSFileManager, src, dest string) error {
8485
return fmt.Errorf("error copying file contents: %w", err)
8586
}
8687

88+
if err := osFileManager.Chmod(destFile, os.FileMode(file.RegularFileModeInt)); err != nil {
89+
return fmt.Errorf("error setting file permissions: %w", err)
90+
}
91+
8792
return nil
8893
}

0 commit comments

Comments
 (0)