@@ -18,7 +18,8 @@ type BackendTLSPolicy struct {
1818 Source * v1alpha3.BackendTLSPolicy
1919 // CaCertRef is the name of the ConfigMap that contains the CA certificate.
2020 CaCertRef types.NamespacedName
21- // Gateways are the names of the Gateways that are being checked for this BackendTLSPolicy.
21+ // Gateways are the names of the Gateways for which this BackendTLSPolicy is effectively applied.
22+ // Only contains gateways where the policy can be applied (not limited by ancestor status).
2223 Gateways []types.NamespacedName
2324 // Conditions include Conditions for the BackendTLSPolicy.
2425 Conditions []conditions.Condition
@@ -68,16 +69,13 @@ func validateBackendTLSPolicy(
6869 backendTLSPolicy * v1alpha3.BackendTLSPolicy ,
6970 configMapResolver * configMapResolver ,
7071 secretResolver * secretResolver ,
71- ctlrName string ,
72+ _ string ,
7273) (valid , ignored bool , conds []conditions.Condition ) {
7374 valid = true
7475 ignored = false
7576
76- // FIXME (kate-osborn): https://github.com/nginx/nginx-gateway-fabric/issues/1987
77- if backendTLSPolicyAncestorsFull (backendTLSPolicy .Status .Ancestors , ctlrName ) {
78- valid = false
79- ignored = true
80- }
77+ // Note: Ancestor limit checking moved to addGatewaysForBackendTLSPolicies for per-gateway effectiveness tracking
78+ // The policy may be partially effective (work for some gateways but not others due to ancestor limits)
8179
8280 if err := validateBackendTLSHostname (backendTLSPolicy ); err != nil {
8381 valid = false
@@ -186,10 +184,12 @@ func validateBackendTLSWellKnownCACerts(btp *v1alpha3.BackendTLSPolicy) error {
186184func addGatewaysForBackendTLSPolicies (
187185 backendTLSPolicies map [types.NamespacedName ]* BackendTLSPolicy ,
188186 services map [types.NamespacedName ]* ReferencedService ,
187+ ctlrName string ,
189188) {
190189 for _ , backendTLSPolicy := range backendTLSPolicies {
191- gateways := make (map [types.NamespacedName ]struct {})
190+ potentialGateways := make (map [types.NamespacedName ]struct {})
192191
192+ // First, collect all potential gateways for this policy
193193 for _ , refs := range backendTLSPolicy .Source .Spec .TargetRefs {
194194 if refs .Kind != kinds .Service {
195195 continue
@@ -201,13 +201,32 @@ func addGatewaysForBackendTLSPolicies(
201201 }
202202
203203 for gateway := range referencedServices .GatewayNsNames {
204- gateways [gateway ] = struct {}{}
204+ potentialGateways [gateway ] = struct {}{}
205205 }
206206 }
207207 }
208208
209- for gateway := range gateways {
210- backendTLSPolicy .Gateways = append (backendTLSPolicy .Gateways , gateway )
209+ // Now check each potential gateway against ancestor limits
210+ for gatewayNsName := range potentialGateways {
211+ // Create a proposed ancestor reference for this gateway
212+ proposedAncestor := createParentReference (v1 .GroupName , kinds .Gateway , gatewayNsName )
213+
214+ // Check ancestor limit for BackendTLS policy
215+ isFull := backendTLSPolicyAncestorsFull (
216+ backendTLSPolicy .Source .Status .Ancestors ,
217+ ctlrName ,
218+ )
219+
220+ if isFull {
221+ policyName := backendTLSPolicy .Source .Namespace + "/" + backendTLSPolicy .Source .Name
222+ gatewayName := getAncestorName (proposedAncestor )
223+ LogAncestorLimitReached (policyName , "BackendTLSPolicy" , gatewayName )
224+
225+ continue
226+ }
227+
228+ // Gateway can be effectively used by this policy
229+ backendTLSPolicy .Gateways = append (backendTLSPolicy .Gateways , gatewayNsName )
211230 }
212231 }
213232}
0 commit comments