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

Commit edd932b

Browse files
committed
Add enablePreviewPolicies cli arg
1 parent f48ed63 commit edd932b

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

deploy/crds/k8s.nginx.org_nginxingresscontrollers_crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ spec:
7373
controller reporting the status of Ingress resources – only one replica
7474
will report status.
7575
type: boolean
76+
enablePreviewPolicies:
77+
description: Enables preview policies. Requires enableCRDs set to true.
78+
type: boolean
7679
enableSnippets:
7780
description: Enable custom NGINX configuration snippets in VirtualServer
7881
and VirtualServerRoute resources. Requires enableCRDs set to true.

pkg/apis/k8s/v1alpha1/nginxingresscontroller_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ type NginxIngressControllerSpec struct {
4040
// +kubebuilder:validation:Optional
4141
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
4242
EnableSnippets bool `json:"enableSnippets"`
43+
// Enables preview policies.
44+
// Requires enableCRDs set to true.
45+
// +kubebuilder:validation:Optional
46+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
47+
EnablePreviewPolicies bool `json:"enablePreviewPolicies"`
4348
// +kubebuilder:validation:Optional
4449
// A class of the Ingress controller. The Ingress controller only processes Ingress resources that belong to its
4550
// class (in other words, have the annotation “kubernetes.io/ingress.class”).

pkg/controller/nginxingresscontroller/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ func generatePodArgs(instance *k8sv1alpha1.NginxIngressController) []string {
125125
if instance.Spec.EnableSnippets {
126126
args = append(args, "-enable-snippets")
127127
}
128+
129+
if instance.Spec.EnablePreviewPolicies {
130+
args = append(args, "-enable-preview-policies")
131+
}
128132
}
129133

130134
if instance.Spec.NginxReloadTimeout != 0 {

pkg/controller/nginxingresscontroller/utils_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"reflect"
66
"testing"
77

8+
"github.com/google/go-cmp/cmp"
89
k8sv1alpha1 "github.com/nginxinc/nginx-ingress-operator/pkg/apis/k8s/v1alpha1"
910
corev1 "k8s.io/api/core/v1"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -130,10 +131,11 @@ func TestGeneratePodArgs(t *testing.T) {
130131
Namespace: namespace,
131132
},
132133
Spec: k8sv1alpha1.NginxIngressControllerSpec{
133-
EnableCRDs: true,
134-
EnableSnippets: true,
135-
EnableTLSPassthrough: true,
136-
GlobalConfiguration: "my-nginx-ingress/globalconfiguration",
134+
EnableCRDs: true,
135+
EnableSnippets: true,
136+
EnablePreviewPolicies: true,
137+
EnableTLSPassthrough: true,
138+
GlobalConfiguration: "my-nginx-ingress/globalconfiguration",
137139
},
138140
},
139141
expected: []string{
@@ -142,6 +144,7 @@ func TestGeneratePodArgs(t *testing.T) {
142144
"-enable-tls-passthrough",
143145
"-global-configuration=my-nginx-ingress/globalconfiguration",
144146
"-enable-snippets",
147+
"-enable-preview-policies",
145148
},
146149
},
147150
{
@@ -153,7 +156,6 @@ func TestGeneratePodArgs(t *testing.T) {
153156
Spec: k8sv1alpha1.NginxIngressControllerSpec{
154157
NginxPlus: true,
155158
DefaultSecret: "my-nginx-ingress/my-secret",
156-
EnableCRDs: false,
157159
IngressClass: "ingressClass",
158160
UseIngressClassOnly: true,
159161
WatchNamespace: "default",
@@ -180,12 +182,14 @@ func TestGeneratePodArgs(t *testing.T) {
180182
},
181183
EnableLatencyMetrics: true,
182184
GlobalConfiguration: "my-nginx-ingress/globalconfiguration",
183-
EnableSnippets: true,
184185
EnableTLSPassthrough: true,
185186
AppProtect: &k8sv1alpha1.AppProtect{
186187
Enable: true,
187188
},
188-
NginxReloadTimeout: 5000,
189+
NginxReloadTimeout: 5000,
190+
EnableCRDs: false,
191+
EnableSnippets: true,
192+
EnablePreviewPolicies: true,
189193
},
190194
},
191195
expected: []string{
@@ -218,8 +222,8 @@ func TestGeneratePodArgs(t *testing.T) {
218222

219223
for _, test := range tests {
220224
result := generatePodArgs(test.instance)
221-
if !reflect.DeepEqual(result, test.expected) {
222-
t.Errorf("generatePodArgs(%+v) returned \n %v but expected \n %v", test.instance, result, test.expected)
225+
if diff := cmp.Diff(test.expected, result); diff != "" {
226+
t.Errorf("generatePodArgs(%+v) mismatch (-want +got):\n%s", test.instance, diff)
223227
}
224228
}
225229
}

0 commit comments

Comments
 (0)