Skip to content

Headless service name #936

Open
Open
@crazychengmm

Description

@crazychengmm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions