@@ -23,6 +23,7 @@ import (
2323 dorisv1 "github.com/apache/doris-operator/api/doris/v1"
2424 utils "github.com/apache/doris-operator/pkg/common/utils"
2525 "github.com/apache/doris-operator/pkg/common/utils/k8s"
26+ "github.com/apache/doris-operator/pkg/common/utils/mysql"
2627 "github.com/apache/doris-operator/pkg/common/utils/resource"
2728 "github.com/apache/doris-operator/pkg/common/utils/set"
2829 appv1 "k8s.io/api/apps/v1"
@@ -32,6 +33,8 @@ import (
3233 "k8s.io/apimachinery/pkg/types"
3334 "k8s.io/client-go/tools/record"
3435 "k8s.io/klog/v2"
36+ "path"
37+ "path/filepath"
3538 "sigs.k8s.io/controller-runtime/pkg/client"
3639 "strconv"
3740 "strings"
@@ -280,6 +283,41 @@ func (d *SubDefaultController) CheckSecretExist(ctx context.Context, dcr *dorisv
280283 }
281284}
282285
286+ // FindSecretTLSConfig reads TLS configuration from FE config map and returns
287+ // the TLS config and secret name for establishing TLS-enabled MySQL connections.
288+ func (d * SubDefaultController ) FindSecretTLSConfig (feConfMap map [string ]interface {}, dcr * dorisv1.DorisCluster ) (* mysql.TLSConfig , string ) {
289+ enableTLS := resource .GetString (feConfMap , resource .ENABLE_TLS_KEY )
290+ if enableTLS == "" {
291+ return nil , ""
292+ }
293+
294+ caCertFile := resource .GetString (feConfMap , resource .TLS_CA_CERTIFICATE_PATH_KEY )
295+ clientCertFile := resource .GetString (feConfMap , resource .TLS_CERTIFICATE_PATH_KEY )
296+ clientKeyFile := resource .GetString (feConfMap , resource .TLS_PRIVATE_KEY_PATH_KEY )
297+ caFileName := path .Base (caCertFile )
298+ clientCertFileName := path .Base (clientCertFile )
299+ clientKeyFileName := path .Base (clientKeyFile )
300+
301+ caCertDir := filepath .Dir (caCertFile )
302+ secretName := ""
303+ if dcr .Spec .FeSpec != nil {
304+ for _ , sn := range dcr .Spec .FeSpec .Secrets {
305+ if sn .MountPath == caCertDir {
306+ secretName = sn .SecretName
307+ break
308+ }
309+ }
310+ }
311+
312+ tlsConfig := & mysql.TLSConfig {
313+ CAFileName : caFileName ,
314+ ClientCertFileName : clientCertFileName ,
315+ ClientKeyFileName : clientKeyFileName ,
316+ }
317+
318+ return tlsConfig , secretName
319+ }
320+
283321// CheckSharedPVC verifies two points:
284322// 1. Whether the SharePVC exists
285323// 2. Whether the AccessMode of the SharePVC is ReadWriteMany
0 commit comments