From 73d1855e8e74fd360e111be998d13e190f200b67 Mon Sep 17 00:00:00 2001 From: Anthony TREUILLIER Date: Fri, 5 Apr 2024 11:54:01 +0200 Subject: [PATCH] feat: implement SecretLoader as interface and enforce Fluentd tests using specific implementation Signed-off-by: Anthony TREUILLIER --- apis/fluentd/v1alpha1/plugins/secret_types.go | 10 ++- .../fluentd-cluster-cfg-output-loki.cfg | 3 + .../fluentd-mixed-cfgs-output-copy-1.cfg | 3 + .../fluentd-mixed-cfgs-output-copy-4.cfg | 2 + apis/fluentd/v1alpha1/tests/helper_test.go | 36 +++++++- apis/fluentd/v1alpha1/tests/tools.go | 84 +++++++++++++++---- 6 files changed, 117 insertions(+), 21 deletions(-) diff --git a/apis/fluentd/v1alpha1/plugins/secret_types.go b/apis/fluentd/v1alpha1/plugins/secret_types.go index 162835037..d633158ce 100644 --- a/apis/fluentd/v1alpha1/plugins/secret_types.go +++ b/apis/fluentd/v1alpha1/plugins/secret_types.go @@ -23,19 +23,23 @@ type ValueSource struct { SecretKeyRef corev1.SecretKeySelector `json:"secretKeyRef,omitempty"` } -type SecretLoader struct { +type SecretLoader interface { + LoadSecret(s Secret) (string, error) +} + +type SecretLoaderStruct struct { client client.Client namespace string } func NewSecretLoader(c client.Client, ns string, l logr.Logger) SecretLoader { - return SecretLoader{ + return SecretLoaderStruct{ client: c, namespace: ns, } } -func (sl SecretLoader) LoadSecret(s Secret) (string, error) { +func (sl SecretLoaderStruct) LoadSecret(s Secret) (string, error) { var secret corev1.Secret if err := sl.client.Get(context.Background(), client.ObjectKey{Name: s.ValueFrom.SecretKeyRef.Name, Namespace: sl.namespace}, &secret); err != nil { return "", err diff --git a/apis/fluentd/v1alpha1/tests/expected/fluentd-cluster-cfg-output-loki.cfg b/apis/fluentd/v1alpha1/tests/expected/fluentd-cluster-cfg-output-loki.cfg index 64c3f6304..d0e4fd1bb 100644 --- a/apis/fluentd/v1alpha1/tests/expected/fluentd-cluster-cfg-output-loki.cfg +++ b/apis/fluentd/v1alpha1/tests/expected/fluentd-cluster-cfg-output-loki.cfg @@ -30,8 +30,11 @@ extract_kubernetes_labels true include_thread_label true insecure_tls true + password s3cr3tP@ssword remove_keys key31,key32 + tenant 0c3ba7a4-3148-4605-b62a-afc92dd1c4d7 url http://loki-logging-data.kubesphere-logging-system.svc:3100 + username s3cr3tUsern4me