Skip to content

Commit a0adff1

Browse files
authored
feat(group): support scale subresource (#6213)
1 parent 7190229 commit a0adff1

39 files changed

+342
-2
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ issues:
123123
- dupl
124124
- mnd
125125
- lll
126+
- goconst
126127
exclude-files:
127128
- ".*/br/.*/_test.go"
128129
- ".*/br/.*/testutils/.*"

api/core/v1alpha1/common_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ type GroupStatus struct {
330330
// It will be same as the `spec.version` only when all instances are upgraded to the desired version.
331331
Version string `json:"version,omitempty"`
332332

333+
// Selector is the label selector for scale subresource.
334+
Selector string `json:"selector"`
335+
333336
// Replicas is the number of Instance created by the controller.
334337
Replicas int32 `json:"replicas"`
335338

api/core/v1alpha1/pd_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type PDGroupList struct {
5555
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
5656
// +kubebuilder:object:root=true
5757
// +kubebuilder:subresource:status
58+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
5859
// +kubebuilder:resource:categories=tc;group,shortName=pdg
5960
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
6061
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`

api/core/v1alpha1/scheduler_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type SchedulerGroupList struct {
3535
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
3636
// +kubebuilder:object:root=true
3737
// +kubebuilder:subresource:status
38+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
3839
// +kubebuilder:resource:categories=tc;group,shortName=sg
3940
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
4041
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`

api/core/v1alpha1/ticdc_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type TiCDCGroupList struct {
4242
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
4343
// +kubebuilder:object:root=true
4444
// +kubebuilder:subresource:status
45+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
4546
// +kubebuilder:resource:categories=tc;group,shortName=cg
4647
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
4748
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`

api/core/v1alpha1/tidb_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type TiDBGroupList struct {
6060
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
6161
// +kubebuilder:object:root=true
6262
// +kubebuilder:subresource:status
63+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
6364
// +kubebuilder:resource:categories=tc;group,shortName=dbg
6465
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
6566
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`

api/core/v1alpha1/tiflash_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type TiFlashGroupList struct {
5151
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
5252
// +kubebuilder:object:root=true
5353
// +kubebuilder:subresource:status
54+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
5455
// +kubebuilder:resource:categories=tc;group,shortName=fg
5556
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
5657
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`

api/core/v1alpha1/tikv_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type TiKVGroupList struct {
6464
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
6565
// +kubebuilder:object:root=true
6666
// +kubebuilder:subresource:status
67+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
6768
// +kubebuilder:resource:categories=tc;group,shortName=kvg
6869
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
6970
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`

api/core/v1alpha1/tiproxy_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type TiProxyGroupList struct {
3939
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
4040
// +kubebuilder:object:root=true
4141
// +kubebuilder:subresource:status
42+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
4243
// +kubebuilder:resource:categories=tc;group,shortName=pg
4344
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
4445
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`

api/core/v1alpha1/tso_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type TSOGroupList struct {
3535
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
3636
// +kubebuilder:object:root=true
3737
// +kubebuilder:subresource:status
38+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
3839
// +kubebuilder:resource:categories=tc;group,shortName=tg
3940
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
4041
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`

cmd/runtime-gen/generators/runtime.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,14 @@ func (g *$.|pub$) StatusRevision() (update, current string, collisionCount *int3
347347
g.Status.CollisionCount
348348
}
349349
350+
func (g *$.|pub$) SetStatusSelector(l string) {
351+
g.Status.Selector = l
352+
}
353+
354+
func (g *$.|pub$) StatusSelector() string {
355+
return g.Status.Selector
356+
}
357+
350358
func (g *$.|pub$) TemplateLabels() map[string]string {
351359
return g.Spec.Template.Labels
352360
}

manifests/crd/core.pingcap.com_pdgroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8717,6 +8717,9 @@ spec:
87178717
description: Replicas is the number of Instance created by the controller.
87188718
format: int32
87198719
type: integer
8720+
selector:
8721+
description: Selector is the label selector for scale subresource.
8722+
type: string
87208723
updateRevision:
87218724
description: UpdateRevision is the revision of the Controller that
87228725
should modify the resource.
@@ -8736,6 +8739,7 @@ spec:
87368739
- currentReplicas
87378740
- readyReplicas
87388741
- replicas
8742+
- selector
87398743
- updatedReplicas
87408744
type: object
87418745
type: object
@@ -8744,4 +8748,8 @@ spec:
87448748
served: true
87458749
storage: true
87468750
subresources:
8751+
scale:
8752+
labelSelectorPath: .status.selector
8753+
specReplicasPath: .spec.replicas
8754+
statusReplicasPath: .status.replicas
87478755
status: {}

manifests/crd/core.pingcap.com_schedulergroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8861,6 +8861,9 @@ spec:
88618861
description: Replicas is the number of Instance created by the controller.
88628862
format: int32
88638863
type: integer
8864+
selector:
8865+
description: Selector is the label selector for scale subresource.
8866+
type: string
88648867
updateRevision:
88658868
description: UpdateRevision is the revision of the Controller that
88668869
should modify the resource.
@@ -8880,6 +8883,7 @@ spec:
88808883
- currentReplicas
88818884
- readyReplicas
88828885
- replicas
8886+
- selector
88838887
- updatedReplicas
88848888
type: object
88858889
type: object
@@ -8888,4 +8892,8 @@ spec:
88888892
served: true
88898893
storage: true
88908894
subresources:
8895+
scale:
8896+
labelSelectorPath: .status.selector
8897+
specReplicasPath: .spec.replicas
8898+
statusReplicasPath: .status.replicas
88918899
status: {}

manifests/crd/core.pingcap.com_ticdcgroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8694,6 +8694,9 @@ spec:
86948694
description: Replicas is the number of Instance created by the controller.
86958695
format: int32
86968696
type: integer
8697+
selector:
8698+
description: Selector is the label selector for scale subresource.
8699+
type: string
86978700
updateRevision:
86988701
description: UpdateRevision is the revision of the Controller that
86998702
should modify the resource.
@@ -8713,6 +8716,7 @@ spec:
87138716
- currentReplicas
87148717
- readyReplicas
87158718
- replicas
8719+
- selector
87168720
- updatedReplicas
87178721
type: object
87188722
type: object
@@ -8721,4 +8725,8 @@ spec:
87218725
served: true
87228726
storage: true
87238727
subresources:
8728+
scale:
8729+
labelSelectorPath: .status.selector
8730+
specReplicasPath: .spec.replicas
8731+
statusReplicasPath: .status.replicas
87248732
status: {}

manifests/crd/core.pingcap.com_tidbgroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8827,6 +8827,9 @@ spec:
88278827
description: Replicas is the number of Instance created by the controller.
88288828
format: int32
88298829
type: integer
8830+
selector:
8831+
description: Selector is the label selector for scale subresource.
8832+
type: string
88308833
updateRevision:
88318834
description: UpdateRevision is the revision of the Controller that
88328835
should modify the resource.
@@ -8846,6 +8849,7 @@ spec:
88468849
- currentReplicas
88478850
- readyReplicas
88488851
- replicas
8852+
- selector
88498853
- updatedReplicas
88508854
type: object
88518855
type: object
@@ -8854,4 +8858,8 @@ spec:
88548858
served: true
88558859
storage: true
88568860
subresources:
8861+
scale:
8862+
labelSelectorPath: .status.selector
8863+
specReplicasPath: .spec.replicas
8864+
statusReplicasPath: .status.replicas
88578865
status: {}

manifests/crd/core.pingcap.com_tiflashgroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8739,6 +8739,9 @@ spec:
87398739
description: Replicas is the number of Instance created by the controller.
87408740
format: int32
87418741
type: integer
8742+
selector:
8743+
description: Selector is the label selector for scale subresource.
8744+
type: string
87428745
updateRevision:
87438746
description: UpdateRevision is the revision of the Controller that
87448747
should modify the resource.
@@ -8758,6 +8761,7 @@ spec:
87588761
- currentReplicas
87598762
- readyReplicas
87608763
- replicas
8764+
- selector
87618765
- updatedReplicas
87628766
type: object
87638767
type: object
@@ -8766,4 +8770,8 @@ spec:
87668770
served: true
87678771
storage: true
87688772
subresources:
8773+
scale:
8774+
labelSelectorPath: .status.selector
8775+
specReplicasPath: .spec.replicas
8776+
statusReplicasPath: .status.replicas
87698777
status: {}

manifests/crd/core.pingcap.com_tikvgroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8701,6 +8701,9 @@ spec:
87018701
description: Replicas is the number of Instance created by the controller.
87028702
format: int32
87038703
type: integer
8704+
selector:
8705+
description: Selector is the label selector for scale subresource.
8706+
type: string
87048707
updateRevision:
87058708
description: UpdateRevision is the revision of the Controller that
87068709
should modify the resource.
@@ -8720,6 +8723,7 @@ spec:
87208723
- currentReplicas
87218724
- readyReplicas
87228725
- replicas
8726+
- selector
87238727
- updatedReplicas
87248728
type: object
87258729
type: object
@@ -8728,4 +8732,8 @@ spec:
87288732
served: true
87298733
storage: true
87308734
subresources:
8735+
scale:
8736+
labelSelectorPath: .status.selector
8737+
specReplicasPath: .spec.replicas
8738+
statusReplicasPath: .status.replicas
87318739
status: {}

manifests/crd/core.pingcap.com_tiproxygroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8932,6 +8932,9 @@ spec:
89328932
description: Replicas is the number of Instance created by the controller.
89338933
format: int32
89348934
type: integer
8935+
selector:
8936+
description: Selector is the label selector for scale subresource.
8937+
type: string
89358938
updateRevision:
89368939
description: UpdateRevision is the revision of the Controller that
89378940
should modify the resource.
@@ -8951,6 +8954,7 @@ spec:
89518954
- currentReplicas
89528955
- readyReplicas
89538956
- replicas
8957+
- selector
89548958
- updatedReplicas
89558959
type: object
89568960
type: object
@@ -8959,4 +8963,8 @@ spec:
89598963
served: true
89608964
storage: true
89618965
subresources:
8966+
scale:
8967+
labelSelectorPath: .status.selector
8968+
specReplicasPath: .spec.replicas
8969+
statusReplicasPath: .status.replicas
89628970
status: {}

manifests/crd/core.pingcap.com_tsogroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8860,6 +8860,9 @@ spec:
88608860
description: Replicas is the number of Instance created by the controller.
88618861
format: int32
88628862
type: integer
8863+
selector:
8864+
description: Selector is the label selector for scale subresource.
8865+
type: string
88638866
updateRevision:
88648867
description: UpdateRevision is the revision of the Controller that
88658868
should modify the resource.
@@ -8879,6 +8882,7 @@ spec:
88798882
- currentReplicas
88808883
- readyReplicas
88818884
- replicas
8885+
- selector
88828886
- updatedReplicas
88838887
type: object
88848888
type: object
@@ -8887,4 +8891,8 @@ spec:
88878891
served: true
88888892
storage: true
88898893
subresources:
8894+
scale:
8895+
labelSelectorPath: .status.selector
8896+
specReplicasPath: .spec.replicas
8897+
statusReplicasPath: .status.replicas
88908898
status: {}

pkg/apiutil/core/v1alpha1/group.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package coreutil
1717
import (
1818
"maps"
1919

20+
"k8s.io/apimachinery/pkg/labels"
21+
2022
"github.com/pingcap/tidb-operator/api/v2/core/v1alpha1"
2123
"github.com/pingcap/tidb-operator/pkg/client"
2224
"github.com/pingcap/tidb-operator/pkg/runtime"
@@ -146,3 +148,26 @@ func InstanceAnnotations[
146148

147149
return maps.Clone(obj.TemplateAnnotations())
148150
}
151+
152+
func SetStatusSelector[
153+
S scope.Group[F, T],
154+
F client.Object,
155+
T runtime.Group,
156+
](f F) bool {
157+
obj := scope.From[S](f)
158+
159+
l := obj.StatusSelector()
160+
161+
changed := compare.SetIfChanged(&l, labels.Set{
162+
v1alpha1.LabelKeyManagedBy: v1alpha1.LabelValManagedByOperator,
163+
v1alpha1.LabelKeyComponent: obj.Component(),
164+
v1alpha1.LabelKeyCluster: obj.Cluster(),
165+
v1alpha1.LabelKeyGroup: f.GetName(),
166+
}.String())
167+
168+
if changed {
169+
obj.SetStatusSelector(l)
170+
}
171+
172+
return changed
173+
}

0 commit comments

Comments
 (0)