From 360247556ea74f7ffcc4b6121ae16d502cb1720e Mon Sep 17 00:00:00 2001 From: zhu733756 Date: Fri, 11 Feb 2022 15:20:17 +0800 Subject: [PATCH] refactor selectors in clusterfluentdconfig/fluentdconfig Signed-off-by: zhu733756 --- .../v1alpha1/clusterfluentdconfig_types.go | 4 +- apis/fluentd/v1alpha1/fluentdconfig_types.go | 12 +- apis/fluentd/v1alpha1/helper.go | 4 +- .../v1alpha1/tests/expected-main-cfgs.cfg | 28 ++--- .../fluentd/v1alpha1/zz_generated.deepcopy.go | 49 ++++++-- ...uentd.fluent.io_clusterfluentdconfigs.yaml | 20 ++-- .../fluentd.fluent.io_fluentdconfigs.yaml | 92 +++++++++++++- controllers/fluentdconfig_controller.go | 63 +++++----- ...ntd-cluster-cfg-output-buffer-example.yaml | 6 +- .../fluentd-cluster-cfg-output-es.yaml | 4 +- .../fluentd-cluster-cfg-output-kafka.yaml | 6 +- ...luentd-mixed-cfgs-multi-tenant-output.yaml | 29 +++-- .../forward/fluentd-mixed-cfgs-output-es.yaml | 6 +- .../fluentd-namespaced-cfg-output-es.yaml | 2 +- manifests/setup/fluent-operator-crd.yaml | 112 ++++++++++++++++-- manifests/setup/setup.yaml | 112 ++++++++++++++++-- 16 files changed, 425 insertions(+), 124 deletions(-) diff --git a/apis/fluentd/v1alpha1/clusterfluentdconfig_types.go b/apis/fluentd/v1alpha1/clusterfluentdconfig_types.go index db16fabdc..b2d26a631 100644 --- a/apis/fluentd/v1alpha1/clusterfluentdconfig_types.go +++ b/apis/fluentd/v1alpha1/clusterfluentdconfig_types.go @@ -40,9 +40,9 @@ type ClusterFluentdConfigSpec struct { // Use this field to filter the logs, will make no effect if EnableFilterKubernetes is set false. WatchedLabels map[string]string `json:"watchedLabels,omitempty"` // Select filter plugins - FilterSelector metav1.LabelSelector `json:"filterSelector,omitempty"` + ClusterFilterSelector *metav1.LabelSelector `json:"clusterFilterSelector,omitempty"` // Select output plugins - OutputSelector metav1.LabelSelector `json:"outputSelector,omitempty"` + ClusterOutputSelector *metav1.LabelSelector `json:"clusterOutputSelector,omitempty"` } // ClusterFluentdConfigStatus defines the observed state of ClusterFluentdConfig diff --git a/apis/fluentd/v1alpha1/fluentdconfig_types.go b/apis/fluentd/v1alpha1/fluentdconfig_types.go index 701a86460..8e252016f 100644 --- a/apis/fluentd/v1alpha1/fluentdconfig_types.go +++ b/apis/fluentd/v1alpha1/fluentdconfig_types.go @@ -37,10 +37,14 @@ type FluentdConfigSpec struct { WatchedContainers []string `json:"watchedConstainers,omitempty"` // Use this field to filter the logs, will make no effect if EnableFilterKubernetes is set false. WatchedLabels map[string]string `json:"watchedLabels,omitempty"` - // Select filter plugins - FilterSelector metav1.LabelSelector `json:"filterSelector,omitempty"` - // Select output plugins - OutputSelector metav1.LabelSelector `json:"outputSelector,omitempty"` + // Select namespaced filter plugins + FilterSelector *metav1.LabelSelector `json:"filterSelector,omitempty"` + // Select namespaced output plugins + OutputSelector *metav1.LabelSelector `json:"outputSelector,omitempty"` + // Select clusterfilter plugins + ClusterFilterSelector *metav1.LabelSelector `json:"clusterFilterSelector,omitempty"` + // Select clusteroutput plugins + ClusterOutputSelector *metav1.LabelSelector `json:"clusterOutputSelector,omitempty"` } // FluentdConfigStatus defines the observed state of FluentdConfig diff --git a/apis/fluentd/v1alpha1/helper.go b/apis/fluentd/v1alpha1/helper.go index 8b32b6577..2d7359a4b 100644 --- a/apis/fluentd/v1alpha1/helper.go +++ b/apis/fluentd/v1alpha1/helper.go @@ -164,7 +164,7 @@ func (pgr *PluginResources) PatchAndFilterNamespacedLevelResources(sl plugins.Se func (r *CfgResources) filterForFilters(cfgId, namespace, name, crdtype string, sl plugins.SecretLoader, filters []filter.Filter) error { for n, filter := range filters { - filterId := fmt.Sprintf("%s-%s-%s-%s-%d", cfgId, namespace, crdtype, name, n) + filterId := fmt.Sprintf("%s::%s::%s::%s-%d", cfgId, namespace, crdtype, name, n) filter.FilterCommon.Id = &filterId filter.FilterCommon.Tag = ¶ms.DefaultTag @@ -188,7 +188,7 @@ func (r *CfgResources) filterForFilters(cfgId, namespace, name, crdtype string, func (r *CfgResources) filterForOutputs(cfgId, namespace, name, crdtype string, sl plugins.SecretLoader, outputs []output.Output) error { for n, output := range outputs { - outputId := fmt.Sprintf("%s-%s-%s-%s-%d", cfgId, namespace, crdtype, name, n) + outputId := fmt.Sprintf("%s::%s::%s::%s-%d", cfgId, namespace, crdtype, name, n) output.OutputCommon.Id = &outputId output.OutputCommon.Tag = ¶ms.DefaultTag diff --git a/apis/fluentd/v1alpha1/tests/expected-main-cfgs.cfg b/apis/fluentd/v1alpha1/tests/expected-main-cfgs.cfg index bf5922def..8fd0b9102 100644 --- a/apis/fluentd/v1alpha1/tests/expected-main-cfgs.cfg +++ b/apis/fluentd/v1alpha1/tests/expected-main-cfgs.cfg @@ -30,7 +30,7 @@