Skip to content

Commit

Permalink
Discover namespaces with fluentdconfig too if migration mode is enabl…
Browse files Browse the repository at this point in the history
…ed (#310)

Signed-off-by: Jonas Rutishauser <[email protected]>

Signed-off-by: Jonas Rutishauser <[email protected]>
  • Loading branch information
jonasrutishauser authored Dec 2, 2022
1 parent 9551d88 commit eadeed0
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions config-reloader/datasource/kube_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit eadeed0

Please sign in to comment.