Skip to content

Commit

Permalink
fix: mongodb service role selector error (#5860)
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie authored Nov 16, 2023
1 parent 73d37d7 commit 8201d35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/controller/component/component_definition_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions pkg/controller/component/component_definition_convertor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -447,6 +448,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, _ := 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))
})
})

Expand Down

0 comments on commit 8201d35

Please sign in to comment.