From 33fe8430aa1c4f2ddd2e9492ad5f7b5c1244e53f Mon Sep 17 00:00:00 2001 From: chenfei Date: Fri, 25 Oct 2024 18:19:50 +0800 Subject: [PATCH] optimize code --- pkg/manager/member/ticdc_member_manager.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/manager/member/ticdc_member_manager.go b/pkg/manager/member/ticdc_member_manager.go index 21d88d684b6..5a06f3006af 100644 --- a/pkg/manager/member/ticdc_member_manager.go +++ b/pkg/manager/member/ticdc_member_manager.go @@ -391,10 +391,6 @@ func getNewTiCDCStatefulSet(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap) (*ap vols = append(vols, annVolume) } - clusterTLSSecretName := util.ClusterTLSSecretName(tc.Name, label.TiCDCLabelVal) - if tc.Spec.TiCDC.ClusterTLSSecretName != "" { - clusterTLSSecretName = tc.Spec.TiCDC.ClusterTLSSecretName - } if tc.IsTLSClusterEnabled() { volMounts = append(volMounts, corev1.VolumeMount{ Name: ticdcCertVolumeMount, @@ -409,7 +405,7 @@ func getNewTiCDCStatefulSet(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap) (*ap vols = append(vols, corev1.Volume{ Name: ticdcCertVolumeMount, VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: clusterTLSSecretName, + SecretName: getTiCDCClusterTLSCertSecretName(tc), }, }, }, corev1.Volume{ @@ -570,6 +566,15 @@ func getNewTiCDCStatefulSet(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap) (*ap return ticdcSts, nil } +func getTiCDCClusterTLSCertSecretName(tc *v1alpha1.TidbCluster) string { + clusterTLSSecretName := util.ClusterTLSSecretName(tc.Name, label.TiCDCLabelVal) + if tc.Spec.TiCDC.ClusterTLSSecretName != "" { + clusterTLSSecretName = tc.Spec.TiCDC.ClusterTLSSecretName + } + + return clusterTLSSecretName +} + func labelTiCDC(tc *v1alpha1.TidbCluster) label.Label { instanceName := tc.GetInstanceName() return label.New().Instance(instanceName).TiCDC()