mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-07 01:56:57 +02:00
only consider accepted gateway routes if the condition generation matches the current one
This commit is contained in:
parent
5372915340
commit
4386d8ba94
@ -293,7 +293,7 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
hostTargets := make(map[string]endpoint.Targets)
|
hostTargets := make(map[string]endpoint.Targets)
|
||||||
|
currentGeneration := rt.Metadata().Generation
|
||||||
meta := rt.Metadata()
|
meta := rt.Metadata()
|
||||||
for _, rps := range rt.RouteStatus().Parents {
|
for _, rps := range rt.RouteStatus().Parents {
|
||||||
// Confirm the Parent is the standard Gateway kind.
|
// Confirm the Parent is the standard Gateway kind.
|
||||||
@ -316,8 +316,8 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
|
|||||||
log.Debugf("Gateway %s/%s does not match %s %s/%s", namespace, ref.Name, c.src.gwName, meta.Namespace, meta.Name)
|
log.Debugf("Gateway %s/%s does not match %s %s/%s", namespace, ref.Name, c.src.gwName, meta.Namespace, meta.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Confirm the Gateway has accepted the Route.
|
// Confirm the Gateway has accepted the Route, and that the generation matches.
|
||||||
if !gwRouteIsAccepted(rps.Conditions) {
|
if !gwRouteIsAccepted(rps.Conditions, currentGeneration) {
|
||||||
log.Debugf("Gateway %s/%s has not accepted %s %s/%s", namespace, ref.Name, c.src.rtKind, meta.Namespace, meta.Name)
|
log.Debugf("Gateway %s/%s has not accepted %s %s/%s", namespace, ref.Name, c.src.rtKind, meta.Namespace, meta.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -458,9 +458,9 @@ func (c *gatewayRouteResolver) routeIsAllowed(gw *v1beta1.Gateway, lis *v1.Liste
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func gwRouteIsAccepted(conds []metav1.Condition) bool {
|
func gwRouteIsAccepted(conds []metav1.Condition, currentGeneration int64) bool {
|
||||||
for _, c := range conds {
|
for _, c := range conds {
|
||||||
if v1.RouteConditionType(c.Type) == v1.RouteConditionAccepted {
|
if v1.RouteConditionType(c.Type) == v1.RouteConditionAccepted && c.ObservedGeneration == currentGeneration {
|
||||||
return c.Status == metav1.ConditionTrue
|
return c.Status == metav1.ConditionTrue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
v1 "sigs.k8s.io/gateway-api/apis/v1"
|
v1 "sigs.k8s.io/gateway-api/apis/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -245,3 +246,75 @@ func TestIsDNS1123Domain(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGwRouteIsAccepted(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
desc string
|
||||||
|
conditions []metav1.Condition
|
||||||
|
currentGeneration int64
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "accepted condition with matching generation",
|
||||||
|
conditions: []metav1.Condition{
|
||||||
|
{
|
||||||
|
Type: string(v1.RouteConditionAccepted),
|
||||||
|
Status: metav1.ConditionTrue,
|
||||||
|
ObservedGeneration: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
currentGeneration: 1,
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "accepted condition with different generation",
|
||||||
|
conditions: []metav1.Condition{
|
||||||
|
{
|
||||||
|
Type: string(v1.RouteConditionAccepted),
|
||||||
|
Status: metav1.ConditionTrue,
|
||||||
|
ObservedGeneration: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
currentGeneration: 2,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "accepted condition with false status",
|
||||||
|
conditions: []metav1.Condition{
|
||||||
|
{
|
||||||
|
Type: string(v1.RouteConditionAccepted),
|
||||||
|
Status: metav1.ConditionFalse,
|
||||||
|
ObservedGeneration: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
currentGeneration: 1,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no accepted condition",
|
||||||
|
conditions: []metav1.Condition{
|
||||||
|
{
|
||||||
|
Type: "OtherCondition",
|
||||||
|
Status: metav1.ConditionTrue,
|
||||||
|
ObservedGeneration: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
currentGeneration: 1,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "empty conditions",
|
||||||
|
conditions: []metav1.Condition{},
|
||||||
|
currentGeneration: 1,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
|
if got := gwRouteIsAccepted(tt.conditions, tt.currentGeneration); got != tt.want {
|
||||||
|
t.Errorf("gwRouteIsAccepted() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user