Skip to content

Commit

Permalink
fix: set default update strategy for RSM (apecloud#6336)
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf authored Jan 5, 2024
1 parent 0ea3cb7 commit 7e6e0f6
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions pkg/controller/component/rsm_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,34 @@ type rsmMembershipReconfigurationConvertor struct{}
// rsmMemberUpdateStrategyConvertor is an implementation of the convertor interface, used to convert the given object into ReplicatedStateMachine.Spec.MemberUpdateStrategy.
type rsmMemberUpdateStrategyConvertor struct{}

func (c *rsmMemberUpdateStrategyConvertor) convert(args ...any) (any, error) {
synthesizedComp, err := parseRSMConvertorArgs(args...)
if err != nil {
return nil, err
}
return getMemberUpdateStrategy(synthesizedComp), nil
}

// rsmPodManagementPolicyConvertor is an implementation of the convertor interface, used to convert the given object into ReplicatedStateMachine.Spec.PodManagementPolicy.
type rsmPodManagementPolicyConvertor struct{}

// rsmUpdateStrategyConvertor is an implementation of the convertor interface, used to convert the given object into ReplicatedStateMachine.Spec.UpdateStrategy.
type rsmUpdateStrategyConvertor struct{}

func (c *rsmUpdateStrategyConvertor) convert(args ...any) (any, error) {
synthesizedComp, err := parseRSMConvertorArgs(args...)
if err != nil {
return nil, err
}
if getMemberUpdateStrategy(synthesizedComp) != nil {
// appsv1.OnDeleteStatefulSetStrategyType is the default value if member update strategy is set.
return appsv1.StatefulSetUpdateStrategy{
Type: appsv1.OnDeleteStatefulSetStrategyType,
}, nil
}
return nil, nil
}

// parseRSMConvertorArgs parses the args of rsm convertor.
func parseRSMConvertorArgs(args ...any) (*SynthesizedComponent, error) {
synthesizeComp, ok := args[0].(*SynthesizedComponent)
Expand All @@ -91,6 +113,27 @@ func parseRSMConvertorArgs(args ...any) (*SynthesizedComponent, error) {
return synthesizeComp, nil
}

func getMemberUpdateStrategy(synthesizedComp *SynthesizedComponent) *workloads.MemberUpdateStrategy {
if synthesizedComp.UpdateStrategy == nil {
return nil
}
var (
serial = workloads.SerialUpdateStrategy
parallelUpdate = workloads.ParallelUpdateStrategy
bestEffortParallelUpdate = workloads.BestEffortParallelUpdateStrategy
)
switch *synthesizedComp.UpdateStrategy {
case appsv1alpha1.SerialStrategy:
return &serial
case appsv1alpha1.ParallelStrategy:
return &parallelUpdate
case appsv1alpha1.BestEffortParallelStrategy:
return &bestEffortParallelUpdate
default:
return nil
}
}

// rsmServiceConvertor converts the given object into ReplicatedStateMachine.Spec.Service.
// TODO(xingran): ComponentServices are not consistent with ReplicatedStateMachine.Spec.Service, If it is based on the new ComponentDefinition API,
// the services is temporarily handled in the component controller, and the corresponding ReplicatedStateMachine.Spec.Service is temporarily set nil.
Expand Down Expand Up @@ -229,39 +272,12 @@ func (c *rsmMembershipReconfigurationConvertor) convert(args ...any) (any, error
return "", nil // TODO
}

func (c *rsmMemberUpdateStrategyConvertor) convert(args ...any) (any, error) {
synthesizeComp, err := parseRSMConvertorArgs(args...)
if err != nil {
return nil, err
}
var memberUpdateStrategy *workloads.MemberUpdateStrategy
switch *synthesizeComp.UpdateStrategy {
case appsv1alpha1.SerialStrategy:
memberSerialUpdateStrategy := workloads.SerialUpdateStrategy
memberUpdateStrategy = &memberSerialUpdateStrategy
case appsv1alpha1.ParallelStrategy:
memberParallelUpdateStrategy := workloads.ParallelUpdateStrategy
memberUpdateStrategy = &memberParallelUpdateStrategy
case appsv1alpha1.BestEffortParallelStrategy:
memberBestEffortParallelUpdateStrategy := workloads.BestEffortParallelUpdateStrategy
memberUpdateStrategy = &memberBestEffortParallelUpdateStrategy
default:
return nil, err
}
return memberUpdateStrategy, err
}

func (c *rsmPodManagementPolicyConvertor) convert(args ...any) (any, error) {
// componentDefinition does not define PodManagementPolicy and StatefulSetUpdateStrategy.
// The Parallel strategy is used by default here. If necessary, the componentDefinition API can be expanded later
return appsv1.ParallelPodManagement, nil
}

func (c *rsmUpdateStrategyConvertor) convert(args ...any) (any, error) {
// synthesizeComp, err := parseRSMConvertorArgs(args...)
return "", nil // TODO
}

// ConvertSynthesizeCompRoleToRSMRole converts the component.SynthesizedComponent.Roles to workloads.ReplicaRole.
func ConvertSynthesizeCompRoleToRSMRole(synthesizedComp *SynthesizedComponent) []workloads.ReplicaRole {
if synthesizedComp.Roles == nil {
Expand Down

0 comments on commit 7e6e0f6

Please sign in to comment.