From 3fa5fc23b7fe48c157275b210e0cab3efd532d44 Mon Sep 17 00:00:00 2001 From: Ivan Ka <5395690+ivankatliarchuk@users.noreply.github.com> Date: Fri, 28 Mar 2025 09:50:45 +0000 Subject: [PATCH] fix(node): logger test fixed (#5232) Signed-off-by: ivan katliarchuk --- source/node.go | 3 +++ source/node_test.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/node.go b/source/node.go index 50ec987c9..c61c232b8 100644 --- a/source/node.go +++ b/source/node.go @@ -33,6 +33,8 @@ import ( "sigs.k8s.io/external-dns/endpoint" ) +const warningMsg = "The default behavior of exposing internal IPv6 addresses will change in the next minor version. Use --no-expose-internal-ipv6 flag to opt-in to the new behavior." + type nodeSource struct { client kubernetes.Interface annotationFilter string @@ -189,6 +191,7 @@ func (ns *nodeSource) nodeAddresses(node *v1.Node) ([]string, error) { if len(addresses[v1.NodeExternalIP]) > 0 { if ns.exposeInternalIPV6 { + log.Warn(warningMsg) return append(addresses[v1.NodeExternalIP], internalIpv6Addresses...), nil } return addresses[v1.NodeExternalIP], nil diff --git a/source/node_test.go b/source/node_test.go index a597082dc..c944c6401 100644 --- a/source/node_test.go +++ b/source/node_test.go @@ -17,10 +17,12 @@ limitations under the License. package source import ( + "bytes" "context" + "testing" + log "github.com/sirupsen/logrus" "sigs.k8s.io/external-dns/internal/testutils" - "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -501,11 +503,9 @@ func testNodeEndpointsWithIPv6(t *testing.T) { _, err := kubernetes.CoreV1().Nodes().Create(context.Background(), node, metav1.CreateOptions{}) require.NoError(t, err) + var buf *bytes.Buffer if tc.exposeInternalIPv6 { - buf := testutils.LogsToBuffer(log.WarnLevel, t) - warningMsg := "The default behavior of exposing internal IPv6 addresses will change in the next minor version. Use --no-expose-internal-ipv6 flag to opt-in to the new behavior." - log.Warn(warningMsg) - assert.Contains(t, buf.String(), warningMsg) + buf = testutils.LogsToBuffer(log.WarnLevel, t) } // Create our object under test and get the endpoints. @@ -524,6 +524,10 @@ func testNodeEndpointsWithIPv6(t *testing.T) { require.Error(t, err) } else { require.NoError(t, err) + + if tc.exposeInternalIPv6 && buf != nil { + assert.Contains(t, buf.String(), warningMsg) + } } // Validate returned endpoints against desired endpoints.