Skip to content

Commit

Permalink
support mysqlNodePort and statusNodePort (#2941) (#2986)
Browse files Browse the repository at this point in the history
* cherry pick #2941 to release-1.1

Signed-off-by: ti-srebot <[email protected]>

* regenerate code

Co-authored-by: Chunzhu Li <[email protected]>
  • Loading branch information
ti-srebot and lichunzhu authored Jul 17, 2020
1 parent 4b4963f commit 762fa76
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9888,6 +9888,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
6 changes: 6 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
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 @@ -551,6 +551,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 @@ -768,6 +768,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

0 comments on commit 762fa76

Please sign in to comment.