Skip to content

CP/DP split: Support nginx debug mode when provisioning Data Plane #3147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apis/v1alpha2/nginxproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ type PodSpec struct {

// ContainerSpec defines container fields for the NGINX container.
type ContainerSpec struct {
// Debug enables debugging for NGINX by using the nginx-debug binary.
//
// +optional
// +kubebuilder:default=false
Debug *bool `json:"debug,omitempty"`

// Image is the NGINX image to use.
//
// +optional
Expand Down
5 changes: 5 additions & 0 deletions apis/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions charts/nginx-gateway-fabric/templates/nginxproxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
{{- end }}
image:
{{- toYaml .Values.nginx.image | nindent 10 }}
debug: {{ .Values.nginx.debug }}
{{- end }}
{{- if .Values.nginx.service }}
service:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/gateway.nginx.org_nginxproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ spec:
description: Container defines container fields for the NGINX
container.
properties:
debug:
default: false
description: Debug enables debugging for NGINX by using
the nginx-debug binary.
type: boolean
image:
description: Image is the NGINX image to use.
properties:
Expand Down
1 change: 1 addition & 0 deletions deploy/aws-nlb/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
Expand Down
1 change: 1 addition & 0 deletions deploy/azure/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
Expand Down
5 changes: 5 additions & 0 deletions deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,11 @@ spec:
description: Container defines container fields for the NGINX
container.
properties:
debug:
default: false
description: Debug enables debugging for NGINX by using
the nginx-debug binary.
type: boolean
image:
description: Image is the NGINX image to use.
properties:
Expand Down
1 change: 1 addition & 0 deletions deploy/default/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
Expand Down
1 change: 1 addition & 0 deletions deploy/experimental-nginx-plus/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: private-registry.nginx.com/nginx-gateway-fabric/nginx-plus
Expand Down
1 change: 1 addition & 0 deletions deploy/experimental/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
Expand Down
1 change: 1 addition & 0 deletions deploy/nginx-plus/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: private-registry.nginx.com/nginx-gateway-fabric/nginx-plus
Expand Down
1 change: 1 addition & 0 deletions deploy/nodeport/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
Expand Down
1 change: 1 addition & 0 deletions deploy/openshift/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
Expand Down
1 change: 1 addition & 0 deletions deploy/snippets-filters-nginx-plus/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: private-registry.nginx.com/nginx-gateway-fabric/nginx-plus
Expand Down
1 change: 1 addition & 0 deletions deploy/snippets-filters/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ spec:
kubernetes:
deployment:
container:
debug: false
image:
pullPolicy: Always
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
Expand Down
5 changes: 5 additions & 0 deletions internal/mode/static/provisioner/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@
}
container.Lifecycle = containerSpec.Lifecycle
container.VolumeMounts = append(container.VolumeMounts, containerSpec.VolumeMounts...)

if containerSpec.Debug != nil && *containerSpec.Debug {
container.Command = append(container.Command, "/bin/sh")
container.Args = append(container.Args, "-c", "rm -rf /var/run/nginx/*sock && nginx-debug -g 'daemon off;'")
}

Check warning on line 454 in internal/mode/static/provisioner/objects.go

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/provisioner/objects.go#L450-L454

Added lines #L450 - L454 were not covered by tests
spec.Spec.Containers[0] = container
}
}
Expand Down
10 changes: 10 additions & 0 deletions internal/mode/static/state/graph/nginxproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestBuildEffectiveNginxProxy(t *testing.T) {
logLevel ngfAPIv1alpha2.NginxErrorLogLevel,
setIP bool,
disableHTTP bool,
nginxDebug bool,
) *ngfAPIv1alpha2.NginxProxy {
return &ngfAPIv1alpha2.NginxProxy{
Spec: ngfAPIv1alpha2.NginxProxySpec{
Expand All @@ -79,6 +80,13 @@ func TestBuildEffectiveNginxProxy(t *testing.T) {
ErrorLevel: &logLevel,
},
DisableHTTP2: &disableHTTP,
Kubernetes: &ngfAPIv1alpha2.KubernetesSpec{
Deployment: &ngfAPIv1alpha2.DeploymentSpec{
Container: ngfAPIv1alpha2.ContainerSpec{
Debug: &nginxDebug,
},
},
},
},
}
}
Expand All @@ -100,6 +108,7 @@ func TestBuildEffectiveNginxProxy(t *testing.T) {
ngfAPIv1alpha2.NginxLogLevelAlert,
true,
false,
false,
)
}

Expand All @@ -120,6 +129,7 @@ func TestBuildEffectiveNginxProxy(t *testing.T) {
ngfAPIv1alpha2.NginxLogLevelError,
false,
true,
true,
)
}

Expand Down
Loading