Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mongodb service role selector error #5860

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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