Skip to content

Change headless svc name #903

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Add `KeepAfterDelete` in `.Spec.VolumeSpec` to keep pvc after mysql cluster been deleted.

### Changed
* Changed headless svc name to a templated name that includes the mysql cluster name

### Removed
### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package mysqlcluster

import (
"fmt"

core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -40,14 +42,14 @@ func NewHeadlessSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysq
return syncer.NewObjectSyncer("HeadlessSVC", nil, service, c, func() error {
// add general labels to this service
service.Labels = map[string]string{
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/name": fmt.Sprintf("%s-mysql-headless", cluster.Name),
"app.kubernetes.io/managed-by": "mysql.presslabs.org",
}
service.Labels["mysql.presslabs.org/service-type"] = "namespace-nodes"

service.Spec.ClusterIP = "None"
service.Spec.Selector = labels.Set{
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/name": fmt.Sprintf("%s-mysql-headless", cluster.Name),
"app.kubernetes.io/managed-by": "mysql.presslabs.org",
}
// we want to be able to access pods even if the pod is not ready because the operator should update
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/orchestrator/orchestrator_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func (ou *orcUpdater) removeNodeConditionNotInOrc(insts InstancesSet) {

// indexInSts is a helper function that returns the index of the pod in statefulset
func indexInSts(name string) (int32, error) {
re := regexp.MustCompile(`^[\w-]+-mysql-(\d*)\.[\w-]*mysql(?:-nodes)?\.[\w-]+$`)
re := regexp.MustCompile(`^[\w-]+-mysql-(\d*)\.[\w-]*mysql(?:-nodes|-headless)?\.[\w-]+$`)
values := re.FindStringSubmatch(name)
if len(values) != 2 {
return 0, fmt.Errorf("no match found")
Expand Down
11 changes: 3 additions & 8 deletions pkg/internal/mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ import (
"github.com/bitpoke/mysql-operator/pkg/util/constants"
)

const (
// HeadlessSVCName is the name of the headless service that is commonly used for all clusters
HeadlessSVCName = "mysql"
)

// MysqlCluster is the wrapper for api.MysqlCluster type
type MysqlCluster struct {
*api.MysqlCluster
Expand Down Expand Up @@ -72,7 +67,7 @@ func (c *MysqlCluster) GetLabels() labels.Set {
labels := labels.Set{
"mysql.presslabs.org/cluster": c.Name,

"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/name": fmt.Sprintf("%s-mysql-headless", c.Name),
"app.kubernetes.io/instance": instance,
"app.kubernetes.io/version": c.GetMySQLSemVer().String(),
"app.kubernetes.io/component": component,
Expand All @@ -91,7 +86,7 @@ func (c *MysqlCluster) GetSelectorLabels() labels.Set {
return labels.Set{
"mysql.presslabs.org/cluster": c.Name,

"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/name": fmt.Sprintf("%s-mysql-headless", c.Name),
"app.kubernetes.io/managed-by": "mysql.presslabs.org",
}
}
Expand Down Expand Up @@ -137,7 +132,7 @@ func GetNameForResource(name ResourceName, clusterName string) string {
case HealthyReplicasService:
return fmt.Sprintf("%s-mysql-replicas", clusterName)
case HeadlessSVC:
return HeadlessSVCName
return fmt.Sprintf("%s-mysql-headless", clusterName)
case OldHeadlessSVC:
return fmt.Sprintf("%s-mysql-nodes", clusterName)
case Secret:
Expand Down
2 changes: 1 addition & 1 deletion pkg/orchestrator/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (o *OrcFakeClient) CheckDiscovered(key string) bool {
func (o *OrcFakeClient) getHostClusterAlias(host string) string {
// input: cluster-1943285891-mysql-0.mysql.default
// output: cluster-1943285891.default
re := regexp.MustCompile(`^([\w-]+)-mysql-\d*.mysql.([\w-]+)$`)
re := regexp.MustCompile(`^([\w-]+)-mysql-\d*(?:\.[\w-]+)?-mysql(?:-headless)?\.(.+)$`)
values := re.FindStringSubmatch(host)
return fmt.Sprintf("%s.%s", values[1], values[2])
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func GetNameForResource(name string, cluster *api.MysqlCluster) string {
case "svc-read":
return fmt.Sprintf("%s-mysql", cluster.Name)
case "svc-headless":
return "mysql"
return fmt.Sprintf("%s-mysql-headless", cluster.Name)
default:
return fmt.Sprintf("%s-mysql", cluster.Name)
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func (f *Framework) ReadSQLTest(cluster *api.MysqlCluster, pod int, pw string) s
func GetClusterLabels(cluster *api.MysqlCluster) labels.Set {
labels := labels.Set{
"mysql.presslabs.org/cluster": cluster.Name,
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/name": fmt.Sprintf("%s-mysql-headless", cluster.Name),
}

return labels
Expand Down