Skip to content

Commit 549cb1d

Browse files
committed
Review feedback
1 parent 105c349 commit 549cb1d

File tree

24 files changed

+429
-259
lines changed

24 files changed

+429
-259
lines changed

cmd/gateway/commands.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func createStaticModeCommand() *cobra.Command {
5656
leaderElectionDisableFlag = "leader-election-disable"
5757
leaderElectionLockNameFlag = "leader-election-lock-name"
5858
plusFlag = "nginx-plus"
59-
experimentalEnableFlag = "experimental-features-enable"
59+
gwAPIExperimentalFlag = "gateway-api-experimental-features"
6060
)
6161

6262
// flag values
@@ -97,7 +97,7 @@ func createStaticModeCommand() *cobra.Command {
9797

9898
plus bool
9999

100-
enableExperimental bool
100+
gwExperimentalFeatures bool
101101
)
102102

103103
cmd := &cobra.Command{
@@ -175,7 +175,7 @@ func createStaticModeCommand() *cobra.Command {
175175
Plus: plus,
176176
TelemetryReportPeriod: period,
177177
Version: version,
178-
ExperimentalFeatures: enableExperimental,
178+
ExperimentalFeatures: gwExperimentalFeatures,
179179
}
180180

181181
if err := static.StartManager(conf); err != nil {
@@ -290,8 +290,8 @@ func createStaticModeCommand() *cobra.Command {
290290
)
291291

292292
cmd.Flags().BoolVar(
293-
&enableExperimental,
294-
experimentalEnableFlag,
293+
&gwExperimentalFeatures,
294+
gwAPIExperimentalFlag,
295295
false,
296296
"Enable the experimental features of Gateway API which are supported by NGINX Gateway Fabric. "+
297297
"Requires the Gateway APIs installed from the experimental channel.",

deploy/helm-chart/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ spec:
5252
{{- else }}
5353
- --leader-election-disable
5454
{{- end }}
55-
{{- if .Values.nginxGateway.experimentalFeatures.enable }}
56-
- --experimental-features-enable
55+
{{- if .Values.nginxGateway.gwAPIExperimentalFeatures.enable }}
56+
- --gateway-api-experimental-features
5757
{{- end }}
5858
env:
5959
- name: POD_IP

deploy/helm-chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ nginxGateway:
5151
## extraVolumeMounts are the additional volume mounts for the nginx-gateway container.
5252
extraVolumeMounts: []
5353

54-
experimentalFeatures:
54+
gwAPIExperimentalFeatures:
5555
## Enable the experimental features of Gateway API which are supported by NGINX Gateway Fabric. Requires the Gateway
5656
## APIs installed from the experimental channel.
5757
enable: false

docs/developer/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ This will build the docker images `nginx-gateway-fabric:<your-user>` and `nginx-
128128
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/standard-install.yaml
129129
```
130130
131-
Alternatively, install Gateway API CRDs from the experimental channel:
131+
If you're implementing experimental Gateway API features, install Gateway API CRDs from the experimental channel:
132132

133133
```shell
134134
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/experimental-install.yaml

internal/framework/status/setters_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,12 @@ func TestBtpStatusEqual(t *testing.T) {
865865
},
866866
}
867867
}
868+
prevMultiple := getPolicyStatus("ancestor1", "ns1", "ctlr1")
869+
prevMultiple.Ancestors = append(prevMultiple.Ancestors, getPolicyStatus("ancestor2", "ns2", "ctlr2").Ancestors...)
870+
871+
currMultiple := getPolicyStatus("ancestor1", "ns1", "ctlr1")
872+
currMultiple.Ancestors = append(currMultiple.Ancestors, getPolicyStatus("ancestor3", "ns3", "ctlr2").Ancestors...)
873+
868874
tests := []struct {
869875
name string
870876
controllerName string
@@ -907,6 +913,13 @@ func TestBtpStatusEqual(t *testing.T) {
907913
controllerName: "ctlr1",
908914
expEqual: false,
909915
},
916+
{
917+
name: "status not equal, different controller ancestor changed",
918+
previous: prevMultiple,
919+
current: currMultiple,
920+
controllerName: "ctlr1",
921+
expEqual: false,
922+
},
910923
}
911924

912925
for _, test := range tests {

internal/framework/status/statuses.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type GatewayClassStatus struct {
116116
ObservedGeneration int64
117117
}
118118

119+
// AncestorStatus holds status-related information related to how the BackendTLSPolicy binds to a specific ancestorRef.
119120
type AncestorStatus struct {
120121
// GatewayNsName is the Namespaced name of the Gateway, which the ancestorRef references.
121122
GatewayNsName types.NamespacedName

internal/mode/static/build_statuses.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,7 @@ func buildBackendTLSPolicyStatuses(backendTLSPolicies map[types.NamespacedName]*
199199

200200
for nsname, backendTLSPolicy := range backendTLSPolicies {
201201
if backendTLSPolicy.IsReferenced {
202-
ignoreStatus := false
203-
if !backendTLSPolicy.Valid {
204-
for i := range backendTLSPolicy.Conditions {
205-
if backendTLSPolicy.Conditions[i].Reason == string(staticConds.BackendTLSPolicyReasonIgnored) {
206-
// We should not report the status of an ignored BackendTLSPolicy.
207-
ignoreStatus = true
208-
}
209-
}
210-
}
211-
if !ignoreStatus {
202+
if !backendTLSPolicy.Ignored {
212203
statuses[nsname] = status.BackendTLSPolicyStatus{
213204
AncestorStatuses: []status.AncestorStatus{
214205
{

internal/mode/static/build_statuses_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
619619
getBackendTLSPolicy := func(
620620
name string,
621621
valid bool,
622+
ignored bool,
622623
isReferenced bool,
623624
conditions []conditions.Condition,
624625
) *graph.BackendTLSPolicy {
@@ -631,15 +632,15 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
631632
},
632633
},
633634
Valid: valid,
635+
Ignored: ignored,
634636
IsReferenced: isReferenced,
635637
Conditions: conditions,
636638
Gateway: types.NamespacedName{Name: "gateway", Namespace: "test"},
637639
}
638640
}
639641

640-
attachedConds := []conditions.Condition{staticConds.NewBackendTLSPolicyAttached()}
642+
attachedConds := []conditions.Condition{staticConds.NewBackendTLSPolicyAccepted()}
641643
invalidConds := []conditions.Condition{staticConds.NewBackendTLSPolicyInvalid("invalid backendTLSPolicy")}
642-
ignoredConds := []conditions.Condition{staticConds.NewBackendTLSPolicyIgnored("ignored backendTLSPolicy")}
643644

644645
tests := []struct {
645646
backendTLSPolicies map[types.NamespacedName]*graph.BackendTLSPolicy
@@ -653,7 +654,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
653654
{
654655
name: "valid backendTLSPolicy",
655656
backendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{
656-
{Namespace: "test", Name: "valid-bt"}: getBackendTLSPolicy("valid-bt", true, true, attachedConds),
657+
{Namespace: "test", Name: "valid-bt"}: getBackendTLSPolicy("valid-bt", true, false, true, attachedConds),
657658
},
658659
expected: status.BackendTLSPolicyStatuses{
659660
{Namespace: "test", Name: "valid-bt"}: {
@@ -669,7 +670,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
669670
{
670671
name: "invalid backendTLSPolicy",
671672
backendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{
672-
{Namespace: "test", Name: "invalid-bt"}: getBackendTLSPolicy("invalid-bt", false, true, invalidConds),
673+
{Namespace: "test", Name: "invalid-bt"}: getBackendTLSPolicy("invalid-bt", false, false, true, invalidConds),
673674
},
674675
expected: status.BackendTLSPolicyStatuses{
675676
{Namespace: "test", Name: "invalid-bt"}: {
@@ -685,16 +686,16 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
685686
{
686687
name: "ignored or not referenced backendTLSPolicies",
687688
backendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{
688-
{Namespace: "test", Name: "ignored-bt"}: getBackendTLSPolicy("ignored-bt", false, true, ignoredConds),
689-
{Namespace: "test", Name: "not-referenced"}: getBackendTLSPolicy("not-referenced", true, false, nil),
689+
{Namespace: "test", Name: "ignored-bt"}: getBackendTLSPolicy("ignored-bt", false, true, true, nil),
690+
{Namespace: "test", Name: "not-referenced"}: getBackendTLSPolicy("not-referenced", true, false, false, nil),
690691
},
691692
expected: status.BackendTLSPolicyStatuses{},
692693
},
693694
{
694695
name: "mix valid and ignored backendTLSPolicies",
695696
backendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{
696-
{Namespace: "test", Name: "ignored-bt"}: getBackendTLSPolicy("ignored-bt", false, true, ignoredConds),
697-
{Namespace: "test", Name: "valid-bt"}: getBackendTLSPolicy("valid-bt", true, true, attachedConds),
697+
{Namespace: "test", Name: "ignored-bt"}: getBackendTLSPolicy("ignored-bt", false, true, true, nil),
698+
{Namespace: "test", Name: "valid-bt"}: getBackendTLSPolicy("valid-bt", true, false, true, attachedConds),
698699
},
699700
expected: status.BackendTLSPolicyStatuses{
700701
{Namespace: "test", Name: "valid-bt"}: {

internal/mode/static/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,13 @@ func registerControllers(
388388
backendTLSObjs := []ctlrCfg{
389389
{
390390
objectType: &gatewayv1alpha2.BackendTLSPolicy{},
391+
options: []controller.Option{
392+
controller.WithK8sPredicate(k8spredicate.GenerationChangedPredicate{}),
393+
},
391394
},
392395
{
393396
// FIXME(ciarams87): If possible, use only metadata predicate
397+
// https://github.com/nginxinc/nginx-gateway-fabric/issues/1545
394398
objectType: &apiv1.ConfigMap{},
395399
},
396400
}

internal/mode/static/nginx/config/generator.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"encoding/base64"
54
"path/filepath"
65

76
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/file"
@@ -96,15 +95,10 @@ func generatePEMFileName(id dataplane.SSLKeyPairID) string {
9695
}
9796

9897
func generateCertBundle(id dataplane.CertBundleID, cert []byte) file.File {
99-
data := make([]byte, base64.StdEncoding.DecodedLen(len(cert)))
100-
_, err := base64.StdEncoding.Decode(data, cert)
101-
if err != nil {
102-
data = cert
103-
}
10498
return file.File{
105-
Content: data,
99+
Content: cert,
106100
Path: generateCertBundleFileName(id),
107-
Type: file.TypeSecret,
101+
Type: file.TypeRegular,
108102
}
109103
}
110104

internal/mode/static/nginx/config/servers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func createProxyTLSFromBackends(backends []dataplane.Backend) *http.ProxySSLVeri
283283
}
284284

285285
func createProxySSLVerify(v *dataplane.VerifyTLS) *http.ProxySSLVerify {
286-
if v == nil || v.Hostname == "" {
286+
if v == nil {
287287
return nil
288288
}
289289
var trustedCert string

internal/mode/static/nginx/config/servers_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,10 +1869,7 @@ func TestConvertBackendTLSFromGroup(t *testing.T) {
18691869
UpstreamName: "my-upstream",
18701870
Valid: true,
18711871
Weight: 1,
1872-
VerifyTLS: &dataplane.VerifyTLS{
1873-
CertBundleID: "",
1874-
Hostname: "",
1875-
},
1872+
VerifyTLS: nil,
18761873
},
18771874
},
18781875
expected: nil,
@@ -1900,6 +1897,24 @@ func TestConvertBackendTLSFromGroup(t *testing.T) {
19001897
Name: "my-hostname",
19011898
},
19021899
},
1900+
{
1901+
msg: "tls enabled, system certs enabled",
1902+
grp: []dataplane.Backend{
1903+
{
1904+
UpstreamName: "my-upstream",
1905+
Valid: true,
1906+
Weight: 1,
1907+
VerifyTLS: &dataplane.VerifyTLS{
1908+
Hostname: "my-hostname",
1909+
RootCAPath: "/etc/ssl/certs/ca-certificates.crt",
1910+
},
1911+
},
1912+
},
1913+
expected: &http.ProxySSLVerify{
1914+
TrustedCertificate: "/etc/ssl/certs/ca-certificates.crt",
1915+
Name: "my-hostname",
1916+
},
1917+
},
19031918
}
19041919

19051920
for _, tc := range tests {

internal/mode/static/state/conditions/conditions.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
77
v1 "sigs.k8s.io/gateway-api/apis/v1"
8+
"sigs.k8s.io/gateway-api/apis/v1alpha2"
89

910
ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
1011
"github.com/nginxinc/nginx-gateway-fabric/internal/framework/conditions"
@@ -73,9 +74,6 @@ const (
7374
// BackendTLSPolicyReasonAttached is the condition reason for the BackendTLSPolicy Attached condition.
7475
BackendTLSPolicyReasonAttached BackendTLSPolicyConditionReason = "BackendTLSPolicyAttached"
7576

76-
// BackendTLSPolicyReasonIgnored is the condition reason for the BackendTLSPolicy being ignored by this Gateway.
77-
BackendTLSPolicyReasonIgnored BackendTLSPolicyConditionReason = "BackendTLSPolicyIgnored"
78-
7977
// BackendTLSPolicyConditionValid is the condition type indicating whether the BackendTLS policy is valid.
8078
BackendTLSPolicyConditionValid BackendTLSPolicyConditionType = "Valid"
8179

@@ -570,34 +568,23 @@ func NewNginxGatewayInvalid(msg string) conditions.Condition {
570568
}
571569
}
572570

573-
// NewBackendTLSPolicyAttached returns a Condition that indicates that the BackendTLSPolicy config is valid and attached
574-
// to the Gateway.
575-
func NewBackendTLSPolicyAttached() conditions.Condition {
571+
// NewBackendTLSPolicyAccepted returns a Condition that indicates that the BackendTLSPolicy config is valid and accepted
572+
// by the Gateway.
573+
func NewBackendTLSPolicyAccepted() conditions.Condition {
576574
return conditions.Condition{
577-
Type: string(BackendTLSPolicyConditionAttached),
575+
Type: string(v1alpha2.PolicyConditionAccepted),
578576
Status: metav1.ConditionTrue,
579-
Reason: string(BackendTLSPolicyReasonAttached),
580-
Message: "BackendTLSPolicy is attached to the Gateway",
581-
}
582-
}
583-
584-
// NewBackendTLSPolicyIgnored returns a Condition that indicates that the BackendTLSPolicy config cannot be attached to
585-
// the Gateway and will be ignored.
586-
func NewBackendTLSPolicyIgnored(msg string) conditions.Condition {
587-
return conditions.Condition{
588-
Type: string(BackendTLSPolicyConditionAttached),
589-
Status: metav1.ConditionFalse,
590-
Reason: string(BackendTLSPolicyReasonIgnored),
591-
Message: msg,
577+
Reason: string(v1alpha2.PolicyReasonAccepted),
578+
Message: "BackendTLSPolicy is accepted by the Gateway",
592579
}
593580
}
594581

595582
// NewBackendTLSPolicyInvalid returns a Condition that indicates that the BackendTLSPolicy config is invalid.
596583
func NewBackendTLSPolicyInvalid(msg string) conditions.Condition {
597584
return conditions.Condition{
598-
Type: string(BackendTLSPolicyConditionValid),
585+
Type: string(v1alpha2.PolicyConditionAccepted),
599586
Status: metav1.ConditionFalse,
600-
Reason: string(BackendTLSPolicyReasonInvalid),
587+
Reason: string(v1alpha2.PolicyReasonInvalid),
601588
Message: msg,
602589
}
603590
}

0 commit comments

Comments
 (0)