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

support mysqlNodePort and statusNodePort #2941

Merged
merged 13 commits into from
Jul 17, 2020
Merged
26 changes: 26 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10227,6 +10227,32 @@ bool
Optional: Defaults to true</p>
</td>
</tr>
<tr>
<td>
<code>mysqlNodePort</code></br>
<em>
int
</em>
</td>
<td>
<em>(Optional)</em>
<p>Expose the tidb cluster mysql port to MySQLNodePort
Optional: Defaults to 0</p>
</td>
</tr>
<tr>
<td>
<code>statusNodePort</code></br>
<em>
int
</em>
</td>
<td>
<em>(Optional)</em>
<p>Expose the tidb status node port to StatusNodePort
Optional: Defaults to 0</p>
</td>
</tr>
</tbody>
</table>
<h3 id="tidbslowlogtailerspec">TiDBSlowLogTailerSpec</h3>
Expand Down
3 changes: 3 additions & 0 deletions examples/advanced/tidb-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ spec:
## Service defines a Kubernetes service of TiDB cluster.
## If you are in a public cloud environment, you can use cloud LB to access the TiDB service
## if you are in a private cloud environment, you can use ingress
## you can set mysqlNodePort and statusNodePort to expose server/status service to given NodePort
# service:
# externalTrafficPolicy: Local
# type: LoadBalancer
# mysqlNodePort: 30020
# statusNodePort: 30040

## Affinity for pod assignment
## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
Expand Down
12 changes: 12 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7040,6 +7040,12 @@ spec:
type: boolean
externalTrafficPolicy:
type: string
mysqlNodePort:
format: int32
type: integer
statusNodePort:
format: int32
type: integer
type: object
slowLogTailer:
properties:
Expand Down Expand Up @@ -15528,6 +15534,12 @@ spec:
type: boolean
externalTrafficPolicy:
type: string
mysqlNodePort:
format: int32
type: integer
statusNodePort:
format: int32
type: integer
type: object
slowLogTailer:
properties:
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/apis/pingcap/v1alpha1/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,22 @@ func (tidbSvc *TiDBServiceSpec) ShouldExposeStatus() bool {
return *exposeStatus
}

func (tidbSvc *TiDBServiceSpec) GetMySQLNodePort() int32 {
mysqlNodePort := tidbSvc.MySQLNodePort
if mysqlNodePort == nil {
return 0
}
return int32(*mysqlNodePort)
}

func (tidbSvc *TiDBServiceSpec) GetStatusNodePort() int32 {
statusNodePort := tidbSvc.StatusNodePort
if statusNodePort == nil {
return 0
}
return int32(*statusNodePort)
}

func (tc *TidbCluster) GetInstanceName() string {
labels := tc.ObjectMeta.GetLabels()
// Keep backward compatibility for helm.
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,16 @@ type TiDBServiceSpec struct {
// Optional: Defaults to true
// +optional
ExposeStatus *bool `json:"exposeStatus,omitempty"`

// Expose the tidb cluster mysql port to MySQLNodePort
// Optional: Defaults to 0
// +optional
MySQLNodePort *int `json:"mysqlNodePort,omitempty"`

// Expose the tidb status node port to StatusNodePort
// Optional: Defaults to 0
// +optional
StatusNodePort *int `json:"statusNodePort,omitempty"`
}

// +k8s:openapi-gen=false
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ func getNewTiDBServiceOrNil(tc *v1alpha1.TidbCluster) *corev1.Service {
Port: 4000,
TargetPort: intstr.FromInt(4000),
Protocol: corev1.ProtocolTCP,
NodePort: svcSpec.GetMySQLNodePort(),
},
}
if svcSpec.ShouldExposeStatus() {
Expand All @@ -457,6 +458,7 @@ func getNewTiDBServiceOrNil(tc *v1alpha1.TidbCluster) *corev1.Service {
Port: 10080,
TargetPort: intstr.FromInt(10080),
Protocol: corev1.ProtocolTCP,
NodePort: svcSpec.GetStatusNodePort(),
})
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ func RetainManagedFields(desiredSvc, existedSvc *corev1.Service) {
}
// Retain NodePorts
for id, dport := range desiredSvc.Spec.Ports {
if dport.NodePort != 0 {
continue
}
for _, eport := range existedSvc.Spec.Ports {
if dport.Port == eport.Port && dport.Protocol == eport.Protocol {
dport.NodePort = eport.NodePort
Expand Down