Skip to content

Commit dfb5347

Browse files
fix: check policy status when generating config (#304)
Signed-off-by: Lin Yang <[email protected]>
1 parent 9bca557 commit dfb5347

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

pkg/gateway/processor/v2/backend_lb_policy.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewBackendLBPolicyProcessor(c *ConfigGenerator) BackendPolicyProcessor {
2525
}
2626
}
2727

28-
func (p *BackendLBPolicyProcessor) Process(route client.Object, _ gwv1.ParentReference, routeRule any, backendRef gwv1.BackendObjectReference, svcPort *fgwv2.ServicePortName) {
28+
func (p *BackendLBPolicyProcessor) Process(route client.Object, routeParentRef gwv1.ParentReference, routeRule any, backendRef gwv1.BackendObjectReference, svcPort *fgwv2.ServicePortName) {
2929
// Any configuration that is specified at Route Rule level MUST override configuration
3030
// that is attached at the backend level because route rule have a more global view and
3131
// responsibility for the overall traffic routing.
@@ -66,6 +66,10 @@ func (p *BackendLBPolicyProcessor) Process(route client.Object, _ gwv1.ParentRef
6666
return
6767
}
6868

69+
if !gwutils.IsPolicyAcceptedForAncestor(routeParentRef, policy.Status.Ancestors) {
70+
return
71+
}
72+
6973
p2 := p.getOrCreateBackendLBPolicy(policy)
7074
if p2 == nil {
7175
return

pkg/gateway/processor/v2/backend_tls_policy.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewBackendTLSPolicyProcessor(c *ConfigGenerator) BackendPolicyProcessor {
3030
}
3131
}
3232

33-
func (p *BackendTLSPolicyProcessor) Process(route client.Object, _ gwv1.ParentReference, routeRule any, backendRef gwv1.BackendObjectReference, svcPort *fgwv2.ServicePortName) {
33+
func (p *BackendTLSPolicyProcessor) Process(route client.Object, routeParentRef gwv1.ParentReference, routeRule any, backendRef gwv1.BackendObjectReference, svcPort *fgwv2.ServicePortName) {
3434
targetRef := gwv1alpha2.LocalPolicyTargetReferenceWithSectionName{
3535
LocalPolicyTargetReference: gwv1alpha2.LocalPolicyTargetReference{
3636
Group: ptr.Deref(backendRef.Group, corev1.GroupName),
@@ -45,6 +45,10 @@ func (p *BackendTLSPolicyProcessor) Process(route client.Object, _ gwv1.ParentRe
4545
return
4646
}
4747

48+
if !gwutils.IsPolicyAcceptedForAncestor(routeParentRef, policy.Status.Ancestors) {
49+
return
50+
}
51+
4852
hostname := string(policy.Spec.Validation.Hostname)
4953
if err := gwutils.IsValidHostname(hostname); err != nil {
5054
return

pkg/gateway/processor/v2/health_check_policy.go

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func (p *HealthCheckPolicyProcessor) Process(route client.Object, routeParentRef
4141
return
4242
}
4343

44+
if !gwutils.IsPolicyAcceptedForAncestor(routeParentRef, policy.Status.Ancestors) {
45+
return
46+
}
47+
4448
psu := policies.NewPolicyStatusHolderWithNamespacedPolicyTargetReference(
4549
policy,
4650
&policy.ObjectMeta,

pkg/gateway/processor/v2/retry_policy.go

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func (p *RetryPolicyProcessor) Process(route client.Object, routeParentRef gwv1.
4141
return
4242
}
4343

44+
if !gwutils.IsPolicyAcceptedForAncestor(routeParentRef, policy.Status.Ancestors) {
45+
return
46+
}
47+
4448
psh := policies.NewPolicyStatusHolderWithNamespacedPolicyTargetReference(
4549
policy,
4650
&policy.ObjectMeta,

pkg/gateway/utils/policies.go

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package utils
33
import (
44
"fmt"
55

6+
"github.com/google/go-cmp/cmp"
7+
metautil "k8s.io/apimachinery/pkg/api/meta"
8+
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
9+
610
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
711
"sigs.k8s.io/controller-runtime/pkg/cache"
812
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -57,6 +61,16 @@ func HasAccessToBackendTargetRef(client cache.Cache, policy client.Object, targe
5761
return true
5862
}
5963

64+
func IsPolicyAcceptedForAncestor(ancestorRef gwv1.ParentReference, ancestors []gwv1alpha2.PolicyAncestorStatus) bool {
65+
for _, ancestor := range ancestors {
66+
if cmp.Equal(ancestor.AncestorRef, ancestorRef) {
67+
return metautil.IsStatusConditionTrue(ancestor.Conditions, string(gwv1alpha2.PolicyConditionAccepted))
68+
}
69+
}
70+
71+
return false
72+
}
73+
6074
// ---------------------------- Access Control ----------------------------
6175

6276
// GetAccessControlsMatchTypePort returns a list of AccessControlPolicy objects that match the given selector

0 commit comments

Comments
 (0)