mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-07 10:06:57 +02:00
fix(source): debug log on gateway target detection
This code referenced the endpoints variable which was updated with each resource leading to confusing debug messages - this sets up a new array each iteration to log just the records from the relevant Gateway resource.
This commit is contained in:
parent
22762d89b3
commit
e6d03edd68
@ -234,14 +234,17 @@ func (src *gatewayRouteSource) Endpoints(ctx context.Context) ([]*endpoint.Endpo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create endpoints from hostnames and targets.
|
// Create endpoints from hostnames and targets.
|
||||||
|
var routeEndpoints []*endpoint.Endpoint
|
||||||
resource := fmt.Sprintf("%s/%s/%s", kind, meta.Namespace, meta.Name)
|
resource := fmt.Sprintf("%s/%s/%s", kind, meta.Namespace, meta.Name)
|
||||||
providerSpecific, setIdentifier := getProviderSpecificAnnotations(annots)
|
providerSpecific, setIdentifier := getProviderSpecificAnnotations(annots)
|
||||||
ttl := getTTLFromAnnotations(annots, resource)
|
ttl := getTTLFromAnnotations(annots, resource)
|
||||||
for host, targets := range hostTargets {
|
for host, targets := range hostTargets {
|
||||||
endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
|
routeEndpoints = append(routeEndpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
|
||||||
}
|
}
|
||||||
setDualstackLabel(rt, endpoints)
|
setDualstackLabel(rt, routeEndpoints)
|
||||||
log.Debugf("Endpoints generated from %s %s/%s: %v", src.rtKind, meta.Namespace, meta.Name, endpoints)
|
log.Debugf("Endpoints generated from %s %s/%s: %v", src.rtKind, meta.Namespace, meta.Name, routeEndpoints)
|
||||||
|
|
||||||
|
endpoints = append(endpoints, routeEndpoints...)
|
||||||
}
|
}
|
||||||
return endpoints, nil
|
return endpoints, nil
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,18 @@ limitations under the License.
|
|||||||
package source
|
package source
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
kubefake "k8s.io/client-go/kubernetes/fake"
|
kubefake "k8s.io/client-go/kubernetes/fake"
|
||||||
"sigs.k8s.io/external-dns/endpoint"
|
"sigs.k8s.io/external-dns/endpoint"
|
||||||
|
"sigs.k8s.io/external-dns/internal/testutils"
|
||||||
v1 "sigs.k8s.io/gateway-api/apis/v1"
|
v1 "sigs.k8s.io/gateway-api/apis/v1"
|
||||||
v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
|
v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||||
gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
|
gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
|
||||||
@ -107,8 +110,6 @@ func newTestEndpointWithTTL(dnsName, recordType string, ttl int64, targets ...st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
fromAll := v1.NamespacesFromAll
|
fromAll := v1.NamespacesFromAll
|
||||||
fromSame := v1.NamespacesFromSame
|
fromSame := v1.NamespacesFromSame
|
||||||
fromSelector := v1.NamespacesFromSelector
|
fromSelector := v1.NamespacesFromSelector
|
||||||
@ -139,6 +140,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
|||||||
gateways []*v1beta1.Gateway
|
gateways []*v1beta1.Gateway
|
||||||
routes []*v1beta1.HTTPRoute
|
routes []*v1beta1.HTTPRoute
|
||||||
endpoints []*endpoint.Endpoint
|
endpoints []*endpoint.Endpoint
|
||||||
|
logExpectations []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
title: "GatewayNamespace",
|
title: "GatewayNamespace",
|
||||||
@ -1119,11 +1121,62 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
|||||||
newTestEndpoint("test.example.internal", "A", "4.3.2.1", "2.3.4.5"),
|
newTestEndpoint("test.example.internal", "A", "4.3.2.1", "2.3.4.5"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "MultipleGatewaysMultipleRoutes",
|
||||||
|
config: Config{},
|
||||||
|
namespaces: namespaces("default"),
|
||||||
|
gateways: []*v1beta1.Gateway{
|
||||||
|
{
|
||||||
|
ObjectMeta: objectMeta("default", "one"),
|
||||||
|
Spec: v1.GatewaySpec{
|
||||||
|
Listeners: []v1.Listener{{Protocol: v1.HTTPProtocolType}},
|
||||||
|
},
|
||||||
|
Status: gatewayStatus("1.2.3.4"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ObjectMeta: objectMeta("default", "two"),
|
||||||
|
Spec: v1.GatewaySpec{
|
||||||
|
Listeners: []v1.Listener{{Protocol: v1.HTTPProtocolType}},
|
||||||
|
},
|
||||||
|
Status: gatewayStatus("2.3.4.5"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
routes: []*v1beta1.HTTPRoute{
|
||||||
|
{
|
||||||
|
ObjectMeta: objectMeta("default", "one"),
|
||||||
|
Spec: v1.HTTPRouteSpec{
|
||||||
|
Hostnames: hostnames("test.one.internal"),
|
||||||
|
},
|
||||||
|
Status: httpRouteStatus(
|
||||||
|
gwParentRef("default", "one"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ObjectMeta: objectMeta("default", "two"),
|
||||||
|
Spec: v1.HTTPRouteSpec{
|
||||||
|
Hostnames: hostnames("test.two.internal"),
|
||||||
|
},
|
||||||
|
Status: httpRouteStatus(
|
||||||
|
gwParentRef("default", "two"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
endpoints: []*endpoint.Endpoint{
|
||||||
|
newTestEndpoint("test.one.internal", "A", "1.2.3.4"),
|
||||||
|
newTestEndpoint("test.two.internal", "A", "2.3.4.5"),
|
||||||
|
},
|
||||||
|
logExpectations: []string{
|
||||||
|
"level=debug msg=\"Endpoints generated from HTTPRoute default/one: [test.one.internal 0 IN A 1.2.3.4 []]\"",
|
||||||
|
"level=debug msg=\"Endpoints generated from HTTPRoute default/two: [test.two.internal 0 IN A 2.3.4.5 []]\"",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
t.Run(tt.title, func(t *testing.T) {
|
t.Run(tt.title, func(t *testing.T) {
|
||||||
|
if len(tt.logExpectations) == 0 {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
gwClient := gatewayfake.NewSimpleClientset()
|
gwClient := gatewayfake.NewSimpleClientset()
|
||||||
@ -1149,9 +1202,17 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
|||||||
src, err := NewGatewayHTTPRouteSource(clients, &tt.config)
|
src, err := NewGatewayHTTPRouteSource(clients, &tt.config)
|
||||||
require.NoError(t, err, "failed to create Gateway HTTPRoute Source")
|
require.NoError(t, err, "failed to create Gateway HTTPRoute Source")
|
||||||
|
|
||||||
|
var b *bytes.Buffer
|
||||||
|
if len(tt.logExpectations) > 0 {
|
||||||
|
b = testutils.LogsToBuffer(log.DebugLevel, t)
|
||||||
|
}
|
||||||
endpoints, err := src.Endpoints(ctx)
|
endpoints, err := src.Endpoints(ctx)
|
||||||
require.NoError(t, err, "failed to get Endpoints")
|
require.NoError(t, err, "failed to get Endpoints")
|
||||||
validateEndpoints(t, endpoints, tt.endpoints)
|
validateEndpoints(t, endpoints, tt.endpoints)
|
||||||
|
|
||||||
|
for _, msg := range tt.logExpectations {
|
||||||
|
require.Contains(t, b.String(), msg)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user