Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 3c01893

Browse files
committed
PR feedback
* Make ingressLink and externalService mutually exclusive * Add missing docs. * Add service type. * Make ingressLink depend on reportIngressStatus
1 parent fbfccc1 commit 3c01893

File tree

8 files changed

+107
-41
lines changed

8 files changed

+107
-41
lines changed

deploy/crds/k8s.nginx.org_nginxingresscontrollers_crd.yaml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ spec:
6969
nullable: true
7070
type: boolean
7171
enableLeaderElection:
72-
description: 'Specifies the name of the IngressLink resource, which
73-
exposes the Ingress Controller pods via a BIG-IP system. The IP of
74-
the BIG-IP system is used when reporting the status of Ingress, VirtualServer
75-
and VirtualServerRoute resources. For Ingress resources only: Requires
76-
-report-ingress-status.'
72+
description: Enables Leader election to avoid multiple replicas of the
73+
controller reporting the status of Ingress resources – only one replica
74+
will report status.
7775
type: boolean
7876
enablePreviewPolicies:
7977
description: Enables preview policies. Requires enableCRDs set to true.
@@ -86,11 +84,6 @@ spec:
8684
description: Enable TLS Passthrough on port 443. Requires enableCRDs
8785
set to true.
8886
type: boolean
89-
extraLabels:
90-
additionalProperties:
91-
type: string
92-
description: Specifies extra labels of the service.
93-
type: object
9487
globalConfiguration:
9588
description: The GlobalConfiguration resource for global configuration
9689
of the Ingress Controller. Format is namespace/name. Requires enableCRDs
@@ -140,11 +133,6 @@ spec:
140133
that annotation, which can be disabled by setting UseIngressClassOnly
141134
to true. Default is `nginx`.
142135
type: string
143-
ingressLink:
144-
description: Enables Leader election to avoid multiple replicas of the
145-
controller reporting the status of Ingress resources – only one replica
146-
will report status.
147-
type: string
148136
logLevel:
149137
description: Log level for V logs. Format is 0 - 3
150138
maximum: 3
@@ -222,9 +210,25 @@ spec:
222210
status of Ingress resources. Note: Only if ServiceType is different
223211
than LoadBalancer.'
224212
type: string
213+
ingressLink:
214+
description: Specifies the name of the IngressLink resource, which
215+
exposes the Ingress Controller pods via a BIG-IP system. The IP
216+
of the BIG-IP system is used when reporting the status of Ingress,
217+
VirtualServer and VirtualServerRoute resources. For Ingress resources
218+
only. Requires reportIngressStatus.Enable set to true.
219+
type: string
225220
required:
226221
- enable
227222
type: object
223+
service:
224+
description: The service of the Ingress controller.
225+
properties:
226+
extraLabels:
227+
additionalProperties:
228+
type: string
229+
description: Specifies extra labels of the service.
230+
type: object
231+
type: object
228232
serviceType:
229233
description: 'The type of the Service for the Ingress Controller. Valid
230234
Service types are: NodePort and LoadBalancer.'

