diff --git a/provider/pihole/pihole.go b/provider/pihole/pihole.go index cf401f374..09a32ab1f 100644 --- a/provider/pihole/pihole.go +++ b/provider/pihole/pihole.go @@ -22,6 +22,7 @@ import ( "slices" "github.com/google/go-cmp/cmp" + log "github.com/sirupsen/logrus" "sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/plan" @@ -32,6 +33,10 @@ import ( // in the environment. var ErrNoPiholeServer = errors.New("no pihole server found in the environment or flags") +const ( + warningMsg = "Pi-hole v5 API support is deprecated. Set --pihole-api-version=\"6\" to use the Pi-hole v6 API. The v5 API will be removed in a future release." +) + // PiholeProvider is an implementation of Provider for Pi-hole Local DNS. type PiholeProvider struct { provider.BaseProvider @@ -69,6 +74,7 @@ func NewPiholeProvider(cfg PiholeConfig) (*PiholeProvider, error) { case "6": api, err = newPiholeClientV6(cfg) default: + log.Warn(warningMsg) api, err = newPiholeClient(cfg) } if err != nil { diff --git a/provider/pihole/pihole_test.go b/provider/pihole/pihole_test.go index ca6d5d7b5..6da4d6df4 100644 --- a/provider/pihole/pihole_test.go +++ b/provider/pihole/pihole_test.go @@ -21,7 +21,10 @@ import ( "reflect" "testing" + log "github.com/sirupsen/logrus" + "github.com/stretchr/testify/require" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/internal/testutils" "sigs.k8s.io/external-dns/plan" ) @@ -81,6 +84,42 @@ func TestNewPiholeProvider(t *testing.T) { } } +func TestNewPiholeProvider_APIVersions(t *testing.T) { + tests := []struct { + name string + config PiholeConfig + wantMsg bool + }{ + { + name: "API version 5 with server", + config: PiholeConfig{ + APIVersion: "5", + Server: "test.example.com", + }, + wantMsg: true, + }, + { + name: "API version 6 with server", + config: PiholeConfig{ + APIVersion: "6", + Server: "test.example.com", + }, + wantMsg: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + hook := testutils.LogsUnderTestWithLogLevel(log.DebugLevel, t) + _, err := NewPiholeProvider(tt.config) + require.NoError(t, err) + if tt.wantMsg { + testutils.TestHelperLogContains(warningMsg, hook, t) + } + }) + } +} + func TestProvider_InitialState(t *testing.T) { requests := requestTracker{} p := &PiholeProvider{