Skip to content

Commit 99ca323

Browse files
committed
remove old code
1 parent 624fd46 commit 99ca323

File tree

5 files changed

+4
-182
lines changed

5 files changed

+4
-182
lines changed

internal/controller/state/graph/backend_tls_policy.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ func processBackendTLSPolicies(
3737
backendTLSPolicies map[types.NamespacedName]*v1alpha3.BackendTLSPolicy,
3838
configMapResolver *configMapResolver,
3939
secretResolver *secretResolver,
40-
ctlrName string,
4140
gateways map[types.NamespacedName]*Gateway,
4241
) map[types.NamespacedName]*BackendTLSPolicy {
4342
if len(backendTLSPolicies) == 0 || len(gateways) == 0 {
@@ -48,7 +47,7 @@ func processBackendTLSPolicies(
4847
for nsname, backendTLSPolicy := range backendTLSPolicies {
4948
var caCertRef types.NamespacedName
5049

51-
valid, ignored, conds := validateBackendTLSPolicy(backendTLSPolicy, configMapResolver, secretResolver, ctlrName)
50+
valid, ignored, conds := validateBackendTLSPolicy(backendTLSPolicy, configMapResolver, secretResolver)
5251

5352
if valid && !ignored && backendTLSPolicy.Spec.Validation.CACertificateRefs != nil {
5453
caCertRef = types.NamespacedName{
@@ -71,21 +70,13 @@ func validateBackendTLSPolicy(
7170
backendTLSPolicy *v1alpha3.BackendTLSPolicy,
7271
configMapResolver *configMapResolver,
7372
secretResolver *secretResolver,
74-
_ string,
7573
) (valid, ignored bool, conds []conditions.Condition) {
7674
valid = true
7775
ignored = false
7876

79-
// Ancestor limit handling is now done during gateway assignment phase, not validation
80-
// if backendTLSPolicyAncestorsFull(backendTLSPolicy.Status.Ancestors, ctlrName) {
81-
// valid = false
82-
// ignored = true
83-
// return
84-
// }
85-
8677
if err := validateBackendTLSHostname(backendTLSPolicy); err != nil {
8778
valid = false
88-
conds = append(conds, conditions.NewPolicyInvalid(err.Error()))
79+
conds = append(conds, conditions.NewPolicyInvalid(fmt.Sprintf("invalid hostname: %s", err.Error())))
8980
}
9081

9182
caCertRefs := backendTLSPolicy.Spec.Validation.CACertificateRefs

internal/controller/state/graph/backend_tls_policy_test.go

Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestProcessBackendTLSPoliciesEmpty(t *testing.T) {
8080
t.Parallel()
8181
g := NewWithT(t)
8282

83-
processed := processBackendTLSPolicies(test.backendTLSPolicies, nil, nil, "test", test.gateways)
83+
processed := processBackendTLSPolicies(test.backendTLSPolicies, nil, nil, test.gateways)
8484

8585
g.Expect(processed).To(Equal(test.expected))
8686
})
@@ -477,7 +477,7 @@ func TestValidateBackendTLSPolicy(t *testing.T) {
477477
t.Run(test.name, func(t *testing.T) {
478478
g := NewWithT(t)
479479

480-
valid, ignored, conds := validateBackendTLSPolicy(test.tlsPolicy, configMapResolver, secretMapResolver, "test")
480+
valid, ignored, conds := validateBackendTLSPolicy(test.tlsPolicy, configMapResolver, secretMapResolver)
481481

482482
if !test.isValid && !test.ignored {
483483
g.Expect(conds).To(HaveLen(1))
@@ -809,105 +809,6 @@ func TestAddGatewaysForBackendTLSPoliciesAncestorLimit(t *testing.T) {
809809
g.Expect(logOutput).To(ContainSubstring("ancestor=test/gateway1"))
810810
}
811811

812-
func TestBackendTLSPolicyAncestorsFullFunc(t *testing.T) {
813-
t.Parallel()
814-
815-
getAncestorRef := func(ctlrName, parentName string) v1alpha2.PolicyAncestorStatus {
816-
return v1alpha2.PolicyAncestorStatus{
817-
ControllerName: gatewayv1.GatewayController(ctlrName),
818-
AncestorRef: gatewayv1.ParentReference{
819-
Name: gatewayv1.ObjectName(parentName),
820-
Namespace: helpers.GetPointer(gatewayv1.Namespace("test")),
821-
Group: helpers.GetPointer[gatewayv1.Group](gatewayv1.GroupName),
822-
Kind: helpers.GetPointer[gatewayv1.Kind](kinds.Gateway),
823-
},
824-
}
825-
}
826-
827-
tests := []struct {
828-
name string
829-
ctlrName string
830-
ancestors []v1alpha2.PolicyAncestorStatus
831-
expected bool
832-
}{
833-
{
834-
name: "empty ancestors list",
835-
ancestors: []v1alpha2.PolicyAncestorStatus{},
836-
ctlrName: "nginx-gateway",
837-
expected: false,
838-
},
839-
{
840-
name: "less than 16 ancestors",
841-
ancestors: []v1alpha2.PolicyAncestorStatus{
842-
getAncestorRef("other-controller", "gateway1"),
843-
getAncestorRef("other-controller", "gateway2"),
844-
},
845-
ctlrName: "nginx-gateway",
846-
expected: false,
847-
},
848-
{
849-
name: "exactly 16 ancestors, none from our controller",
850-
ancestors: func() []v1alpha2.PolicyAncestorStatus {
851-
ancestors := make([]v1alpha2.PolicyAncestorStatus, 16)
852-
for i := range 16 {
853-
ancestors[i] = getAncestorRef("other-controller", "gateway")
854-
}
855-
return ancestors
856-
}(),
857-
ctlrName: "nginx-gateway",
858-
expected: true,
859-
},
860-
{
861-
name: "exactly 16 ancestors, one from our controller",
862-
ancestors: func() []v1alpha2.PolicyAncestorStatus {
863-
ancestors := make([]v1alpha2.PolicyAncestorStatus, 16)
864-
for i := range 15 {
865-
ancestors[i] = getAncestorRef("other-controller", "gateway")
866-
}
867-
ancestors[15] = getAncestorRef("nginx-gateway", "our-gateway")
868-
return ancestors
869-
}(),
870-
ctlrName: "nginx-gateway",
871-
expected: false, // Not full because we can overwrite our own entry
872-
},
873-
{
874-
name: "more than 16 ancestors, none from our controller",
875-
ancestors: func() []v1alpha2.PolicyAncestorStatus {
876-
ancestors := make([]v1alpha2.PolicyAncestorStatus, 20)
877-
for i := range 20 {
878-
ancestors[i] = getAncestorRef("other-controller", "gateway")
879-
}
880-
return ancestors
881-
}(),
882-
ctlrName: "nginx-gateway",
883-
expected: true,
884-
},
885-
{
886-
name: "more than 16 ancestors, one from our controller",
887-
ancestors: func() []v1alpha2.PolicyAncestorStatus {
888-
ancestors := make([]v1alpha2.PolicyAncestorStatus, 20)
889-
for i := range 19 {
890-
ancestors[i] = getAncestorRef("other-controller", "gateway")
891-
}
892-
ancestors[19] = getAncestorRef("nginx-gateway", "our-gateway")
893-
return ancestors
894-
}(),
895-
ctlrName: "nginx-gateway",
896-
expected: false, // Not full because we can overwrite our own entry
897-
},
898-
}
899-
900-
for _, test := range tests {
901-
t.Run(test.name, func(t *testing.T) {
902-
t.Parallel()
903-
g := NewWithT(t)
904-
905-
result := backendTLSPolicyAncestorsFull(test.ancestors, test.ctlrName)
906-
g.Expect(result).To(Equal(test.expected))
907-
})
908-
}
909-
}
910-
911812
// testLogSink implements logr.LogSink for testing.
912813
type testLogSink struct {
913814
buffer *bytes.Buffer

internal/controller/state/graph/graph.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ func BuildGraph(
239239
state.BackendTLSPolicies,
240240
configMapResolver,
241241
secretResolver,
242-
controllerName,
243242
gws,
244243
)
245244

internal/controller/state/graph/policy_ancestor.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/go-logr/logr"
77
"k8s.io/apimachinery/pkg/types"
88
v1 "sigs.k8s.io/gateway-api/apis/v1"
9-
"sigs.k8s.io/gateway-api/apis/v1alpha2"
109

1110
"github.com/nginx/nginx-gateway-fabric/v2/internal/controller/nginx/config/policies"
1211
"github.com/nginx/nginx-gateway-fabric/v2/internal/framework/helpers"
@@ -19,27 +18,6 @@ func LogAncestorLimitReached(logger logr.Logger, policyName, policyKind, ancesto
1918
logger.Info("Policy ancestor limit reached", "policy", policyName, "policyKind", policyKind, "ancestor", ancestorName)
2019
}
2120

22-
// backendTLSPolicyAncestorsFull returns whether or not an ancestor list is full. A list is not full when:
23-
// - the number of current ancestors is less than the maximum allowed
24-
// - an entry for an NGF managed resource already exists in the ancestor list. This means that we are overwriting
25-
// that status entry with the current status entry, since there is only one ancestor (Gateway) for this policy.
26-
func backendTLSPolicyAncestorsFull(
27-
ancestors []v1alpha2.PolicyAncestorStatus,
28-
ctlrName string,
29-
) bool {
30-
if len(ancestors) < maxAncestors {
31-
return false
32-
}
33-
34-
for _, ancestor := range ancestors {
35-
if string(ancestor.ControllerName) == ctlrName {
36-
return false
37-
}
38-
}
39-
40-
return true
41-
}
42-
4321
// ngfPolicyAncestorsFull returns whether or not an ancestor list is full. A list is full when
4422
// the sum of the following is greater than or equal to the maximum allowed:
4523
// - number of non-NGF managed ancestors

internal/controller/state/graph/policy_ancestor_test.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,6 @@ import (
1212
"github.com/nginx/nginx-gateway-fabric/v2/internal/framework/kinds"
1313
)
1414

15-
func TestBackendTLSPolicyAncestorsFull(t *testing.T) {
16-
t.Parallel()
17-
createCurStatus := func(numAncestors int, ctlrName string) []v1alpha2.PolicyAncestorStatus {
18-
statuses := make([]v1alpha2.PolicyAncestorStatus, 0, numAncestors)
19-
20-
for range numAncestors {
21-
statuses = append(statuses, v1alpha2.PolicyAncestorStatus{
22-
ControllerName: v1.GatewayController(ctlrName),
23-
})
24-
}
25-
26-
return statuses
27-
}
28-
29-
tests := []struct {
30-
name string
31-
curStatus []v1alpha2.PolicyAncestorStatus
32-
expFull bool
33-
}{
34-
{
35-
name: "not full",
36-
curStatus: createCurStatus(15, "controller"),
37-
expFull: false,
38-
},
39-
{
40-
name: "full; ancestor does not exist in current status",
41-
curStatus: createCurStatus(16, "controller"),
42-
expFull: true,
43-
},
44-
{
45-
name: "full, but ancestor does exist in current status",
46-
curStatus: createCurStatus(16, "nginx-gateway"),
47-
expFull: false,
48-
},
49-
}
50-
51-
for _, test := range tests {
52-
t.Run(test.name, func(t *testing.T) {
53-
t.Parallel()
54-
g := NewWithT(t)
55-
56-
full := backendTLSPolicyAncestorsFull(test.curStatus, "nginx-gateway")
57-
g.Expect(full).To(Equal(test.expFull))
58-
})
59-
}
60-
}
61-
6215
func TestNGFPolicyAncestorsFull(t *testing.T) {
6316
t.Parallel()
6417
type ancestorConfig struct {

0 commit comments

Comments
 (0)