fix(node): logger test fixed (#5232)

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
This commit is contained in:
Ivan Ka 2025-03-28 09:50:45 +00:00 committed by GitHub
parent 67119e0aac
commit 3fa5fc23b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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.