diff --git a/pkg/controller/mysqlcluster/internal/syncer/headless_service.go b/pkg/controller/mysqlcluster/internal/syncer/headless_service.go index e23d6464e..9860b8f69 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/headless_service.go +++ b/pkg/controller/mysqlcluster/internal/syncer/headless_service.go @@ -39,6 +39,13 @@ func NewHeadlessSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysq return syncer.NewObjectSyncer("HeadlessSVC", nil, obj, c, scheme, func(in runtime.Object) error { out := in.(*core.Service) + // add general labels to this service + out.Labels = map[string]string{ + "app.kubernetes.io/name": "mysql", + "app.kubernetes.io/managed-by": "mysql.presslabs.org", + } + out.Labels["mysql.presslabs.org/service-type"] = "common-headless" + out.Spec.ClusterIP = "None" out.Spec.Selector = labels.Set{ "app.kubernetes.io/name": "mysql", diff --git a/pkg/controller/mysqlcluster/internal/syncer/healthy_service.go b/pkg/controller/mysqlcluster/internal/syncer/healthy_service.go index a99beba4c..cb9155691 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/healthy_service.go +++ b/pkg/controller/mysqlcluster/internal/syncer/healthy_service.go @@ -38,6 +38,10 @@ func NewHealthySVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysql return syncer.NewObjectSyncer("HealthySVC", cluster.Unwrap(), obj, c, scheme, func(in runtime.Object) error { out := in.(*core.Service) + // set service labels + out.Labels = cluster.GetLabels() + out.Labels["mysql.presslabs.org/service-type"] = "healthy" + out.Spec.Type = "ClusterIP" out.Spec.Selector = cluster.GetSelectorLabels() out.Spec.Selector["healthy"] = "yes" diff --git a/pkg/controller/mysqlcluster/internal/syncer/master_service.go b/pkg/controller/mysqlcluster/internal/syncer/master_service.go index ab6250b3f..8ff1f1e1d 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/master_service.go +++ b/pkg/controller/mysqlcluster/internal/syncer/master_service.go @@ -38,7 +38,13 @@ func NewMasterSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysqlc return syncer.NewObjectSyncer("MasterSVC", cluster.Unwrap(), obj, c, scheme, func(in runtime.Object) error { out := in.(*core.Service) + // set service labels + out.Labels = cluster.GetLabels() + out.Labels["mysql.presslabs.org/service-type"] = "master" + out.Spec.Type = "ClusterIP" + + // set selectors for master node out.Spec.Selector = cluster.GetSelectorLabels() out.Spec.Selector["role"] = "master"