From eadeed06dd46b6aa8d4ecd27c00ce363d6ef5cd3 Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Fri, 2 Dec 2022 16:15:44 +0100 Subject: [PATCH] Discover namespaces with fluentdconfig too if migration mode is enabled (#310) Signed-off-by: Jonas Rutishauser Signed-off-by: Jonas Rutishauser --- config-reloader/datasource/kube_informer.go | 36 +++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/config-reloader/datasource/kube_informer.go b/config-reloader/datasource/kube_informer.go index 748da019..686480aa 100644 --- a/config-reloader/datasource/kube_informer.go +++ b/config-reloader/datasource/kube_informer.go @@ -145,18 +145,11 @@ func (d *kubeInformerConnection) discoverNamespaces(ctx context.Context) ([]stri } else { if d.cfg.Datasource == "crd" { logrus.Infof("Discovering only namespaces that have fluentdconfig crd defined.") - if d.fdlist == nil { - return nil, fmt.Errorf("Failed to initialize the fluentdconfig crd client, d.fclient = nil") - } - fcList, err := d.fdlist.List(labels.NewSelector()) + nsList, err := d.discoverFluentdConfigNamespaces() if err != nil { - return nil, fmt.Errorf("Failed to list all fluentdconfig crds in cluster: %v", err) - } - namespaces = make([]string, 0) - for _, crd := range fcList { - namespaces = append(namespaces, crd.ObjectMeta.Namespace) + return nil, err } - logrus.Debugf("Returned these namespaces for fluentdconfig crds: %v", namespaces) + namespaces = nsList } else { // Find the configmaps that exist on this cluster to find namespaces: confMapsList, err := d.cmlist.List(labels.NewSelector()) @@ -170,6 +163,13 @@ func (d *kubeInformerConnection) discoverNamespaces(ctx context.Context) ([]stri namespaces = append(namespaces, cfmap.ObjectMeta.Namespace) } } + if d.cfg.CRDMigrationMode { + nsList, err := d.discoverFluentdConfigNamespaces() + if err != nil { + return nil, err + } + namespaces = append(namespaces, nsList...) + } } else { // get all namespaces and iterrate through them like before: nses, err := d.nslist.List(labels.NewSelector()) @@ -197,6 +197,22 @@ func (d *kubeInformerConnection) discoverNamespaces(ctx context.Context) ([]stri return nsList, nil } +func (d *kubeInformerConnection) discoverFluentdConfigNamespaces() ([]string, error) { + if d.fdlist == nil { + return nil, fmt.Errorf("Failed to initialize the fluentdconfig crd client, d.fclient = nil") + } + fcList, err := d.fdlist.List(labels.NewSelector()) + if err != nil { + return nil, fmt.Errorf("Failed to list all fluentdconfig crds in cluster: %v", err) + } + nsList := make([]string, 0) + for _, crd := range fcList { + nsList = append(nsList, crd.ObjectMeta.Namespace) + } + logrus.Debugf("Returned these namespaces for fluentdconfig crds: %v", nsList) + return nsList, nil +} + // NewKubernetesInformerDatasource builds a new Datasource from the provided config. // The returned Datasource uses Informers to efficiently track objects in the kubernetes // API by watching for updates to a known state.