Skip to content

Commit 9121f82

Browse files
committed
Fix #1: add --default-configmap
If a configmap exists on the namespace then there is no need to annotate it. Use --default-configmap="" if the default cannot be used for some reason.
1 parent 34673ad commit 9121f82

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

config-reloader/config/config.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Config struct {
3131
LogLevel string
3232
AnnotConfigmapName string
3333
AnnotStatus string
34+
DefaultConfigmapName string
3435
IntervalSeconds int
3536
Datasource string
3637
FsDatasourceDir string
@@ -45,17 +46,18 @@ type Config struct {
4546
}
4647

4748
var defaultConfig = &Config{
48-
Master: "",
49-
KubeConfig: "",
50-
FluentdRPCPort: 24444,
51-
TemplatesDir: "/templates",
52-
OutputDir: "/fluentd/etc",
53-
Datasource: "default",
54-
LogLevel: logrus.InfoLevel.String(),
55-
AnnotConfigmapName: "logging.csp.vmware.com/fluentd-configmap",
56-
AnnotStatus: "logging.csp.vmware.com/fluentd-status",
57-
IntervalSeconds: 60,
58-
ID: "default",
49+
Master: "",
50+
KubeConfig: "",
51+
FluentdRPCPort: 24444,
52+
TemplatesDir: "/templates",
53+
OutputDir: "/fluentd/etc",
54+
Datasource: "default",
55+
LogLevel: logrus.InfoLevel.String(),
56+
AnnotConfigmapName: "logging.csp.vmware.com/fluentd-configmap",
57+
AnnotStatus: "logging.csp.vmware.com/fluentd-status",
58+
DefaultConfigmapName: "fluentd-config",
59+
IntervalSeconds: 60,
60+
ID: "default",
5961
}
6062

6163
var reValidID = regexp.MustCompile("([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]")
@@ -156,6 +158,7 @@ func (cfg *Config) ParseFlags(args []string) error {
156158
app.Flag("fluentd-rpc-port", "RPC port of Fluentd").Default(strconv.Itoa(defaultConfig.FluentdRPCPort)).IntVar(&cfg.FluentdRPCPort)
157159
app.Flag("log-level", "Control verbosity of log").Default(defaultConfig.LogLevel).StringVar(&cfg.LogLevel)
158160
app.Flag("annotation", "Which annotation on the namespace stores the configmap name?").Default(defaultConfig.AnnotConfigmapName).StringVar(&cfg.AnnotConfigmapName)
161+
app.Flag("default-configmap", "Read the configmap by this name if namespace is not annotated. Use empty string to suppress the default.").Default(defaultConfig.DefaultConfigmapName).StringVar(&cfg.DefaultConfigmapName)
159162
app.Flag("status-annotation", "Store configuration errors in this annotation, leave empty to turn off").Default(defaultConfig.AnnotStatus).StringVar(&cfg.AnnotStatus)
160163

161164
app.Flag("templates-dir", "Where to find templates").Default(defaultConfig.TemplatesDir).StringVar(&cfg.TemplatesDir)

config-reloader/datasource/kube.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@ func (d *kubeConnection) GetNamespaces() ([]*NamespaceConfig, error) {
6262
for _, item := range resp.Items {
6363
configMapName := item.Annotations[d.cfg.AnnotConfigmapName]
6464
if configMapName == "" {
65-
logrus.Debugf("Will not process namespace '%s': not annotated with '%s'", item.Name, d.cfg.AnnotConfigmapName)
66-
// namespace not annotated
67-
result = append(result, d.unconfiguredNamespace(item.Name))
68-
continue
65+
if d.cfg.DefaultConfigmapName != "" {
66+
configMapName = d.cfg.DefaultConfigmapName
67+
logrus.Debugf("Using default configmap for namespace '%s'", item.Name)
68+
} else {
69+
logrus.Debugf("Will not process namespace '%s': not annotated with '%s'", item.Name, d.cfg.AnnotConfigmapName)
70+
// namespace not annotated
71+
result = append(result, d.unconfiguredNamespace(item.Name))
72+
continue
73+
}
6974
}
7075

7176
contents, err := d.readConfig(item.Name, configMapName)

0 commit comments

Comments
 (0)