From b51e93ee86a711e561e1426e23f1843b38c04ca3 Mon Sep 17 00:00:00 2001 From: catpineapple Date: Wed, 13 Nov 2024 16:52:04 +0800 Subject: [PATCH] fix service access in diff namespace --- api/disaggregated/v1/unique_id.go | 4 ++++ .../disaggregated_cluster/computegroups/controller.go | 3 +-- .../disaggregated_cluster/computegroups/statefulset.go | 2 +- .../disaggregated_cluster/disaggregated_fe/controller.go | 3 +-- .../disaggregated_cluster/disaggregated_fe/statefulset.go | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/disaggregated/v1/unique_id.go b/api/disaggregated/v1/unique_id.go index db4b72b..54a97b3 100644 --- a/api/disaggregated/v1/unique_id.go +++ b/api/disaggregated/v1/unique_id.go @@ -68,6 +68,10 @@ func (ddc *DorisDisaggregatedCluster) GetFEServiceName() string { return ddc.Name + "-" + "fe" } +func (ddc *DorisDisaggregatedCluster) GetFEServiceNameForAccess() string { + return ddc.GetFEServiceName() + "." + ddc.Namespace +} + func (ddc *DorisDisaggregatedCluster) GetFEInternalServiceName() string { return ddc.Name + "-" + "fe-internal" } diff --git a/pkg/controller/sub_controller/disaggregated_cluster/computegroups/controller.go b/pkg/controller/sub_controller/disaggregated_cluster/computegroups/controller.go index 330cf76..89fe9ec 100644 --- a/pkg/controller/sub_controller/disaggregated_cluster/computegroups/controller.go +++ b/pkg/controller/sub_controller/disaggregated_cluster/computegroups/controller.go @@ -496,9 +496,8 @@ func (dcgs *DisaggregatedComputeGroupsController) scaledOutBENodesBySQL( adminUserName, password := resource.GetDorisLoginInformation(secret) // get host and port - serviceName := cluster.GetFEServiceName() // When the operator and dcr are deployed in different namespace, it will be inaccessible, so need to add the dcr svc namespace - host := serviceName + "." + cluster.Namespace + host := cluster.GetFEServiceNameForAccess() confMap := dcgs.GetConfigValuesFromConfigMaps(cluster.Namespace, resource.FE_RESOLVEKEY, cluster.Spec.FeSpec.ConfigMaps) queryPort := resource.GetPort(confMap, resource.QUERY_PORT) diff --git a/pkg/controller/sub_controller/disaggregated_cluster/computegroups/statefulset.go b/pkg/controller/sub_controller/disaggregated_cluster/computegroups/statefulset.go index 7f67f71..f2ccb5a 100644 --- a/pkg/controller/sub_controller/disaggregated_cluster/computegroups/statefulset.go +++ b/pkg/controller/sub_controller/disaggregated_cluster/computegroups/statefulset.go @@ -319,7 +319,7 @@ func (dcgs *DisaggregatedComputeGroupsController) newSpecificEnvs(ddc *dv1.Doris fqp := resource.GetPort(confMap, resource.QUERY_PORT) fqpStr := strconv.FormatInt(int64(fqp), 10) //use fe service name as access address. - feAddr := ddc.GetFEServiceName() + feAddr := ddc.GetFEServiceNameForAccess() cgEnvs = append(cgEnvs, corev1.EnvVar{Name: resource.STATEFULSET_NAME, Value: stsName}, corev1.EnvVar{Name: resource.COMPUTE_GROUP_NAME, Value: ddc.GetCGName(cg)}, diff --git a/pkg/controller/sub_controller/disaggregated_cluster/disaggregated_fe/controller.go b/pkg/controller/sub_controller/disaggregated_cluster/disaggregated_fe/controller.go index a76eb27..6db0315 100644 --- a/pkg/controller/sub_controller/disaggregated_cluster/disaggregated_fe/controller.go +++ b/pkg/controller/sub_controller/disaggregated_cluster/disaggregated_fe/controller.go @@ -308,9 +308,8 @@ func (dfc *DisaggregatedFEController) dropFEBySQLClient(ctx context.Context, k8s adminUserName, password := resource.GetDorisLoginInformation(secret) // get host and port - serviceName := cluster.GetFEServiceName() // When the operator and dcr are deployed in different namespace, it will be inaccessible, so need to add the dcr svc namespace - host := serviceName + "." + cluster.Namespace + host := cluster.GetFEServiceNameForAccess() confMap := dfc.GetConfigValuesFromConfigMaps(cluster.Namespace, resource.FE_RESOLVEKEY, cluster.Spec.FeSpec.ConfigMaps) queryPort := resource.GetPort(confMap, resource.QUERY_PORT) diff --git a/pkg/controller/sub_controller/disaggregated_cluster/disaggregated_fe/statefulset.go b/pkg/controller/sub_controller/disaggregated_cluster/disaggregated_fe/statefulset.go index ed53494..81bc4d6 100644 --- a/pkg/controller/sub_controller/disaggregated_cluster/disaggregated_fe/statefulset.go +++ b/pkg/controller/sub_controller/disaggregated_cluster/disaggregated_fe/statefulset.go @@ -297,7 +297,7 @@ func (dfc *DisaggregatedFEController) newSpecificEnvs(ddc *v1.DorisDisaggregated corev1.EnvVar{Name: MS_ENDPOINT, Value: msEndpoint}, corev1.EnvVar{Name: CLUSTER_ID, Value: fmt.Sprintf("%d", ddc.GetInstanceHashId())}, corev1.EnvVar{Name: STATEFULSET_NAME, Value: stsName}, - corev1.EnvVar{Name: resource.ENV_FE_ADDR, Value: ddc.GetFEServiceName()}, + corev1.EnvVar{Name: resource.ENV_FE_ADDR, Value: ddc.GetFEServiceNameForAccess()}, corev1.EnvVar{Name: resource.ENV_FE_ELECT_NUMBER, Value: strconv.FormatInt(int64(ddc.GetElectionNumber()), 10)}, ) return feEnvs