Skip to content

Commit 2b06bc7

Browse files
bjee19sjberman
authored andcommitted
CP/DP split: Support nginx debug mode when provisioning Data Plane (#3147)
Support nginx debug mode when provisioning the Data Plane. Problem: We want to have the option to provision nginx instances in debug mode. Solution: Add debug field to NginxProxy CRD. Also user can set debug field when installing through Helm by setting the nginx.debug flag.
1 parent af91add commit 2b06bc7

File tree

8 files changed

+44
-2
lines changed

8 files changed

+44
-2
lines changed

apis/v1alpha2/nginxproxy_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ type PodSpec struct {
435435

436436
// ContainerSpec defines container fields for the NGINX container.
437437
type ContainerSpec struct {
438+
// Debug enables debugging for NGINX by using the nginx-debug binary.
439+
//
440+
// +optional
441+
Debug *bool `json:"debug,omitempty"`
442+
438443
// Image is the NGINX image to use.
439444
//
440445
// +optional

apis/v1alpha2/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/entrypoint.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ rm -rf /var/run/nginx/*.sock
1616

1717
# Launch nginx
1818
echo "starting nginx ..."
19-
/usr/sbin/nginx -g "daemon off;" &
19+
20+
# if we want to use the nginx-debug binary, we will call this script with an argument "debug"
21+
if [ "${1:-false}" = "debug" ]; then
22+
/usr/sbin/nginx-debug -g "daemon off;" &
23+
else
24+
/usr/sbin/nginx -g "daemon off;" &
25+
fi
2026

2127
nginx_pid=$!
2228

@@ -31,7 +37,7 @@ done
3137

3238
# start nginx-agent, pass args
3339
echo "starting nginx-agent ..."
34-
nginx-agent "$@" &
40+
nginx-agent &
3541

3642
agent_pid=$!
3743

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

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ spec:
2323
{{- end }}
2424
image:
2525
{{- toYaml .Values.nginx.image | nindent 10 }}
26+
{{- if .Values.nginx.debug }}
27+
debug: {{ .Values.nginx.debug }}
28+
{{- end }}
2629
{{- end }}
2730
{{- if .Values.nginx.service }}
2831
service:

config/crd/bases/gateway.nginx.org_nginxproxies.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ spec:
7979
description: Container defines container fields for the NGINX
8080
container.
8181
properties:
82+
debug:
83+
description: Debug enables debugging for NGINX by using
84+
the nginx-debug binary.
85+
type: boolean
8286
image:
8387
description: Image is the NGINX image to use.
8488
properties:

deploy/crds.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,10 @@ spec:
664664
description: Container defines container fields for the NGINX
665665
container.
666666
properties:
667+
debug:
668+
description: Debug enables debugging for NGINX by using
669+
the nginx-debug binary.
670+
type: boolean
667671
image:
668672
description: Image is the NGINX image to use.
669673
properties:

internal/mode/static/provisioner/objects.go

+5
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
447447
}
448448
container.Lifecycle = containerSpec.Lifecycle
449449
container.VolumeMounts = append(container.VolumeMounts, containerSpec.VolumeMounts...)
450+
451+
if containerSpec.Debug != nil && *containerSpec.Debug {
452+
container.Command = append(container.Command, "/agent/entrypoint.sh")
453+
container.Args = append(container.Args, "debug")
454+
}
450455
spec.Spec.Containers[0] = container
451456
}
452457
}

internal/mode/static/state/graph/nginxproxy_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestBuildEffectiveNginxProxy(t *testing.T) {
5555
logLevel ngfAPIv1alpha2.NginxErrorLogLevel,
5656
setIP bool,
5757
disableHTTP bool,
58+
nginxDebug bool,
5859
) *ngfAPIv1alpha2.NginxProxy {
5960
return &ngfAPIv1alpha2.NginxProxy{
6061
Spec: ngfAPIv1alpha2.NginxProxySpec{
@@ -79,6 +80,13 @@ func TestBuildEffectiveNginxProxy(t *testing.T) {
7980
ErrorLevel: &logLevel,
8081
},
8182
DisableHTTP2: &disableHTTP,
83+
Kubernetes: &ngfAPIv1alpha2.KubernetesSpec{
84+
Deployment: &ngfAPIv1alpha2.DeploymentSpec{
85+
Container: ngfAPIv1alpha2.ContainerSpec{
86+
Debug: &nginxDebug,
87+
},
88+
},
89+
},
8290
},
8391
}
8492
}
@@ -100,6 +108,7 @@ func TestBuildEffectiveNginxProxy(t *testing.T) {
100108
ngfAPIv1alpha2.NginxLogLevelAlert,
101109
true,
102110
false,
111+
false,
103112
)
104113
}
105114

@@ -120,6 +129,7 @@ func TestBuildEffectiveNginxProxy(t *testing.T) {
120129
ngfAPIv1alpha2.NginxLogLevelError,
121130
false,
122131
true,
132+
true,
123133
)
124134
}
125135

0 commit comments

Comments
 (0)