Skip to content

Commit 7579ce2

Browse files
feat(pihole): deprecate v5 API support (#6123)
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent ee87a9a commit 7579ce2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

provider/pihole/pihole.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"slices"
2323

2424
"github.com/google/go-cmp/cmp"
25+
log "github.com/sirupsen/logrus"
2526

2627
"sigs.k8s.io/external-dns/endpoint"
2728
"sigs.k8s.io/external-dns/plan"
@@ -32,6 +33,10 @@ import (
3233
// in the environment.
3334
var ErrNoPiholeServer = errors.New("no pihole server found in the environment or flags")
3435

36+
const (
37+
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."
38+
)
39+
3540
// PiholeProvider is an implementation of Provider for Pi-hole Local DNS.
3641
type PiholeProvider struct {
3742
provider.BaseProvider
@@ -69,6 +74,7 @@ func NewPiholeProvider(cfg PiholeConfig) (*PiholeProvider, error) {
6974
case "6":
7075
api, err = newPiholeClientV6(cfg)
7176
default:
77+
log.Warn(warningMsg)
7278
api, err = newPiholeClient(cfg)
7379
}
7480
if err != nil {

provider/pihole/pihole_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import (
2121
"reflect"
2222
"testing"
2323

24+
log "github.com/sirupsen/logrus"
25+
"github.com/stretchr/testify/require"
2426
"sigs.k8s.io/external-dns/endpoint"
27+
"sigs.k8s.io/external-dns/internal/testutils"
2528
"sigs.k8s.io/external-dns/plan"
2629
)
2730

@@ -81,6 +84,42 @@ func TestNewPiholeProvider(t *testing.T) {
8184
}
8285
}
8386

87+
func TestNewPiholeProvider_APIVersions(t *testing.T) {
88+
tests := []struct {
89+
name string
90+
config PiholeConfig
91+
wantMsg bool
92+
}{
93+
{
94+
name: "API version 5 with server",
95+
config: PiholeConfig{
96+
APIVersion: "5",
97+
Server: "test.example.com",
98+
},
99+
wantMsg: true,
100+
},
101+
{
102+
name: "API version 6 with server",
103+
config: PiholeConfig{
104+
APIVersion: "6",
105+
Server: "test.example.com",
106+
},
107+
wantMsg: false,
108+
},
109+
}
110+
111+
for _, tt := range tests {
112+
t.Run(tt.name, func(t *testing.T) {
113+
hook := testutils.LogsUnderTestWithLogLevel(log.DebugLevel, t)
114+
_, err := NewPiholeProvider(tt.config)
115+
require.NoError(t, err)
116+
if tt.wantMsg {
117+
testutils.TestHelperLogContains(warningMsg, hook, t)
118+
}
119+
})
120+
}
121+
}
122+
84123
func TestProvider_InitialState(t *testing.T) {
85124
requests := requestTracker{}
86125
p := &PiholeProvider{

0 commit comments

Comments
 (0)