Skip to content

Commit 995eaa5

Browse files
committed
hostPorts list
1 parent 60fd6fd commit 995eaa5

File tree

8 files changed

+78
-64
lines changed

8 files changed

+78
-64
lines changed

apis/v1alpha2/nginxproxy_types.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,10 @@ type ContainerSpec struct {
479479
// +optional
480480
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
481481

482-
// HostPort configuration
482+
// HostPorts are the list of ports to expose on the host
483483
//
484484
// +optional
485-
HostPort *HostPort `json:"hostPort,omitempty"`
485+
HostPorts []HostPort `json:"hostPorts,omitempty"`
486486

487487
// VolumeMounts describe the mounting of Volumes within a container.
488488
//
@@ -616,14 +616,13 @@ type NodePort struct {
616616

617617
// HostPort to expose on the host.
618618
type HostPort struct {
619-
// Whether to enable hostPort feature
620-
// If not specified, or set to false, hostPort will not be enabled.
621-
//
622-
// +optional
623-
Enable bool `json:"enable"`
619+
// ContainerPort is nginx port.
620+
// kubebuilder:validation:Minimum=1
621+
// kubebuilder:validation:Maximum=65535
622+
ContainerPort int32 `json:"containerPort"`
624623

625624
// Number of port to expose on the host.
626625
// kubebuilder:validation:Minimum=1
627626
// kubebuilder:validation:Maximum=65535
628-
Port int32 `json:"port"`
627+
HostPort int32 `json:"hostPort"`
629628
}

charts/nginx-gateway-fabric/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,10 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
264264
| `certGenerator.ttlSecondsAfterFinished` | How long to wait after the cert generator job has finished before it is removed by the job controller. | int | `30` |
265265
| `clusterDomain` | The DNS cluster domain of your Kubernetes cluster. | string | `"cluster.local"` |
266266
| `gateways` | A list of Gateway objects. View https://gateway-api.sigs.k8s.io/reference/spec/#gateway for full Gateway reference. | list | `[]` |
267-
| `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}}` |
267+
| `nginx` | The nginx section contains the configuration for all NGINX data plane deployments installed by the NGINX Gateway Fabric control plane. | object | `{"config":{},"container":{"hostPorts":[]},"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}}` |
268268
| `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 | `{}` |
269-
| `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}}` |
270-
| `nginx.container.hostPort` | The hostPort configuration | object | `{"enable":false,"port":443}` |
271-
| `nginx.container.hostPort.enable` | Enables hostPort. | bool | `false` |
272-
| `nginx.container.hostPort.port` | The port | int | `443` |
269+
| `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 | `{"hostPorts":[]}` |
270+
| `nginx.container.hostPorts` | The hostPort configuration | list | `[]` |
273271
| `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` |
274272
| `nginx.image.repository` | The NGINX image to use. | string | `"ghcr.io/nginx/nginx-gateway-fabric/nginx"` |
275273
| `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 | `""` |

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -314,29 +314,29 @@
314314
"container": {
315315
"description": "The container configuration for the NGINX container. This is applied globally to all Gateways managed by this\ninstance of NGINX Gateway Fabric.",
316316
"properties": {
317-
"hostPort": {
317+
"hostPorts": {
318318
"description": "The hostPort configuration",
319-
"properties": {
320-
"enable": {
321-
"default": false,
322-
"description": "Enables hostPort.",
323-
"required": [],
324-
"title": "enable",
325-
"type": "boolean"
319+
"items": {
320+
"properties": {
321+
"containerPort": {
322+
"maximum": 65535,
323+
"minimum": 1,
324+
"required": [],
325+
"type": "integer"
326+
},
327+
"hostPort": {
328+
"maximum": 65535,
329+
"minimum": 1,
330+
"required": [],
331+
"type": "integer"
332+
}
326333
},
327-
"port": {
328-
"default": 443,
329-
"description": "The port",
330-
"maximum": 65535,
331-
"minimum": 1,
332-
"required": [],
333-
"title": "port",
334-
"type": "integer"
335-
}
334+
"required": [],
335+
"type": "object"
336336
},
337337
"required": [],
338-
"title": "hostPort",
339-
"type": "object"
338+
"title": "hostPorts",
339+
"type": "array"
340340
}
341341
},
342342
"required": [],

charts/nginx-gateway-fabric/values.yaml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,26 @@ nginx:
398398
# instance of NGINX Gateway Fabric.
399399
container:
400400

401+
# @schema
402+
# type: array
403+
# items:
404+
# type: object
405+
# properties:
406+
# containerPort:
407+
# type: integer
408+
# required: true
409+
# minimum: 1
410+
# maximum: 65535
411+
# hostPort:
412+
# type: integer
413+
# required: true
414+
# minimum: 1
415+
# maximum: 65535
416+
# @schema
401417
# -- 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
418+
hostPorts: []
419+
# - containerPort: 80
420+
# hostPort: 80
413421

414422
# -- The resource requirements of the NGINX container.
415423
# resources: {}

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,22 @@ spec:
337337
StopSignal can only be set for Pods with a non-empty .spec.os.name
338338
type: string
339339
type: object
340-
hostPort:
340+
hostPorts:
341341
description: |-
342-
Number of port to expose on the host.
343-
If specified, this must be a valid port number, 0 < x < 65536.
344-
properties:
345-
enable:
342+
List of ports to expose on the host.
343+
items:
344+
containerPort:
346345
description: |-
347-
Whether to enable hostPort
348-
type: boolean
349-
port:
346+
ContainerPort number of nginx
347+
type: integer
348+
hostPort:
350349
description: |-
351-
Port number
350+
HostPort number to expose on the host
352351
type: integer
352+
required:
353+
- containerPort
354+
- hostPort
355+
type: array
353356
resources:
354357
description: Resources describes the compute resource
355358
requirements.

deploy/crds.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -924,17 +924,20 @@ spec:
924924
type: object
925925
hostPort:
926926
description: |-
927-
Number of port to expose on the host.
928-
If specified, this must be a valid port number, 0 < x < 65536.
929-
properties:
930-
enable:
927+
List of ports to expose on the host.
928+
items:
929+
containerPort:
931930
description: |-
932-
Whether to enable hostPort
933-
type: boolean
934-
port:
931+
ContainerPort number of nginx
932+
type: integer
933+
hostPort:
935934
description: |-
936-
Port number
935+
HostPort number to expose on the host
937936
type: integer
937+
required:
938+
- containerPort
939+
- hostPort
940+
type: array
938941
resources:
939942
description: Resources describes the compute resource
940943
requirements.

internal/controller/provisioner/objects.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,12 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
781781
container.Args = append(container.Args, "debug")
782782
}
783783

784-
if containerSpec.HostPort != nil && containerSpec.HostPort.Enable && len(container.Ports) > 0 {
785-
container.Ports[0].HostPort = containerSpec.HostPort.Port
784+
for _, hostPort := range containerSpec.HostPorts {
785+
for i, port := range container.Ports {
786+
if hostPort.ContainerPort == port.ContainerPort {
787+
container.Ports[i].HostPort = hostPort.HostPort
788+
}
789+
}
786790
}
787791

788792
spec.Spec.Containers[0] = container

internal/controller/provisioner/objects_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
293293
corev1.ResourceCPU: resource.Quantity{Format: "100m"},
294294
},
295295
},
296-
HostPort: &ngfAPIv1alpha2.HostPort{Enable: true, Port: int32(8443)},
296+
HostPorts: []ngfAPIv1alpha2.HostPort{{ContainerPort: int32(8443), HostPort: int32(8443)}},
297297
},
298298
},
299299
},
@@ -339,7 +339,6 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
339339
g.Expect(container.Ports).To(ContainElement(corev1.ContainerPort{
340340
ContainerPort: 8080,
341341
Name: "metrics",
342-
HostPort: int32(8443),
343342
}))
344343

345344
g.Expect(container.Image).To(Equal("nginx-repo:1.1.1"))

0 commit comments

Comments
 (0)