Skip to content

Commit

Permalink
refactor: use constant to replace magic number
Browse files Browse the repository at this point in the history
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Jan 10, 2024
1 parent 3f9cd1a commit 82ff608
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/transformer/xlinecluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

const (
XlinePort = 2379
)

func GetServiceKey(xlineClusterName types.NamespacedName) types.NamespacedName {
return types.NamespacedName{
Namespace: xlineClusterName.Namespace,
Expand All @@ -36,7 +40,7 @@ func GetMemberTopology(stsRef types.NamespacedName, svcName string, replicas int
for i := 0; i < replicas; i++ {
podName := fmt.Sprintf("%s-%d", stsRef.Name, i)
dnsName := fmt.Sprintf("%s.%s.%s.svc.cluster.local", podName, svcName, stsRef.Namespace)
members[i] = fmt.Sprintf("%s=%s:2379", podName, dnsName)
members[i] = fmt.Sprintf("%s=%s:%d", podName, dnsName, XlinePort)
}
return strings.Join(members, ",")
}
Expand All @@ -53,7 +57,7 @@ func MakeService(cr *xapi.XlineCluster, scheme *runtime.Scheme) *corev1.Service
Ports: []corev1.ServicePort{
{
Name: "xline-port",
Port: 2379,
Port: XlinePort,
},
},
Selector: svcLabel,
Expand All @@ -76,7 +80,7 @@ func MakeStatefulSet(cr *xapi.XlineCluster, scheme *runtime.Scheme) *appv1.State
Image: *cr.Spec.Image,
ImagePullPolicy: cr.Spec.ImagePullPolicy,
Ports: []corev1.ContainerPort{
{Name: "xline-port", ContainerPort: 2379},
{Name: "xline-port", ContainerPort: XlinePort},
},
Env: []corev1.EnvVar{
{Name: "MEMBERS", Value: GetMemberTopology(stsRef, svcName, int(cr.Spec.Replicas))},
Expand Down

0 comments on commit 82ff608

Please sign in to comment.