Skip to content

Commit 8317ade

Browse files
committed
hostPort crds
1 parent bbf9a67 commit 8317ade

File tree

6 files changed

+72
-93
lines changed

6 files changed

+72
-93
lines changed

apis/v1alpha2/nginxproxy_types.go

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -383,33 +383,15 @@ type KubernetesSpec struct {
383383

384384
// Deployment is the configuration for the NGINX Deployment.
385385
type DeploymentSpec struct {
386-
// Number of desired Pods.
387-
//
388-
// +optional
389-
Replicas *int32 `json:"replicas,omitempty"`
390-
391-
// Pod defines Pod-specific fields.
392-
//
393-
// +optional
394-
Pod PodSpec `json:"pod"`
395-
396-
// Container defines container fields for the NGINX container.
397-
//
398-
// +optional
399386
Container ContainerSpec `json:"container"`
387+
Replicas *int32 `json:"replicas,omitempty"`
388+
Pod PodSpec `json:"pod"`
400389
}
401390

402391
// DaemonSet is the configuration for the NGINX DaemonSet.
403392
type DaemonSetSpec struct {
404-
// Pod defines Pod-specific fields.
405-
//
406-
// +optional
407-
Pod PodSpec `json:"pod"`
408-
409-
// Container defines container fields for the NGINX container.
410-
//
411-
// +optional
412393
Container ContainerSpec `json:"container"`
394+
Pod PodSpec `json:"pod"`
413395
}
414396

415397
// PodSpec defines Pod-specific fields.
@@ -457,32 +439,12 @@ type PodSpec struct {
457439

458440
// ContainerSpec defines container fields for the NGINX container.
459441
type ContainerSpec struct {
460-
// Debug enables debugging for NGINX by using the nginx-debug binary.
461-
//
462-
// +optional
463-
Debug *bool `json:"debug,omitempty"`
464-
465-
// Image is the NGINX image to use.
466-
//
467-
// +optional
468-
Image *Image `json:"image,omitempty"`
469-
470-
// Resources describes the compute resource requirements.
471-
//
472-
// +optional
473-
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
474-
475-
// Lifecycle describes actions that the management system should take in response to container lifecycle
476-
// events. For the PostStart and PreStop lifecycle handlers, management of the container blocks
477-
// until the action is complete, unless the container process fails, in which case the handler is aborted.
478-
//
479-
// +optional
480-
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
481-
482-
// VolumeMounts describe the mounting of Volumes within a container.
483-
//
484-
// +optional
485-
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
442+
Debug *bool `json:"debug,omitempty"`
443+
Image *Image `json:"image,omitempty"`
444+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
445+
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
446+
HostPort *HostPort `json:"hostPort,omitempty"`
447+
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
486448
}
487449

488450
// Image is the NGINX image to use.
@@ -608,3 +570,15 @@ type NodePort struct {
608570
// kubebuilder:validation:Maximum=65535
609571
ListenerPort int32 `json:"listenerPort"`
610572
}
573+
574+
type HostPort struct {
575+
// Whether to enable hostPort feature
576+
// If not specified, or set to false, hostPort will not be enabled.
577+
// +optional
578+
Enable bool `json:"enable,omitempty"`
579+
580+
// Number of port to expose on the host.
581+
// kubebuilder:validation:Minimum=1
582+
// kubebuilder:validation:Maximum=65535
583+
Port int32 `json:"port"`
584+
}

charts/nginx-gateway-fabric/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,13 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
259259
| `certGenerator.serverTLSSecretName` | The name of the Secret containing TLS CA, certificate, and key for the NGINX Gateway Fabric control plane to securely communicate with the NGINX Agent. Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in (default namespace: nginx-gateway). | string | `"server-tls"` |
260260
| `clusterDomain` | The DNS cluster domain of your Kubernetes cluster. | string | `"cluster.local"` |
261261
| `gateways` | A list of Gateway objects. View https://gateway-api.sigs.k8s.io/reference/spec/#gateway for full Gateway reference. | list | `[]` |
262-
| `nginx` | The nginx section contains the configuration for all NGINX data plane deployments installed by the NGINX Gateway Fabric control plane. | object | `{"config":{},"container":{},"debug":false,"hostPort":{"enable":false,"port":443},"image":{"pullPolicy":"Always","repository":"ghcr.io/nginx/nginx-gateway-fabric/nginx","tag":"edge"},"imagePullSecret":"","imagePullSecrets":[],"kind":"deployment","plus":false,"pod":{},"replicas":1,"service":{"externalTrafficPolicy":"Local","loadBalancerClass":"","loadBalancerIP":"","loadBalancerSourceRanges":[],"nodePorts":[],"type":"LoadBalancer"},"usage":{"caSecretName":"","clientSSLSecretName":"","endpoint":"","resolver":"","secretName":"nplus-license","skipVerify":false}}` |
262+
| `nginx` | The nginx section contains the configuration for all NGINX data plane deployments installed by the NGINX Gateway Fabric control plane. | object | `{"config":{},"container":{"hostPort":{"enable":false,"port":443}},"debug":false,"image":{"pullPolicy":"Always","repository":"ghcr.io/nginx/nginx-gateway-fabric/nginx","tag":"edge"},"imagePullSecret":"","imagePullSecrets":[],"kind":"deployment","plus":false,"pod":{},"replicas":1,"service":{"externalTrafficPolicy":"Local","loadBalancerClass":"","loadBalancerIP":"","loadBalancerSourceRanges":[],"nodePorts":[],"type":"LoadBalancer"},"usage":{"caSecretName":"","clientSSLSecretName":"","endpoint":"","resolver":"","secretName":"nplus-license","skipVerify":false}}` |
263263
| `nginx.config` | The configuration for the data plane that is contained in the NginxProxy resource. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{}` |
264-
| `nginx.container` | The container configuration for the NGINX container. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{}` |
264+
| `nginx.container` | The container configuration for the NGINX container. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{"hostPort":{"enable":false,"port":443}}` |
265+
| `nginx.container.hostPort` | The hostPort configuration | object | `{"enable":false,"port":443}` |
266+
| `nginx.container.hostPort.enable` | Enables hostPort. | bool | `false` |
267+
| `nginx.container.hostPort.port` | The port | int | `443` |
265268
| `nginx.debug` | Enable debugging for NGINX. Uses the nginx-debug binary. The NGINX error log level should be set to debug in the NginxProxy resource. | bool | `false` |
266-
| `nginx.hostPort` | The hostPort configuration | object | `{"enable":false,"port":443}` |
267-
| `nginx.hostPort.enable` | Enables hostPort. | bool | `false` |
268-
| `nginx.hostPort.port` | The port | int | `443` |
269269
| `nginx.image.repository` | The NGINX image to use. | string | `"ghcr.io/nginx/nginx-gateway-fabric/nginx"` |
270270
| `nginx.imagePullSecret` | The name of the secret containing docker registry credentials. Secret must exist in the same namespace as the helm release. The control plane will copy this secret into any namespace where NGINX is deployed. | string | `""` |
271271
| `nginx.imagePullSecrets` | A list of secret names containing docker registry credentials. Secrets must exist in the same namespace as the helm release. The control plane will copy these secrets into any namespace where NGINX is deployed. | list | `[]` |

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ spec:
135135
ports:
136136
- name: agent-grpc
137137
containerPort: 8443
138-
{{- if .Values.nginx.hostPort.enable }}
139-
hostPort: {{ .Values.nginx.hostPort.port }}
140-
{{- end }}
141138
{{- if .Values.nginxGateway.metrics.enable }}
142139
- name: metrics
143140
containerPort: {{ .Values.nginxGateway.metrics.port }}

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,32 @@
276276
},
277277
"container": {
278278
"description": "The container configuration for the NGINX container. This is applied globally to all Gateways managed by this\ninstance of NGINX Gateway Fabric.",
279+
"properties": {
280+
"hostPort": {
281+
"description": "The hostPort configuration",
282+
"properties": {
283+
"enable": {
284+
"default": false,
285+
"description": "Enables hostPort.",
286+
"required": [],
287+
"title": "enable",
288+
"type": "boolean"
289+
},
290+
"port": {
291+
"default": 443,
292+
"description": "The port",
293+
"maximum": 65535,
294+
"minimum": 1,
295+
"required": [],
296+
"title": "port",
297+
"type": "integer"
298+
}
299+
},
300+
"required": [],
301+
"title": "hostPort",
302+
"type": "object"
303+
}
304+
},
279305
"required": [],
280306
"title": "container",
281307
"type": "object"
@@ -287,30 +313,6 @@
287313
"title": "debug",
288314
"type": "boolean"
289315
},
290-
"hostPort": {
291-
"description": "The hostPort configuration",
292-
"properties": {
293-
"enable": {
294-
"default": false,
295-
"description": "Enables hostPort.",
296-
"required": [],
297-
"title": "enable",
298-
"type": "boolean"
299-
},
300-
"port": {
301-
"default": 443,
302-
"description": "The port",
303-
"maximum": 65535,
304-
"minimum": 1,
305-
"required": [],
306-
"title": "port",
307-
"type": "integer"
308-
}
309-
},
310-
"required": [],
311-
"title": "hostPort",
312-
"type": "object"
313-
},
314316
"image": {
315317
"properties": {
316318
"pullPolicy": {

charts/nginx-gateway-fabric/values.yaml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,6 @@ nginx:
241241
# Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in (default namespace: nginx-gateway).
242242
clientSSLSecretName: ""
243243

244-
# -- The hostPort configuration
245-
hostPort:
246-
# -- Enables hostPort.
247-
enable: false
248-
249-
# @schema
250-
# type: integer
251-
# minimum: 1
252-
# maximum: 65535
253-
# @schema
254-
# -- The port
255-
port: 443
256-
257244
# @schema
258245
# type: object
259246
# properties:
@@ -409,7 +396,21 @@ nginx:
409396

410397
# -- The container configuration for the NGINX container. This is applied globally to all Gateways managed by this
411398
# instance of NGINX Gateway Fabric.
412-
container: {}
399+
container:
400+
401+
# -- The hostPort configuration
402+
hostPort:
403+
# -- Enables hostPort.
404+
enable: false
405+
406+
# @schema
407+
# type: integer
408+
# minimum: 1
409+
# maximum: 65535
410+
# @schema
411+
# -- The port
412+
port: 443
413+
413414
# -- The resource requirements of the NGINX container.
414415
# resources: {}
415416

internal/controller/provisioner/objects.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,11 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
766766
container.Command = append(container.Command, "/agent/entrypoint.sh")
767767
container.Args = append(container.Args, "debug")
768768
}
769+
770+
if containerSpec.HostPort != nil && containerSpec.HostPort.Enable && len(container.Ports) > 1 {
771+
container.Ports[0].HostPort = containerSpec.HostPort.Port
772+
}
773+
769774
spec.Spec.Containers[0] = container
770775
}
771776
}

0 commit comments

Comments
 (0)