Skip to content

Commit

Permalink
chore: remove ProcessBackendTLSPoliciesAncestorRef (#2845)
Browse files Browse the repository at this point in the history
* remove ProcessBackendTLSPoliciesAncestorRef

Signed-off-by: huabing zhao <[email protected]>

* address comments

Signed-off-by: huabing zhao <[email protected]>

---------

Signed-off-by: huabing zhao <[email protected]>
  • Loading branch information
zhaohuabing authored Mar 12, 2024
1 parent 8d05fb5 commit 3793f54
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 45 deletions.
38 changes: 0 additions & 38 deletions internal/gatewayapi/backendtlspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,41 +162,3 @@ func getBackendTLSBundle(policies []*gwapiv1a2.BackendTLSPolicy, configmaps []*c

return tlsBundle, nil
}

func (t *Translator) ProcessBackendTLSPoliciesAncestorRef(backendTLSPolicies []*gwapiv1a2.BackendTLSPolicy, gateways []*GatewayContext) []*gwapiv1a2.BackendTLSPolicy {

var res []*gwapiv1a2.BackendTLSPolicy

for _, btlsPolicy := range backendTLSPolicies {

policy := btlsPolicy.DeepCopy()
res = append(res, policy)

if policy.Status.Ancestors != nil {
for k, status := range policy.Status.Ancestors {
if status.AncestorRef.Kind != nil && *status.AncestorRef.Kind != KindGateway {
continue
}
exist := false
for _, gwContext := range gateways {
gw := gwContext.Gateway
if gw.Name == string(status.AncestorRef.Name) && gw.Namespace == NamespaceDerefOrAlpha(status.AncestorRef.Namespace, "default") {
for _, lis := range gw.Spec.Listeners {
if lis.Name == ptr.Deref(status.AncestorRef.SectionName, "") {
exist = true
}
}
}
}

if !exist {
policy.Status.Ancestors = append(policy.Status.Ancestors[:k], policy.Status.Ancestors[k+1:]...)
}
}
} else {
policy.Status.Ancestors = []gwapiv1a2.PolicyAncestorStatus{}
}
}

return res
}
5 changes: 1 addition & 4 deletions internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,12 @@ func (t *Translator) Translate(resources *Resources) *TranslateResult {
securityPolicies := t.ProcessSecurityPolicies(
resources.SecurityPolicies, gateways, routes, resources, xdsIR)

backendTLSPolicies := t.ProcessBackendTLSPoliciesAncestorRef(
resources.BackendTLSPolicies, gateways)

// Sort xdsIR based on the Gateway API spec
sortXdsIRMap(xdsIR)

return newTranslateResult(gateways, httpRoutes, grpcRoutes, tlsRoutes,
tcpRoutes, udpRoutes, clientTrafficPolicies, backendTrafficPolicies,
securityPolicies, backendTLSPolicies, xdsIR, infraIR)
securityPolicies, resources.BackendTLSPolicies, xdsIR, infraIR)

}

Expand Down
5 changes: 2 additions & 3 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,8 @@ func (r *gatewayAPIReconciler) processBackendTLSPolicies(

for _, policy := range backendTLSPolicies.Items {
policy := policy
// Discard Status to reduce memory consumption in watchable
// It will be recomputed by the gateway-api layer
policy.Status = gwapiv1a2.PolicyStatus{} // todo ?
// The status of BackendTLSPolicies can't be discarded because the status
// can be modified by multiple controllers.
resourceTree.BackendTLSPolicies = append(resourceTree.BackendTLSPolicies, &policy)
}

Expand Down

0 comments on commit 3793f54

Please sign in to comment.