Skip to content

Commit

Permalink
Merge pull request radondb#252 from runkecheng/dmp_svc
Browse files Browse the repository at this point in the history
*: Support extranet access service. radondb#251
  • Loading branch information
andyli029 authored Oct 11, 2021
2 parents d986ca7 + 101a305 commit 934c703
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions cluster/syncer/follower_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (

// NewFollowerSVCSyncer returns follower service syncer.
func NewFollowerSVCSyncer(cli client.Client, c *cluster.Cluster) syncer.Interface {
labels := c.GetLabels()
labels["mysql.radondb.com/service-type"] = string(utils.FollowerService)
service := &corev1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand All @@ -37,11 +39,14 @@ func NewFollowerSVCSyncer(cli client.Client, c *cluster.Cluster) syncer.Interfac
ObjectMeta: metav1.ObjectMeta{
Name: c.GetNameForResource(utils.FollowerService),
Namespace: c.Namespace,
Labels: c.GetLabels(),
Labels: labels,
},
}
return syncer.NewObjectSyncer("FollowerSVC", c.Unwrap(), service, cli, func() error {
service.Spec.Type = "ClusterIP"
// Allows to modify the service access method, the default is ClusterIP.
if service.Spec.Type == "" {
service.Spec.Type = "ClusterIP"
}
service.Spec.Selector = c.GetSelectorLabels()
service.Spec.Selector["role"] = "follower"
service.Spec.Selector["healthy"] = "yes"
Expand Down
9 changes: 7 additions & 2 deletions cluster/syncer/leader_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (

// NewLeaderSVCSyncer returns leader service syncer.
func NewLeaderSVCSyncer(cli client.Client, c *cluster.Cluster) syncer.Interface {
labels := c.GetLabels()
labels["mysql.radondb.com/service-type"] = string(utils.LeaderService)
service := &corev1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand All @@ -37,11 +39,14 @@ func NewLeaderSVCSyncer(cli client.Client, c *cluster.Cluster) syncer.Interface
ObjectMeta: metav1.ObjectMeta{
Name: c.GetNameForResource(utils.LeaderService),
Namespace: c.Namespace,
Labels: c.GetLabels(),
Labels: labels,
},
}
return syncer.NewObjectSyncer("LeaderSVC", c.Unwrap(), service, cli, func() error {
service.Spec.Type = "ClusterIP"
// Allows to modify the service access method, the default is ClusterIP.
if service.Spec.Type == "" {
service.Spec.Type = "ClusterIP"
}
service.Spec.Selector = c.GetSelectorLabels()
service.Spec.Selector["role"] = "leader"

Expand Down
9 changes: 7 additions & 2 deletions cluster/syncer/metrics_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (

// NewMetricsSVCSyncer returns metrics service syncer.
func NewMetricsSVCSyncer(cli client.Client, c *cluster.Cluster) syncer.Interface {
labels := c.GetLabels()
labels["mysql.radondb.com/service-type"] = string(utils.MetricsService)
service := &corev1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand All @@ -37,11 +39,14 @@ func NewMetricsSVCSyncer(cli client.Client, c *cluster.Cluster) syncer.Interface
ObjectMeta: metav1.ObjectMeta{
Name: c.GetNameForResource(utils.MetricsService),
Namespace: c.Namespace,
Labels: c.GetLabels(),
Labels: labels,
},
}
return syncer.NewObjectSyncer("MetricsSVC", c.Unwrap(), service, cli, func() error {
service.Spec.Type = "ClusterIP"
// Allows to modify the service access method, the default is ClusterIP.
if service.Spec.Type == "" {
service.Spec.Type = "ClusterIP"
}
service.Spec.Selector = c.GetSelectorLabels()

if len(service.Spec.Ports) != 1 {
Expand Down

0 comments on commit 934c703

Please sign in to comment.