From 78797ecf7fb8f35cc2cf9900716c632ab6fee91d Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Mon, 4 Nov 2024 17:34:22 +0100 Subject: [PATCH 1/2] fix: ensure input CAbundle always end with a newline - missing newline will cause problem when inject data into configmap - this happens when user use kustomize with their own CA for DSCI, it set to use |- not | - fix lint Signed-off-by: Wen Zhou --- pkg/trustedcabundle/trustedcabundle.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/trustedcabundle/trustedcabundle.go b/pkg/trustedcabundle/trustedcabundle.go index 5be58c77283..8567ee23571 100644 --- a/pkg/trustedcabundle/trustedcabundle.go +++ b/pkg/trustedcabundle/trustedcabundle.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "strconv" + "strings" "time" "github.com/go-logr/logr" @@ -47,6 +48,10 @@ func HasCABundleAnnotationDisabled(ns client.Object) bool { // or update existing odh-trusted-ca-bundle configmap if already exists with new content of .data.odh-ca-bundle.crt // this is certificates for the cluster trusted CA Cert Bundle. func CreateOdhTrustedCABundleConfigMap(ctx context.Context, cli client.Client, namespace string, customCAData string) error { + // Adding newline breaker if user input does not have it + if !strings.HasSuffix(customCAData, "\n") { + customCAData += "\n" + } // Expected configmap for the given namespace desiredConfigMap := &corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ From dd0393f9c7b13fe22459a9b36a6aa52c0193e32e Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Wed, 6 Nov 2024 09:50:37 +0100 Subject: [PATCH 2/2] update: better way to add newline Signed-off-by: Wen Zhou --- pkg/trustedcabundle/trustedcabundle.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/trustedcabundle/trustedcabundle.go b/pkg/trustedcabundle/trustedcabundle.go index 8567ee23571..41a9ab2ef8b 100644 --- a/pkg/trustedcabundle/trustedcabundle.go +++ b/pkg/trustedcabundle/trustedcabundle.go @@ -49,9 +49,8 @@ func HasCABundleAnnotationDisabled(ns client.Object) bool { // this is certificates for the cluster trusted CA Cert Bundle. func CreateOdhTrustedCABundleConfigMap(ctx context.Context, cli client.Client, namespace string, customCAData string) error { // Adding newline breaker if user input does not have it - if !strings.HasSuffix(customCAData, "\n") { - customCAData += "\n" - } + customCAData = strings.TrimSpace(customCAData) + "\n" + // Expected configmap for the given namespace desiredConfigMap := &corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{