Skip to content

Commit

Permalink
opt: add LoadBalancerClass support for TiDB service (#5964)
Browse files Browse the repository at this point in the history
  • Loading branch information
csuzhangxc authored Dec 6, 2024
1 parent 7a9c1eb commit a5bce17
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15638,6 +15638,27 @@ More info: <a href="https://kubernetes.io/docs/concepts/services-networking/serv
Optional: Defaults to omitted</p>
</td>
</tr>
<tr>
<td>
<code>loadBalancerClass</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>loadBalancerClass is the class of the load balancer implementation this Service belongs to.
If specified, the value of this field must be a label-style identifier, with an optional prefix,
e.g. &ldquo;internal-vip&rdquo; or &ldquo;example.com/internal-vip&rdquo;. Unprefixed names are reserved for end-users.
This field can only be set when the Service type is &lsquo;LoadBalancer&rsquo;. If not set, the default load
balancer implementation is used, today this is typically done through the cloud provider integration,
but should apply for any default implementation. If set, it is assumed that a load balancer
implementation is watching for Services with a matching class. Any default load balancer
implementation (e.g. cloud providers) should ignore Services that set this field.
This field can only be set when creating or updating a Service to type &lsquo;LoadBalancer&rsquo;.
Once set, it can not be changed. This field will be wiped when a service is updated to a non &lsquo;LoadBalancer&rsquo; type.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="startscriptv2featureflag">StartScriptV2FeatureFlag</h3>
Expand Down
16 changes: 16 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12812,6 +12812,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -25273,6 +25275,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -28005,6 +28009,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -36359,6 +36365,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -48981,6 +48989,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -50954,6 +50964,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -51417,6 +51429,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -51522,6 +51536,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down
2 changes: 2 additions & 0 deletions manifests/crd/v1/pingcap.com_dmclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5762,6 +5762,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down
6 changes: 6 additions & 0 deletions manifests/crd/v1/pingcap.com_tidbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5814,6 +5814,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -8546,6 +8548,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -16900,6 +16904,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down
2 changes: 2 additions & 0 deletions manifests/crd/v1/pingcap.com_tidbdashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down
6 changes: 6 additions & 0 deletions manifests/crd/v1/pingcap.com_tidbmonitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -2022,6 +2024,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -2127,6 +2131,8 @@ spec:
additionalProperties:
type: string
type: object
loadBalancerClass:
type: string
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down
7 changes: 7 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.

13 changes: 13 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,19 @@ type ServiceSpec struct {
// Optional: Defaults to omitted
// +optional
LoadBalancerSourceRanges []string `json:"loadBalancerSourceRanges,omitempty"`

// loadBalancerClass is the class of the load balancer implementation this Service belongs to.
// If specified, the value of this field must be a label-style identifier, with an optional prefix,
// e.g. "internal-vip" or "example.com/internal-vip". Unprefixed names are reserved for end-users.
// This field can only be set when the Service type is 'LoadBalancer'. If not set, the default load
// balancer implementation is used, today this is typically done through the cloud provider integration,
// but should apply for any default implementation. If set, it is assumed that a load balancer
// implementation is watching for Services with a matching class. Any default load balancer
// implementation (e.g. cloud providers) should ignore Services that set this field.
// This field can only be set when creating or updating a Service to type 'LoadBalancer'.
// Once set, it can not be changed. This field will be wiped when a service is updated to a non 'LoadBalancer' type.
// +optional
LoadBalancerClass *string `json:"loadBalancerClass,omitempty" protobuf:"bytes,21,opt,name=loadBalancerClass"`
}

// TiDBServiceSpec defines `.tidb.service` field of `TidbCluster.spec`.
Expand Down
5 changes: 5 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.

3 changes: 3 additions & 0 deletions pkg/manager/member/dm_master_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ func (m *masterMemberManager) getNewMasterServiceForDMCluster(dc *v1alpha1.DMClu
if svcSpec.LoadBalancerSourceRanges != nil {
masterSvc.Spec.LoadBalancerSourceRanges = svcSpec.LoadBalancerSourceRanges
}
if svcSpec.LoadBalancerClass != nil {
masterSvc.Spec.LoadBalancerClass = svcSpec.LoadBalancerClass
}
}
if svcSpec.ExternalTrafficPolicy != nil {
masterSvc.Spec.ExternalTrafficPolicy = *svcSpec.ExternalTrafficPolicy
Expand Down
3 changes: 3 additions & 0 deletions pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,9 @@ func getNewTiDBServiceOrNil(tc *v1alpha1.TidbCluster) *corev1.Service {
if svcSpec.LoadBalancerSourceRanges != nil {
tidbSvc.Spec.LoadBalancerSourceRanges = svcSpec.LoadBalancerSourceRanges
}
if svcSpec.LoadBalancerClass != nil {
tidbSvc.Spec.LoadBalancerClass = svcSpec.LoadBalancerClass
}
}
if svcSpec.ExternalTrafficPolicy != nil {
tidbSvc.Spec.ExternalTrafficPolicy = *svcSpec.ExternalTrafficPolicy
Expand Down
3 changes: 3 additions & 0 deletions pkg/manager/member/tidb_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,7 @@ func TestGetNewTiDBService(t *testing.T) {
"10.0.0.0/8",
"130.211.204.1/32",
}
loadBalancerClass := "service.k8s.aws/nlb"
testCases := []struct {
name string
tc v1alpha1.TidbCluster
Expand Down Expand Up @@ -1903,6 +1904,7 @@ func TestGetNewTiDBService(t *testing.T) {
"lb-type": "testlb",
},
LoadBalancerSourceRanges: loadBalancerSourceRanges,
LoadBalancerClass: &loadBalancerClass,
},
ExternalTrafficPolicy: &trafficPolicy,
ExposeStatus: pointer.BoolPtr(true),
Expand Down Expand Up @@ -1948,6 +1950,7 @@ func TestGetNewTiDBService(t *testing.T) {
"10.0.0.0/8",
"130.211.204.1/32",
},
LoadBalancerClass: &loadBalancerClass,
Ports: []corev1.ServicePort{
{
Name: "mysql-client",
Expand Down

0 comments on commit a5bce17

Please sign in to comment.