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: replace 'shardingName' to isSharding of opsRequest.componentOps #7147

Merged
merged 3 commits into from
Apr 24, 2024
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
62 changes: 47 additions & 15 deletions apis/apps/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,50 @@ type OpsRequestSpec struct {

// Defines what component need to horizontal scale the specified replicas.
// +optional
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.horizontalScaling"
HorizontalScalingList []HorizontalScaling `json:"horizontalScaling,omitempty"`
HorizontalScalingList []HorizontalScaling `json:"horizontalScaling,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Note: Quantity struct can not do immutable check by CEL.
// Defines what component and volumeClaimTemplate need to expand the specified storage.
// +optional
VolumeExpansionList []VolumeExpansion `json:"volumeExpansion,omitempty"`
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
VolumeExpansionList []VolumeExpansion `json:"volumeExpansion,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Restarts the specified components.
// +optional
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.restart"
// +kubebuilder:validation:MaxItems=1024
RestartList []ComponentOps `json:"restart,omitempty"`
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
RestartList []ComponentOps `json:"restart,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Switches over the specified components.
// +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"`
SwitchoverList []Switchover `json:"switchover,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Note: Quantity struct can not do immutable check by CEL.
// Defines what component need to vertical scale the specified compute resources.
// +kubebuilder:validation:MaxItems=1024
// +optional
VerticalScalingList []VerticalScaling `json:"verticalScaling,omitempty"`
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
VerticalScalingList []VerticalScaling `json:"verticalScaling,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Deprecated: replace by reconfigures.
// Defines the variables that need to input when updating configuration.
Expand All @@ -94,7 +114,11 @@ type OpsRequestSpec struct {
// Defines the variables that need to input when updating configuration.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.reconfigure"
// +optional
Reconfigures []Reconfigure `json:"reconfigures,omitempty"`
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
Reconfigures []Reconfigure `json:"reconfigures,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Defines services the component needs to expose.
// +optional
Expand Down Expand Up @@ -126,22 +150,26 @@ type OpsRequestSpec struct {

// Specifies the instances that require re-creation.
// +optional
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.rebuildFrom"
RebuildFrom []RebuildInstance `json:"rebuildFrom,omitempty"`
RebuildFrom []RebuildInstance `json:"rebuildFrom,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Specifies a custom operation as defined by OpsDefinition.
// +optional
CustomSpec *CustomOpsSpec `json:"customSpec,omitempty"`
}

// ComponentOps represents the common variables required for operations within the scope of a normal component/shard component.
// +kubebuilder:validation:XValidation:rule="(has(self.componentName) && !has(self.shardingName)) || (has(self.shardingName) && !has(self.componentName))",message="either componentName or shardingName"
type ComponentOps struct {
// Specifies the name of the cluster component.
ComponentName string `json:"componentName,omitempty"`
// +kubebuilder:validation:Required
ComponentName string `json:"componentName"`

// Specifies the name of the cluster sharding component.
ShardingName string `json:"shardingName,omitempty"`
// Specifies that the componentName refers to the cluster's sharding component.
IsSharding bool `json:"isSharding,omitempty"`
}

type RebuildInstance struct {
Expand Down Expand Up @@ -355,10 +383,14 @@ type CustomOpsSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=1024
CustomOpsItems []CustomOpsItem `json:"items"`
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
CustomOpsItems []CustomOpsComponent `json:"components" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`
}

type CustomOpsItem struct {
type CustomOpsComponent struct {
ComponentOps `json:",inline"`

// Represents the parameters for this operation as declared in the opsDefinition.spec.parametersSchema.
Expand Down Expand Up @@ -994,8 +1026,8 @@ func (c ComponentOps) GetComponentName() string {
return c.ComponentName
}

func (c ComponentOps) GetShardingName() string {
return c.ShardingName
func (c ComponentOps) IsShardingComponent() bool {
return c.IsSharding
}

// ToExposeListToMap build expose map
Expand Down
38 changes: 18 additions & 20 deletions apis/apps/v1alpha1/opsrequest_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ func (r *OpsRequest) checkInstanceTemplate(cluster *Cluster, componentOps Compon
instanceNameMap[instances[i].Name] = sets.Empty{}
}
}
if componentOps.ShardingName != "" {
if componentOps.IsSharding {
for _, shardingSpec := range cluster.Spec.ShardingSpecs {
if shardingSpec.Name != componentOps.ShardingName {
if shardingSpec.Name != componentOps.ComponentName {
continue
}
setInstanceMap(shardingSpec.Template.Instances)
Expand Down Expand Up @@ -483,19 +483,17 @@ func (r *OpsRequest) checkComponentExistence(cluster *Cluster, compOpsList []Com
notFoundShardingNames []string
)
for _, compOps := range compOpsList {
if compOps.ComponentName != "" {
if _, ok := compSpecNameMap[compOps.ComponentName]; !ok {
notFoundCompNames = append(notFoundCompNames, compOps.ComponentName)
if compOps.IsSharding {
if _, ok := shardingMap[compOps.ComponentName]; !ok {
notFoundShardingNames = append(notFoundShardingNames, compOps.ComponentName)
}
continue
}
if compOps.ShardingName != "" {
if _, ok := shardingMap[compOps.ShardingName]; !ok {
notFoundShardingNames = append(notFoundShardingNames, compOps.ShardingName)
} else {
if _, ok := compSpecNameMap[compOps.ComponentName]; !ok {
notFoundCompNames = append(notFoundCompNames, compOps.ComponentName)
}
continue
}
return fmt.Errorf("shardingName or componentName can not be empty")
}

if len(notFoundCompNames) > 0 {
Expand All @@ -517,19 +515,19 @@ func (r *OpsRequest) checkVolumesAllowExpansion(ctx context.Context, cli client.

vols := make(map[string]map[string]Entity)
// component name/ sharding name -> vct name -> entity
getKey := func(compName, shardingName, templateName string) string {
getKey := func(compOps ComponentOps, templateName string) string {
templateKey := ""
if templateName != "" {
templateKey = "." + templateName
}
if compName != "" {
return fmt.Sprintf("component.%s%s", compName, templateKey)
if compOps.IsSharding {
return fmt.Sprintf("sharding.%s%s", compOps.ComponentName, templateKey)
}
return fmt.Sprintf("sharding.%s%s", shardingName, templateKey)
return fmt.Sprintf("component.%s%s", compOps.ComponentName, templateKey)
}
setVols := func(vcts []OpsRequestVolumeClaimTemplate, compOps ComponentOps, templateName string) {
for _, vct := range vcts {
key := getKey(compOps.ComponentName, compOps.ShardingName, templateName)
key := getKey(compOps, templateName)
if _, ok := vols[key]; !ok {
vols[key] = make(map[string]Entity)
}
Expand All @@ -552,27 +550,27 @@ func (r *OpsRequest) checkVolumesAllowExpansion(ctx context.Context, cli client.
e.storageClassName = vct.Spec.StorageClassName
vols[key][vct.Name] = e
}
fillCompVols := func(compSpec ClusterComponentSpec, compName, shardingName string) {
key := getKey(compName, shardingName, "")
fillCompVols := func(compSpec ClusterComponentSpec, compOps ComponentOps) {
key := getKey(compOps, "")
if _, ok := vols[key]; !ok {
return // ignore not-exist component
}
for _, vct := range compSpec.VolumeClaimTemplates {
fillVol(vct, key)
}
for _, ins := range compSpec.Instances {
key = getKey(compName, shardingName, ins.Name)
key = getKey(compOps, ins.Name)
for _, vct := range ins.VolumeClaimTemplates {
fillVol(vct, key)
}
}
}
// traverse the spec to update volumes
for _, comp := range cluster.Spec.ComponentSpecs {
fillCompVols(comp, comp.Name, "")
fillCompVols(comp, ComponentOps{ComponentName: comp.Name})
}
for _, sharding := range cluster.Spec.ShardingSpecs {
fillCompVols(sharding.Template, "", sharding.Name)
fillCompVols(sharding.Template, ComponentOps{ComponentName: sharding.Name, IsSharding: true})
}

// check all used storage classes
Expand Down
10 changes: 5 additions & 5 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

Loading
Loading