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

Headless service name #936

Open
crazychengmm opened this issue Feb 13, 2025 · 0 comments
Open

Headless service name #936

crazychengmm opened this issue Feb 13, 2025 · 0 comments

Comments

@crazychengmm
Copy link

Version: v0.5.3

I noticed that Headless name was named mysql.
If i created two cluster on same namespace, it would be got problem.

Code:

// NewHeadlessSVCSyncer returns a service syncer
func NewHeadlessSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysqlcluster.MysqlCluster) syncer.Interface {
	service := &core.Service{
		ObjectMeta: metav1.ObjectMeta{
			Name:      cluster.GetNameForResource(mysqlcluster.HeadlessSVC),
			Namespace: cluster.Namespace,
		},
	}

	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/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/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
		// the in memory table to mark the pod ready.
		service.Spec.PublishNotReadyAddresses = true

		if len(service.Spec.Ports) != 2 {
			service.Spec.Ports = make([]core.ServicePort, 2)
		}
		service.Spec.Ports[0].Name = MysqlPortName
		service.Spec.Ports[0].Port = MysqlPort
		service.Spec.Ports[0].TargetPort = TargetPort
		service.Spec.Ports[0].Protocol = core.ProtocolTCP

		service.Spec.Ports[1].Name = ExporterPortName
		service.Spec.Ports[1].Port = ExporterPort
		service.Spec.Ports[1].TargetPort = ExporterTargetPort
		service.Spec.Ports[1].Protocol = core.ProtocolTCP

		return nil
	})
}

Why not add the cluster name to the MySQL headless name? like the master service includes the cluster name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant