@@ -27,7 +27,6 @@ import (
2727 "k8s.io/client-go/metadata"
2828 "net/http"
2929 "os"
30- "sigs.k8s.io/controller-runtime/pkg/client/apiutil"
3130 "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3231 "sigs.k8s.io/controller-runtime/pkg/webhook"
3332 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -112,6 +111,10 @@ func main() {
112111 errgrp , errGroupCtx := errgroup .WithContext (signals .SetupSignalHandler ())
113112
114113 dnsCache := dnscache .NewDNSCache ()
114+ dnsPublisher , dnsPublisherEnabled , err := dnsintentspublisher .InitWithManager (errGroupCtx , mgr , dnsCache )
115+ if err != nil {
116+ logrus .WithError (err ).Panic ("Failed to initialize DNS publisher" )
117+ }
115118
116119 mapperServer := echo .New ()
117120 mapperServer .HideBanner = true
@@ -259,9 +262,12 @@ func main() {
259262 intentsHolder .RegisterNotifyIntents (otelExporter .NotifyIntents )
260263 }
261264
262- err = StartDNSClientIntentsPublisher (mgr , dnsCache , errGroupCtx , errgrp )
263- if err != nil {
264- logrus .WithError (err ).Panic ("failed to initialize DNS client intents publisher" )
265+ if dnsPublisherEnabled {
266+ errgrp .Go (func () error {
267+ defer errorreporter .AutoNotify ()
268+ dnsPublisher .RunForever (errGroupCtx )
269+ return nil
270+ })
265271 }
266272
267273 errgrp .Go (func () error {
@@ -311,31 +317,6 @@ func main() {
311317 }
312318}
313319
314- func StartDNSClientIntentsPublisher (mgr manager.Manager , dnsCache * dnscache.DNSCache , errGroupCtx context.Context , errgrp * errgroup.Group ) error {
315- if viper .GetBool (config .DNSClientIntentsUpdateEnabledKey ) {
316- dnsPublisher := dnsintentspublisher .NewPublisher (mgr .GetClient (), dnsCache )
317- err := dnsPublisher .InitIndices (errGroupCtx , mgr )
318- if err != nil {
319- if discoveryErr := (& apiutil.ErrResourceDiscoveryFailed {}); errors .As (err , & discoveryErr ) {
320- for gvk := range * discoveryErr {
321- if gvk .Group == "k8s.otterize.com" {
322- logrus .Debugf ("DNS client intents publishing is not enabled due to missing CRD %v" , gvk )
323- // This can happen if the network mapper is deployed without the intents operator, which is normal.
324- return nil
325- }
326- }
327- }
328- return errors .Wrap (err )
329- }
330- errgrp .Go (func () error {
331- defer errorreporter .AutoNotify ()
332- dnsPublisher .RunForever (errGroupCtx )
333- return nil
334- })
335- }
336- return nil
337- }
338-
339320func shutdownGracefullyOnCancel (errGroupCtx context.Context , server * echo.Echo ) {
340321 <- errGroupCtx .Done ()
341322 timeoutCtx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
0 commit comments