From a98cad36908bc9a1202af0a756744859441f81a5 Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Thu, 16 Nov 2023 18:17:49 +0800 Subject: [PATCH 1/3] fix mongodb service role selector empty --- pkg/controller/component/component_definition_convertor.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/controller/component/component_definition_convertor.go b/pkg/controller/component/component_definition_convertor.go index 9644912f4a4..8cc9d4ddcfb 100644 --- a/pkg/controller/component/component_definition_convertor.go +++ b/pkg/controller/component/component_definition_convertor.go @@ -213,7 +213,10 @@ func (c *compDefServicesConvertor) removeDuplicatePorts(svc *corev1.Service) *co func (c *compDefServicesConvertor) roleSelector(clusterCompDef *appsv1alpha1.ClusterComponentDefinition) string { switch clusterCompDef.WorkloadType { case appsv1alpha1.Consensus: - return constant.Leader + if clusterCompDef.ConsensusSpec == nil { + return constant.Leader + } + return clusterCompDef.ConsensusSpec.Leader.Name case appsv1alpha1.Replication: return constant.Primary default: From 4ccd59e1a5f044c1fbb0b0c7762b5fd35fe187cb Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Thu, 16 Nov 2023 18:38:13 +0800 Subject: [PATCH 2/3] fix mongodb service role selector empty --- .../component_definition_convertor_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/controller/component/component_definition_convertor_test.go b/pkg/controller/component/component_definition_convertor_test.go index 253dacfebe3..d1f44a4c6e0 100644 --- a/pkg/controller/component/component_definition_convertor_test.go +++ b/pkg/controller/component/component_definition_convertor_test.go @@ -447,6 +447,20 @@ var _ = Describe("Component Definition Convertor", func() { Expect(services[1].Spec.Type).Should(Equal(corev1.ServiceTypeClusterIP)) Expect(services[1].Spec.ClusterIP).Should(Equal(corev1.ClusterIPNone)) Expect(services[1].RoleSelector).Should(BeEquivalentTo(constant.Leader)) + + // consensus role selector + clusterCompDef.WorkloadType = appsv1alpha1.Consensus + clusterCompDef.ConsensusSpec = &appsv1alpha1.ConsensusSetSpec{ + Leader: appsv1alpha1.ConsensusMember{ + Name: constant.Primary, + AccessMode: appsv1alpha1.ReadWrite, + }, + } + res2, err := convertor.convert(clusterCompDef, clusterName) + services2, ok := res2.([]appsv1alpha1.Service) + Expect(ok).Should(BeTrue()) + Expect(services2).Should(HaveLen(2)) + Expect(services2[0].RoleSelector).Should(BeEquivalentTo(constant.Primary)) }) }) From e993f7cb229eaa5ff1cc948ace870b16440cce15 Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Thu, 16 Nov 2023 18:44:05 +0800 Subject: [PATCH 3/3] add ut and fix lint --- .../component/component_definition_convertor_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/controller/component/component_definition_convertor_test.go b/pkg/controller/component/component_definition_convertor_test.go index d1f44a4c6e0..eb6313adfc0 100644 --- a/pkg/controller/component/component_definition_convertor_test.go +++ b/pkg/controller/component/component_definition_convertor_test.go @@ -22,6 +22,7 @@ package component import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -456,9 +457,9 @@ var _ = Describe("Component Definition Convertor", func() { AccessMode: appsv1alpha1.ReadWrite, }, } - res2, err := convertor.convert(clusterCompDef, clusterName) - services2, ok := res2.([]appsv1alpha1.Service) - Expect(ok).Should(BeTrue()) + res2, _ := convertor.convert(clusterCompDef, clusterName) + services2, ok2 := res2.([]appsv1alpha1.Service) + Expect(ok2).Should(BeTrue()) Expect(services2).Should(HaveLen(2)) Expect(services2[0].RoleSelector).Should(BeEquivalentTo(constant.Primary)) })