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

chore: support for switchover in the sharding component by specifying the componentObjectName of the shard #8791

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 17 additions & 7 deletions apis/operations/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ type SpecificOpsRequest struct {
// Lists Switchover objects, each specifying a Component to perform the switchover operation.
//
// +optional
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.switchover"
SwitchoverList []Switchover `json:"switchover,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

Expand Down Expand Up @@ -239,7 +235,7 @@ type SpecificOpsRequest struct {

// ComponentOps specifies the Component to be operated on.
type ComponentOps struct {
// Specifies the name of the Component.
// Specifies the name of the Component as defined in the cluster.spec
// +kubebuilder:validation:Required
ComponentName string `json:"componentName"`
}
Expand Down Expand Up @@ -302,9 +298,16 @@ type Instance struct {
TargetNodeName string `json:"targetNodeName,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="(has(self.componentName) && !has(self.componentObjectName)) || (!has(self.componentName) && has(self.componentObjectName))",message="need to specified only componentName or componentObjectName"

type Switchover struct {
// Specifies the name of the Component.
ComponentOps `json:",inline"`
// Specifies the name of the Component as defined in the cluster.spec.
// +optional
ComponentName string `json:"componentName,omitempty"`

// Specifies the name of the Component object.
// +optional
ComponentObjectName string `json:"componentObjectName,omitempty"`

// Specifies the instance whose role will be transferred. A typical usage is to transfer the leader role
// in a consensus system.
Expand Down Expand Up @@ -1338,3 +1341,10 @@ func (p *ProgressStatusDetail) SetStatusAndMessage(status ProgressStatus, messag
p.Message = message
p.Status = status
}

func (s *Switchover) GetComponentName() string {
if len(s.ComponentObjectName) > 0 {
return s.ComponentObjectName
}
return s.ComponentName
}
11 changes: 8 additions & 3 deletions apis/operations/v1alpha1/opsrequest_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,14 @@ func (r *OpsRequest) validateSwitchover(cluster *appsv1.Cluster) error {
if len(switchoverList) == 0 {
return notEmptyError("spec.switchover")
}
compOpsList := make([]ComponentOps, len(switchoverList))
for i, v := range switchoverList {
compOpsList[i] = v.ComponentOps
compOpsList := make([]ComponentOps, 0)
for _, v := range switchoverList {
if len(v.ComponentName) == 0 {
continue
}
compOpsList = append(compOpsList, ComponentOps{
ComponentName: v.ComponentName,
})

}
if err := r.checkComponentExistence(cluster, compOpsList); err != nil {
Expand Down
1 change: 0 additions & 1 deletion apis/operations/v1alpha1/zz_generated.deepcopy.go

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

44 changes: 29 additions & 15 deletions config/crd/bases/operations.kubeblocks.io_opsrequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ spec:
items:
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
parameters:
description: Specifies the parameters that match the schema
Expand Down Expand Up @@ -562,7 +563,8 @@ spec:
scaling operation.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
scaleIn:
description: |-
Expand Down Expand Up @@ -4046,7 +4048,8 @@ spec:
- Logical backups (e.g., 'mysqldump' for MySQL) are unsupported in the current version.
type: string
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
inPlace:
description: |-
Expand Down Expand Up @@ -4223,7 +4226,8 @@ spec:
configuration.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
configurations:
description: |-
Expand Down Expand Up @@ -4323,7 +4327,8 @@ spec:
on.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
required:
- componentName
Expand Down Expand Up @@ -4533,7 +4538,8 @@ spec:
on.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
required:
- componentName
Expand All @@ -4554,7 +4560,8 @@ spec:
on.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
required:
- componentName
Expand All @@ -4579,21 +4586,25 @@ spec:
Refer to ComponentDefinition's Swtichover lifecycle action for more details.
type: string
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec.
type: string
componentObjectName:
description: Specifies the name of the Component object.
type: string
instanceName:
description: |-
Specifies the instance whose role will be transferred. A typical usage is to transfer the leader role
in a consensus system.
type: string
required:
- componentName
- instanceName
type: object
x-kubernetes-validations:
- message: need to specified only componentName or componentObjectName
rule: (has(self.componentName) && !has(self.componentObjectName))
|| (!has(self.componentName) && has(self.componentObjectName))
type: array
x-kubernetes-list-map-keys:
- componentName
x-kubernetes-list-type: map
x-kubernetes-validations:
- message: forbidden to update spec.switchover
rule: self == oldSelf
Expand Down Expand Up @@ -4666,7 +4677,8 @@ spec:
maxLength: 64
type: string
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
serviceVersion:
description: |-
Expand Down Expand Up @@ -4727,7 +4739,8 @@ spec:
- name
x-kubernetes-list-type: map
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
instances:
description: Specifies the desired compute resources of the
Expand Down Expand Up @@ -4839,7 +4852,8 @@ spec:
for a volume expansion operation.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
instances:
description: Specifies the desired storage size of the instance
Expand Down
44 changes: 29 additions & 15 deletions deploy/helm/crds/operations.kubeblocks.io_opsrequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ spec:
items:
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
parameters:
description: Specifies the parameters that match the schema
Expand Down Expand Up @@ -562,7 +563,8 @@ spec:
scaling operation.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
scaleIn:
description: |-
Expand Down Expand Up @@ -4046,7 +4048,8 @@ spec:
- Logical backups (e.g., 'mysqldump' for MySQL) are unsupported in the current version.
type: string
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
inPlace:
description: |-
Expand Down Expand Up @@ -4223,7 +4226,8 @@ spec:
configuration.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
configurations:
description: |-
Expand Down Expand Up @@ -4323,7 +4327,8 @@ spec:
on.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
required:
- componentName
Expand Down Expand Up @@ -4533,7 +4538,8 @@ spec:
on.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
required:
- componentName
Expand All @@ -4554,7 +4560,8 @@ spec:
on.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
required:
- componentName
Expand All @@ -4579,21 +4586,25 @@ spec:
Refer to ComponentDefinition's Swtichover lifecycle action for more details.
type: string
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec.
type: string
componentObjectName:
description: Specifies the name of the Component object.
type: string
instanceName:
description: |-
Specifies the instance whose role will be transferred. A typical usage is to transfer the leader role
in a consensus system.
type: string
required:
- componentName
- instanceName
type: object
x-kubernetes-validations:
- message: need to specified only componentName or componentObjectName
rule: (has(self.componentName) && !has(self.componentObjectName))
|| (!has(self.componentName) && has(self.componentObjectName))
type: array
x-kubernetes-list-map-keys:
- componentName
x-kubernetes-list-type: map
x-kubernetes-validations:
- message: forbidden to update spec.switchover
rule: self == oldSelf
Expand Down Expand Up @@ -4666,7 +4677,8 @@ spec:
maxLength: 64
type: string
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
serviceVersion:
description: |-
Expand Down Expand Up @@ -4727,7 +4739,8 @@ spec:
- name
x-kubernetes-list-type: map
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
instances:
description: Specifies the desired compute resources of the
Expand Down Expand Up @@ -4839,7 +4852,8 @@ spec:
for a volume expansion operation.
properties:
componentName:
description: Specifies the name of the Component.
description: Specifies the name of the Component as defined
in the cluster.spec
type: string
instances:
description: Specifies the desired storage size of the instance
Expand Down
Loading
Loading