docs/nginx-ingress-controller.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ spec:
6161
reportIngressStatus:
6262
enable: true
6363
externalService: my-nginx-ingress
64+
ingressLink: my-ingresslink
6465
prometheus:
6566
enable: true
6667
port: 9114
@@ -85,6 +86,7 @@ spec:
8586
| `enableCRDs` | `boolean` | Enables the use of NGINX Ingress Resource Definitions (VirtualServer and VirtualServerRoute). | No |
8687
| `enableSnippets` | `boolean` | Enable custom NGINX configuration snippets in VirtualServer and VirtualServerRoute resources. Requires enableCRDs set to true. | No |
8788
| `ingressClass` | `string` | A class of the Ingress controller. For Kubernetes >= 1.18, the Ingress controller only processes resources that belong to its class - i.e. have the "ingressClassName" field resource equal to the class. Additionally the Ingress Controller processes all the VirtualServer/VirtualServerRoute resources that do not have the "ingressClassName" field. For Kubernetes < 1.18, the Ingress Controller only processes resources that belong to its class - i.e have the annotation "kubernetes.io/ingress.class" (for Ingress resources) or field "ingressClassName" (for VirtualServer/VirtualServerRoute resources) equal to the class. Additionally, the Ingress Controller processes resources that do not have the class set, which can be disabled by setting `useIngressClassOnly` to `true`. Default is `nginx`. | No |
89+
| `service` | [service](#nginxingresscontrollerservice) | The service of the Ingress Controller. | No |
8890
| `useIngressClassOnly` | `boolean` | Ignore Ingress resources without the `"kubernetes.io/ingress.class"` annotation. For kubernetes versions >= 1.18 this flag will be IGNORED. | No |
8991
| `watchNamespace` | `boolean` | Namespace to watch for Ingress resources. By default the Ingress controller watches all namespaces. | No |
9092
| `healthStatus` | [healthStatus](#nginxingresscontrollerhealthstatus) | Adds a new location to the default server. The location responds with the 200 status code for any request. Useful for external health-checking of the Ingress Controller. | No |
@@ -124,12 +126,19 @@ spec:
124126
| `port` | `int` | Set the port where the NGINX stub_status or the NGINX Plus API is exposed. Default is `8080`. Format is `1023 - 65535` | No |
125127
| `allowCidrs` | `string` | Whitelist IPv4 IP/CIDR blocks to allow access to NGINX stub_status or the NGINX Plus API. Separate multiple IP/CIDR by commas. (default `127.0.0.1`) | No |
126128

129+
## NginxIngressController.Service
130+
131+
| Field | Type | Description | Required |
132+
| --- | --- | --- | --- |
133+
| `extraLabels` | `map[string]string` | Specifies extra labels of the service. | No |
134+
127135
## NginxIngressController.ReportIngressStatus
128136

129137
| Field | Type | Description | Required |
130138
| --- | --- | --- | --- |
131139
| `enable` | `boolean` | Enable reporting of the Ingress status. | Yes |
132140
| `externalService` | `string` | Specifies the name of the service with the type LoadBalancer through which the Ingress controller pods are exposed externally. The external address of the service is used when reporting the status of Ingress resources. Note: Only if ServiceType is different than LoadBalancer. | No |
141+
| `ingressLink` | `string` | Specifies the name of the IngressLink resource, which exposes the Ingress Controller pods via a BIG-IP system. The IP of the BIG-IP system is used when reporting the status of Ingress, VirtualServer and VirtualServerRoute resources. For Ingress resources only. Requires `reportIngressStatus.enable` set to `true`. | No |
133142

134143
## NginxIngressController.Prometheus
135144

pkg/apis/k8s/v1alpha1/nginxingresscontroller_types.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ type NginxIngressControllerSpec struct {
5353
// +kubebuilder:validation:Optional
5454
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
5555
IngressClass string `json:"ingressClass"`
56-
// Specifies extra labels of the service.
56+
// The service of the Ingress controller.
5757
// +kubebuilder:validation:Optional
5858
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
59-
ExtraLabels map[string]string `json:"extraLabels,omitempty"`
59+
Service *Service `json:"service"`
6060
// Ignore Ingress resources without the “kubernetes.io/ingress.class” annotation.
6161
// +kubebuilder:validation:Optional
6262
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
@@ -96,12 +96,6 @@ type NginxIngressControllerSpec struct {
9696
// – only one replica will report status.
9797
// +kubebuilder:validation:Optional
9898
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
99-
IngressLink string `json:"ingressLink,omitempty"`
100-
// Specifies the name of the IngressLink resource, which exposes the Ingress Controller pods via a BIG-IP system.
101-
// The IP of the BIG-IP system is used when reporting the status of Ingress, VirtualServer and VirtualServerRoute resources.
102-
// For Ingress resources only: Requires -report-ingress-status.
103-
// +kubebuilder:validation:Optional
104-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
10599
EnableLeaderElection bool `json:"enableLeaderElection"`
106100
// A Secret with a TLS certificate and key for TLS termination of every Ingress host for which TLS termination is enabled but the Secret is not specified.
107101
// The secret must be of the type kubernetes.io/tls.
@@ -198,6 +192,12 @@ type ReportIngressStatus struct {
198192
// Note: Only if ServiceType is different than LoadBalancer.
199193
// +kubebuilder:validation:Optional
200194
ExternalService string `json:"externalService"`
195+
// Specifies the name of the IngressLink resource, which exposes the Ingress Controller pods via a BIG-IP system.
196+
// The IP of the BIG-IP system is used when reporting the status of Ingress, VirtualServer and VirtualServerRoute resources.
197+
// For Ingress resources only. Requires reportIngressStatus.Enable set to true.
198+
// +kubebuilder:validation:Optional
199+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
200+
IngressLink string `json:"ingressLink,omitempty"`
201201
}
202202

203203
// Prometheus defines the Prometheus metrics for the Ingress Controller.
@@ -213,12 +213,19 @@ type Prometheus struct {
213213
Port *uint16 `json:"port"`
214214
}
215215

216-
// App Protect support configuration.
216+
// AppProtect support configuration.
217217
type AppProtect struct {
218218
// Enable App Protect.
219219
Enable bool `json:"enable"`
220220
}
221221

222+
// Service defines the Service for the Ingress Controller.
223+
type Service struct {
224+
// Specifies extra labels of the service.
225+
// +kubebuilder:validation:Optional
226+
ExtraLabels map[string]string `json:"extraLabels,omitempty"`
227+
}
228+
222229
// NginxIngressControllerStatus defines the observed state of NginxIngressController
223230
type NginxIngressControllerStatus struct {
224231
// Deployed is true if the Operator has finished the deployment of the NginxIngressController.

pkg/apis/k8s/v1alpha1/zz_generated.deepcopy.go

Lines changed: 27 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/nginxingresscontroller/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func serviceForNginxIngressController(instance *k8sv1alpha1.NginxIngressControll
1212
ObjectMeta: v1.ObjectMeta{
1313
Name: instance.Name,
1414
Namespace: instance.Namespace,
15-
Labels: instance.Spec.ExtraLabels,
15+
Labels: instance.Spec.Service.ExtraLabels,
1616
},
1717
Spec: corev1.ServiceSpec{
1818
Ports: []corev1.ServicePort{

pkg/controller/nginxingresscontroller/service_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ func TestServiceForNginxIngressController(t *testing.T) {
2424
},
2525
Spec: k8sv1alpha1.NginxIngressControllerSpec{
2626
ServiceType: serviceType,
27-
ExtraLabels: extraLabels,
27+
Service: &k8sv1alpha1.Service{
28+
ExtraLabels: extraLabels,
29+
},
2830
},
2931
}
3032
expected := &corev1.Service{

pkg/controller/nginxingresscontroller/utils.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ func generatePodArgs(instance *k8sv1alpha1.NginxIngressController) []string {
9090
args = append(args, fmt.Sprintf("-external-service=%v", instance.Spec.ReportIngressStatus.ExternalService))
9191
} else if instance.Spec.ServiceType == "LoadBalancer" {
9292
args = append(args, fmt.Sprintf("-external-service=%v", instance.Name))
93-
}
94-
95-
if instance.Spec.IngressLink != "" {
96-
args = append(args, fmt.Sprintf("-ingresslink=%v", instance.Spec.IngressLink))
93+
} else if instance.Spec.ReportIngressStatus.IngressLink != "" {
94+
args = append(args, fmt.Sprintf("-ingresslink=%v", instance.Spec.ReportIngressStatus.IngressLink))
9795
}
9896
}
9997

pkg/controller/nginxingresscontroller/utils_test.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,35 @@ func TestGeneratePodArgs(t *testing.T) {
111111
Namespace: namespace,
112112
},
113113
Spec: k8sv1alpha1.NginxIngressControllerSpec{
114-
DefaultSecret: "my-nginx-ingress/my-secret",
115-
ServiceType: "LoadBalancer",
116-
ReportIngressStatus: &k8sv1alpha1.ReportIngressStatus{Enable: true},
114+
DefaultSecret: "my-nginx-ingress/my-secret",
115+
ServiceType: "NodePort",
116+
ReportIngressStatus: &k8sv1alpha1.ReportIngressStatus{
117+
Enable: true,
118+
IngressLink: "my-ingresslink",
119+
},
120+
},
121+
},
122+
expected: []string{
123+
"-nginx-configmaps=my-nginx-ingress/my-nginx-ingress",
124+
"-default-server-tls-secret=my-nginx-ingress/my-secret",
125+
"-enable-custom-resources=false",
126+
"-report-ingress-status",
127+
"-ingresslink=my-ingresslink",
128+
},
129+
},
130+
{
131+
instance: &k8sv1alpha1.NginxIngressController{
132+
ObjectMeta: metav1.ObjectMeta{
133+
Name: name,
134+
Namespace: namespace,
135+
},
136+
Spec: k8sv1alpha1.NginxIngressControllerSpec{
137+
DefaultSecret: "my-nginx-ingress/my-secret",
138+
ServiceType: "LoadBalancer",
139+
ReportIngressStatus: &k8sv1alpha1.ReportIngressStatus{
140+
Enable: true,
141+
IngressLink: "my-invalid-ingresslink",
142+
},
117143
},
118144
},
119145
expected: []string{
@@ -173,8 +199,8 @@ func TestGeneratePodArgs(t *testing.T) {
173199
ReportIngressStatus: &k8sv1alpha1.ReportIngressStatus{
174200
Enable: true,
175201
ExternalService: "external",
202+
IngressLink: "my-invalid-ingressLink",
176203
},
177-
IngressLink: "my-ingresslink",
178204
EnableLeaderElection: true,
179205
WildcardTLS: "my-nginx-ingress/wildcard-secret",
180206
Prometheus: &k8sv1alpha1.Prometheus{
@@ -211,7 +237,6 @@ func TestGeneratePodArgs(t *testing.T) {
211237
"-nginx-status-allow-cidrs=127.0.0.1",
212238
"-report-ingress-status",
213239
"-external-service=external",
214-
"-ingresslink=my-ingresslink",
215240
"-enable-leader-election",
216241
"-wildcard-tls-secret=my-nginx-ingress/wildcard-secret",
217242
"-enable-prometheus-metrics",

0 commit comments

Comments
 (0)