diff --git a/.golangci.yml b/.golangci.yml index 2ac950c..3a2ebf2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -29,7 +29,6 @@ linters: - unconvert - unparam - unused - - wastedassign linters-settings: gosec: # Exclude generated files diff --git a/pkg/sync/sync.go b/pkg/sync/sync.go index f967543..df9193b 100644 --- a/pkg/sync/sync.go +++ b/pkg/sync/sync.go @@ -173,10 +173,12 @@ func (w *worker) sync() { return } - o.dhcpServerConfig, err = oc.DHCPServerConfig() - if err != nil { - sl.With("error", err).Error("Error getting dhcp server config") - return + if w.cfg.Features.DHCP.ServerConfig || w.cfg.Features.DHCP.StaticLeases { + o.dhcpServerConfig, err = oc.DHCPServerConfig() + if err != nil { + sl.With("error", err).Error("Error getting dhcp server config") + return + } } replicas := w.cfg.UniqueReplicas() @@ -256,9 +258,11 @@ func (w *worker) syncTo(l *zap.SugaredLogger, o *origin, replica types.AdGuardIn return } - if err = w.syncDHCPServer(o.dhcpServerConfig, rc, replica); err != nil { - rl.With("error", err).Error("Error syncing dns") - return + if w.cfg.Features.DHCP.ServerConfig || w.cfg.Features.DHCP.StaticLeases { + if err = w.syncDHCPServer(o.dhcpServerConfig, rc, replica); err != nil { + rl.With("error", err).Error("Error syncing dns") + return + } } rl.Info("Sync done") @@ -475,6 +479,9 @@ func (w *worker) syncDNS(oal *types.AccessList, odc *types.DNSConfig, rc client. } func (w *worker) syncDHCPServer(osc *types.DHCPServerConfig, rc client.Client, replica types.AdGuardInstance) error { + if !w.cfg.Features.DHCP.ServerConfig && !w.cfg.Features.DHCP.StaticLeases { + return nil + } sc, err := rc.DHCPServerConfig() if w.cfg.Features.DHCP.ServerConfig { if err != nil { diff --git a/pkg/sync/sync_test.go b/pkg/sync/sync_test.go index fb18c76..b5f069e 100644 --- a/pkg/sync/sync_test.go +++ b/pkg/sync/sync_test.go @@ -528,6 +528,51 @@ var _ = Describe("Sync", func() { cl.EXPECT().DeleteDHCPStaticLeases().Return(nil) w.sync() }) + It("should not sync DHCP", func() { + w.cfg.Features.DHCP.ServerConfig = false + w.cfg.Features.DHCP.StaticLeases = false + // origin + cl.EXPECT().Host() + cl.EXPECT().Status().Return(&types.Status{Version: versions.MinAgh}, nil) + cl.EXPECT().Parental() + cl.EXPECT().SafeSearch() + cl.EXPECT().SafeBrowsing() + cl.EXPECT().RewriteList().Return(&types.RewriteEntries{}, nil) + cl.EXPECT().Services() + cl.EXPECT().Filtering().Return(&types.FilteringStatus{}, nil) + cl.EXPECT().Clients().Return(&types.Clients{}, nil) + cl.EXPECT().QueryLogConfig().Return(&types.QueryLogConfig{}, nil) + cl.EXPECT().StatsConfig().Return(&types.IntervalConfig{}, nil) + cl.EXPECT().AccessList().Return(&types.AccessList{}, nil) + cl.EXPECT().DNSConfig().Return(&types.DNSConfig{}, nil) + + // replica + cl.EXPECT().Host() + cl.EXPECT().Status().Return(&types.Status{Version: versions.MinAgh}, nil) + cl.EXPECT().Parental() + cl.EXPECT().SafeSearch() + cl.EXPECT().SafeBrowsing() + cl.EXPECT().QueryLogConfig().Return(&types.QueryLogConfig{}, nil) + cl.EXPECT().StatsConfig().Return(&types.IntervalConfig{}, nil) + cl.EXPECT().RewriteList().Return(&types.RewriteEntries{}, nil) + cl.EXPECT().AddRewriteEntries() + cl.EXPECT().DeleteRewriteEntries() + cl.EXPECT().Filtering().Return(&types.FilteringStatus{}, nil) + cl.EXPECT().AddFilters(false) + cl.EXPECT().UpdateFilters(false) + cl.EXPECT().DeleteFilters(false) + cl.EXPECT().AddFilters(true) + cl.EXPECT().UpdateFilters(true) + cl.EXPECT().DeleteFilters(true) + cl.EXPECT().Services() + cl.EXPECT().Clients().Return(&types.Clients{}, nil) + cl.EXPECT().AddClients() + cl.EXPECT().UpdateClients() + cl.EXPECT().DeleteClients() + cl.EXPECT().AccessList().Return(&types.AccessList{}, nil) + cl.EXPECT().DNSConfig().Return(&types.DNSConfig{}, nil) + w.sync() + }) It("origin version is too small", func() { // origin cl.EXPECT().Host()