From c8eb9f7e861780acf748ff258b6b8274a61365d2 Mon Sep 17 00:00:00 2001 From: Krise <17857459+krise86@users.noreply.github.com> Date: Mon, 25 Jul 2022 19:32:38 +0200 Subject: [PATCH] fix: Resolved issue with kafka secret not returning SASL and TLS (#628) Signed-off-by: Kristoffer Olafsen --- runner/sidecar/kafka.go | 11 +++++++++-- runner/sidecar/kafka_test.go | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/runner/sidecar/kafka.go b/runner/sidecar/kafka.go index 83b72208..479183bf 100644 --- a/runner/sidecar/kafka.go +++ b/runner/sidecar/kafka.go @@ -15,11 +15,18 @@ func kafkaFromSecret(k *dfv1.Kafka, secret *corev1.Secret) error { tls := tlsFromSecret(secret) sasl := saslFromSecret(secret) + + if tls == nil && sasl == nil { + return nil + } + + k.NET = &dfv1.KafkaNET{} + if tls != nil { - k.NET = &dfv1.KafkaNET{TLS: tls} + k.NET.TLS = tls } if sasl != nil { - k.NET = &dfv1.KafkaNET{SASL: sasl} + k.NET.SASL = sasl } return nil } diff --git a/runner/sidecar/kafka_test.go b/runner/sidecar/kafka_test.go index 5d3fc168..933ec170 100644 --- a/runner/sidecar/kafka_test.go +++ b/runner/sidecar/kafka_test.go @@ -51,6 +51,21 @@ func Test_kafkaFromSecret(t *testing.T) { assert.NotNil(t, x.NET.SASL) } }) + t.Run("NetSASLAndTLS", func(t *testing.T) { + x := &dfv1.Kafka{} + err := kafkaFromSecret(x, &corev1.Secret{ + Data: map[string][]byte{ + "net.sasl.user": []byte(""), + "net.sasl.password": []byte(""), + "net.tls.caCert": []byte(""), + }, + }) + assert.NoError(t, err) + if assert.NotNil(t, x.NET) { + assert.NotNil(t, x.NET.SASL) + assert.NotNil(t, x.NET.TLS) + } + }) } func Test_enrichKafka(t *testing.T) {