Skip to content

Commit

Permalink
chore: remove isSharding field of the backupPolicyTemplate (#7068)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Apr 18, 2024
1 parent 5853db2 commit a916e1d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
4 changes: 0 additions & 4 deletions apis/apps/v1alpha1/backuppolicytemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ type BackupPolicy struct {
// +optional
ComponentDefRef string `json:"componentDefRef,omitempty"`

// Specifies that this componentDef is a shading component definition.
// +optional
IsSharding bool `json:"isSharding,omitempty"`

// References to componentDefinitions.
// Must comply with the IANA Service Naming rule.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,6 @@ spec:
items:
type: string
type: array
isSharding:
description: Specifies that this componentDef is a shading component
definition.
type: boolean
schedules:
description: Define the policy for backup scheduling.
items:
Expand Down
32 changes: 17 additions & 15 deletions controllers/apps/transformer_cluster_backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (r *clusterBackupPolicyTransformer) Transform(ctx graph.TransformContext, d
backupScheduleNames := map[string]struct{}{}
// Note: In a cluster with multiple components referencing the same componentDefinition,
// only the backupPolicy associated with the first component will be created.
// TODO: create backupPolicy by foreach component and sharding
for _, tpl := range backupPolicyTPLs.Items {
r.isDefaultTemplate = tpl.Annotations[dptypes.DefaultBackupPolicyTemplateAnnotationKey]
r.tplIdentifier = tpl.Spec.Identifier
Expand Down Expand Up @@ -389,7 +390,7 @@ func (r *clusterBackupPolicyTransformer) syncBackupMethods(backupPolicy *dpv1alp
backupMethod = m
delete(oldBackupMethodMap, backupMethod.Name)
} else if v.Target != nil {
if r.backupPolicy.IsSharding {
if r.shardingSpec != nil {
backupMethod.Targets = r.buildBackupTargets(backupMethod.Targets, comp)
} else {
backupMethod.Target = r.buildBackupTarget(backupMethod.Target, *v.Target, comp)
Expand Down Expand Up @@ -431,7 +432,7 @@ func (r *clusterBackupPolicyTransformer) doEnvMapping(comp *appsv1alpha1.Cluster
}

func (r *clusterBackupPolicyTransformer) syncBackupPolicyTargetSpec(backupPolicy *dpv1alpha1.BackupPolicy, comp *appsv1alpha1.ClusterComponentSpec) {
if r.backupPolicy.IsSharding {
if r.shardingSpec != nil {
backupPolicy.Spec.Targets = r.buildBackupTargets(backupPolicy.Spec.Targets, comp)
} else {
backupPolicy.Spec.Target = r.buildBackupTarget(backupPolicy.Spec.Target, r.backupPolicy.Target, comp)
Expand Down Expand Up @@ -480,7 +481,7 @@ func (r *clusterBackupPolicyTransformer) buildBackupTarget(
// dataprotection will use its dedicated service account if this field is empty.
ServiceAccountName: "",
}
if r.backupPolicy.IsSharding {
if r.shardingSpec != nil {
target.Name = comp.Name
}
// build the target connection credential
Expand Down Expand Up @@ -622,20 +623,21 @@ func (r *clusterBackupPolicyTransformer) mergeClusterBackup(

// getClusterComponentSpec returns the first component name of the componentDefRef.
func (r *clusterBackupPolicyTransformer) getClusterComponentSpec() *appsv1alpha1.ClusterComponentSpec {
if !r.backupPolicy.IsSharding {
for i, v := range r.clusterTransformContext.Cluster.Spec.ComponentSpecs {
if len(v.ComponentDef) > 0 {
if slices.Contains(r.backupPolicy.ComponentDefs, v.ComponentDef) {
return &r.clusterTransformContext.Cluster.Spec.ComponentSpecs[i]
}
continue
}
if v.ComponentDefRef == r.backupPolicy.ComponentDefRef {
return &v
// 1. get the componentSpec from cluster.spec.componentSpecs firstly.
for i, v := range r.clusterTransformContext.Cluster.Spec.ComponentSpecs {
if len(v.ComponentDef) > 0 {
if slices.Contains(r.backupPolicy.ComponentDefs, v.ComponentDef) {
r.shardingSpec = nil
return &r.clusterTransformContext.Cluster.Spec.ComponentSpecs[i]
}
continue
}
if v.ComponentDefRef == r.backupPolicy.ComponentDefRef {
r.shardingSpec = nil
return &v
}
return nil
}
// 2. if not found in cluster.spec.componentSpecs, try to find in cluster.spec.shardingSpecs
for _, v := range r.clusterTransformContext.Cluster.Spec.ShardingSpecs {
if len(v.Template.ComponentDef) > 0 {
if slices.Contains(r.backupPolicy.ComponentDefs, v.Template.ComponentDef) {
Expand Down Expand Up @@ -720,7 +722,7 @@ func (r *clusterBackupPolicyTransformer) buildTargetPodLabels(targetTpl appsv1al
// the role only works when the component has multiple replicas.
labels[constant.RoleLabelKey] = targetTpl.Role
}
if r.backupPolicy.IsSharding {
if r.shardingSpec != nil {
labels[constant.KBAppShardingNameLabelKey] = r.shardingSpec.Name
}
return labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,6 @@ spec:
items:
type: string
type: array
isSharding:
description: Specifies that this componentDef is a shading component
definition.
type: boolean
schedules:
description: Define the policy for backup scheduling.
items:
Expand Down

0 comments on commit a916e1d

Please sign in to comment.