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

feature:make Service port name configurable for tidb and pd service #1823

Merged
merged 21 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
695f159
feature:make Service port name configurable for tidb and pd service
mikechengwei Feb 28, 2020
6f144e2
Merge branch 'master' into portName
mikechengwei Feb 28, 2020
f39ef71
Merge branch 'master' of github.com:pingcap/tidb-operator into portName2
mikechengwei Feb 29, 2020
ba93254
Merge branch 'portName' of github.com:tongcheng-elong/tidb-operator i…
mikechengwei Feb 29, 2020
880f2a6
reset default port name
mikechengwei Mar 2, 2020
7c28834
reset default port name
mikechengwei Mar 2, 2020
de16542
reset default port name
mikechengwei Mar 2, 2020
91bf395
recover pd service clusterIP
mikechengwei Mar 3, 2020
37b77ec
Merge branch 'master' of github.com:pingcap/tidb-operator into portName2
mikechengwei Mar 3, 2020
ce7b627
comment pd and tidb service portName
mikechengwei Mar 3, 2020
71107d0
Merge branch 'master' of github.com:pingcap/tidb-operator into portName2
mikechengwei Mar 4, 2020
f7812ad
Merge branch 'master' into portName
mikechengwei Mar 4, 2020
2a901c4
Merge branch 'master' of github.com:pingcap/tidb-operator into portName2
mikechengwei Mar 6, 2020
b99631a
Merge branch 'portName' of github.com:tongcheng-elong/tidb-operator i…
mikechengwei Mar 6, 2020
5a9e2df
set pd and tidb port name value in yaml
mikechengwei Mar 6, 2020
db93903
set pd and tidb port name value in yaml
mikechengwei Mar 6, 2020
cfc50f5
Merge branch 'master' into portName
mikechengwei Mar 6, 2020
7f06a44
Merge branch 'master' into portName
mikechengwei Mar 9, 2020
2ff4dcd
Merge branch 'master' into portName
mikechengwei Mar 9, 2020
368882f
Merge branch 'master' into portName
mikechengwei Mar 9, 2020
8cf1129
Merge branch 'master' into portName
mikechengwei Mar 9, 2020
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 charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pd:
# we can only specify clusterIP and loadBalancerIP now
service:
clusterIP: "None"
# portName: "<the default name will be used>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you replace <the default name will be used> with the actual port name used for pd? I guess it's client here?

Copy link
Contributor

@Yisaer Yisaer Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# portName: "<the default name will be used>"
portName: "http-pd"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default value in our code is client, http-pd is the value he used in the unit tests

Ports: []corev1.ServicePort{
{
Name: "client",
Port: 2379,
TargetPort: intstr.FromInt(2379),
Protocol: corev1.ProtocolTCP,
},
},

Copy link
Contributor Author

@mikechengwei mikechengwei Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do this, there will be a problem of backward compatibility.

Copy link
Contributor Author

@mikechengwei mikechengwei Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can set http-pd value in yaml file ,but we can't change value in code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. See my previous comments and use actual default values in comments. then people will know port name used if they didn’t set these fields. This is common practice in configuration files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining, I understand now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# portName: "<the default name will be used>"
# portName: "client"


replicas: 3
image: pingcap/pd:v3.0.8
Expand Down Expand Up @@ -396,6 +397,7 @@ tidb:
service:
type: NodePort
exposeStatus: true
# portName: "<the default name will be used>"
Copy link
Contributor

@cofyc cofyc Mar 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you replace <the default name will be used> with the actual default name used for tidb? I guess it's mysql-client here.

Yisaer marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# portName: "<the default name will be used>"
# portName: "mysql-client"

# annotations:
# cloud.google.com/load-balancer-type: Internal
separateSlowLog: true
Expand Down
3 changes: 3 additions & 0 deletions pkg/manager/member/pd_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ func (pmm *pdMemberManager) getNewPDServiceForTidbCluster(tc *v1alpha1.TidbClust
if svcSpec.ClusterIP != nil {
pdService.Spec.ClusterIP = *svcSpec.ClusterIP
}
if svcSpec.PortName != nil {
pdService.Spec.Ports[0].Name = *svcSpec.PortName
}
}
return pdService
}
Expand Down
64 changes: 64 additions & 0 deletions pkg/manager/member/pd_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,70 @@ func TestGetNewPdServiceForTidbCluster(t *testing.T) {
},
},
},
{
name: "basic and specify pd service portname",
tc: v1alpha1.TidbCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "ns",
},
Spec: v1alpha1.TidbClusterSpec{
Services: []v1alpha1.Service{
{Name: "pd", Type: string(corev1.ServiceTypeLoadBalancer)},
},
PD: v1alpha1.PDSpec{
Service: &v1alpha1.ServiceSpec{Type: corev1.ServiceTypeClusterIP,
ClusterIP: pointer.StringPtr("172.20.10.1"),
PortName: pointer.StringPtr("http-pd"),
},
},
},
},
expected: corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "foo-pd",
Namespace: "ns",
Labels: map[string]string{
"app.kubernetes.io/name": "tidb-cluster",
"app.kubernetes.io/managed-by": "tidb-operator",
"app.kubernetes.io/instance": "foo",
"app.kubernetes.io/component": "pd",
},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "pingcap.com/v1alpha1",
Kind: "TidbCluster",
Name: "foo",
UID: "",
Controller: func(b bool) *bool {
return &b
}(true),
BlockOwnerDeletion: func(b bool) *bool {
return &b
}(true),
},
},
},
Spec: corev1.ServiceSpec{
ClusterIP: "172.20.10.1",
Type: corev1.ServiceTypeClusterIP,
Ports: []corev1.ServicePort{
{
Name: "http-pd",
Port: 2379,
TargetPort: intstr.FromInt(2379),
Protocol: corev1.ProtocolTCP,
},
},
Selector: map[string]string{
"app.kubernetes.io/name": "tidb-cluster",
"app.kubernetes.io/managed-by": "tidb-operator",
"app.kubernetes.io/instance": "foo",
"app.kubernetes.io/component": "pd",
},
},
},
},
}

for _, tt := range tests {
Expand Down
7 changes: 5 additions & 2 deletions pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,13 @@ func getNewTiDBServiceOrNil(tc *v1alpha1.TidbCluster) *corev1.Service {
instanceName := tc.GetInstanceName()
tidbLabels := label.New().Instance(instanceName).TiDB().Labels()
svcName := controller.TiDBMemberName(tcName)

portName := "mysql-client"
if svcSpec.PortName != nil {
portName = *svcSpec.PortName
}
ports := []corev1.ServicePort{
{
Name: "mysql-client",
Name: portName,
Port: 4000,
TargetPort: intstr.FromInt(4000),
Protocol: corev1.ProtocolTCP,
Expand Down
16 changes: 16 additions & 0 deletions pkg/manager/member/tidb_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,22 @@ func TestTiDBMemberManagerSyncTidbService(t *testing.T) {
g.Expect(svc.Spec.ClusterIP).To(Equal("8.8.8.8"))
},
},
{
name: "Create service with portName",
prepare: func(tc *v1alpha1.TidbCluster, _ *fakeIndexers) {
tc.Spec.TiDB.Service = &v1alpha1.TiDBServiceSpec{
ServiceSpec: v1alpha1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
PortName: pointer.StringPtr("mysql-tidb"),
},
}
},
expectFn: func(g *GomegaWithT, err error, svc *corev1.Service) {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(svc).NotTo(BeNil())
g.Expect(svc.Spec.Ports[0].Name).To(Equal("mysql-tidb"))
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down