Skip to content

Commit

Permalink
fix: unable to start if mismatchtag in config (#412)
Browse files Browse the repository at this point in the history
Fix unable to start if mismatch tag is present in some config

Signed-off-by: jcriadomarco <jcriadomarco@vmware.com>
  • Loading branch information
javiercri authored Aug 3, 2023
1 parent 49bea45 commit 82d2021
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 25 deletions.
5 changes: 3 additions & 2 deletions config-reloader/datasource/kube_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (d *kubeInformerConnection) GetNamespaces(ctx context.Context) ([]*Namespac
fragment, err := fluentd.ParseString(configdata)
if err != nil {
logrus.Errorf("Error parsing config for ns %s: %v", ns, err)
return nil, err
continue
}

var mountedLabels []map[string]string
Expand All @@ -189,7 +189,8 @@ func (d *kubeInformerConnection) GetNamespaces(ctx context.Context) ([]*Namespac
// under consideration
pods, err := d.podlist.Pods(ns).List(labels.NewSelector())
if err != nil {
return nil, err
logrus.Errorf("Error listing pod in ns %s: %v", ns, err)
continue
}
podsCopy := make([]core.Pod, len(pods))
for i, pod := range pods {
Expand Down
70 changes: 47 additions & 23 deletions config-reloader/datasource/kube_informer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type testConfig struct {
expectErr bool
expectedResult int
namespaces []string
configmap map[string]string
configmapData map[string]string
configmap map[string][]string
configmapData map[string]map[string]string
}

func importK8sObjects(factory informers.SharedInformerFactory, namespaces []string, configmaps map[string]string, configmapData map[string]string) {
func importK8sObjects(factory informers.SharedInformerFactory, namespaces []string, configmaps map[string][]string, configmapData map[string]map[string]string) {
for _, ns := range namespaces {
factory.Core().V1().Namespaces().Informer().GetIndexer().Add(
&corev1.Namespace{
Expand All @@ -35,16 +35,18 @@ func importK8sObjects(factory informers.SharedInformerFactory, namespaces []stri
},
)
}
for cm, ns := range configmaps {
factory.Core().V1().ConfigMaps().Informer().GetIndexer().Add(
&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: cm,
Namespace: ns,
for ns, cms := range configmaps {
for _, cm := range cms {
factory.Core().V1().ConfigMaps().Informer().GetIndexer().Add(
&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: cm,
Namespace: ns,
},
Data: configmapData[ns],
},
Data: configmapData,
},
)
)
}
}
}

Expand Down Expand Up @@ -80,10 +82,9 @@ func TestGetNamespaces(t *testing.T) {
"test-empty",
"test-empty-2",
},
configmap: map[string]string{
"fluentd-config": "test-empty",
"my-configmap1": "test-empty",
"my-configmap2": "test-empty-2",
configmap: map[string][]string{
"test-empty": {"fluentd-config", "my-configmap1"},
"test-empty-2": {"my-configmap2"},
},
},
{
Expand All @@ -101,10 +102,34 @@ func TestGetNamespaces(t *testing.T) {
"test-not-empty",
"test-not-empty-2",
},
configmap: map[string]string{
"fluentd-config": "test-not-empty",
configmap: map[string][]string{
"test-not-empty": {"fluentd-config"},
},
configmapData: map[string]map[string]string{"test-not-empty": {"fluent.conf": "<match **>\n@type stdout\n</match>"}},
},
{
//TestCase: Two Namespaces, one fluentd config wrong. Result 1
config: config.Config{
Datasource: "default",
DefaultConfigmapName: "fluentd-config",
AnnotConfigmapName: "logging.csp.vmware.com/fluentd-configmap",
AnnotStatus: "logging.csp.vmware.com/fluentd-status",
ID: "default",
},
expectErr: false,
expectedResult: 1,
namespaces: []string{
"test-not-empty",
"test-not-empty-2",
},
configmap: map[string][]string{
"test-not-empty": {"fluentd-config"},
"test-not-empty-2": {"fluentd-config"},
},
configmapData: map[string]map[string]string{
"test-not-empty": {"fluent.conf": "<match **>\n@type stdout\n</match>"},
"test-not-empty-2": {"fluent.conf": "<filter **>\n></filter><match **>\n@type stdout\n</match>"},
},
configmapData: map[string]string{"fluent.conf": "<match **>\n@type stdout\n</match>"},
},
}
for _, config := range configs {
Expand Down Expand Up @@ -169,10 +194,9 @@ func TestDiscoverNamespaces(t *testing.T) {
"test1",
"test2",
},
configmap: map[string]string{
"configmap1": "test1",
"configmap2": "test2",
"fluentd-config": "test1",
configmap: map[string][]string{
"test1": {"configmap1", "fluentd-config"},
"test2": {"configmap2"},
},
},
}
Expand Down

0 comments on commit 82d2021

Please sign in to comment.