Skip to content

Commit

Permalink
refactor: update the PodUpdateStrategyType from ReplaceUpdate to Repl…
Browse files Browse the repository at this point in the history
…ace (#175)

* refactor: update the PodUpdateStrategyType from ReplaceUpdate to Replace

* refactor: fix ut
  • Loading branch information
wu8685 committed Mar 28, 2024
1 parent 4544135 commit d8f290b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
7 changes: 3 additions & 4 deletions apis/apps/v1alpha1/collaset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ const (
// CollaSetInPlaceOnlyPodUpdateStrategyType indicates that CollaSet will always update Pod in-place, instead of
// recreating pod. It will encounter an error on original Kubernetes cluster.
CollaSetInPlaceOnlyPodUpdateStrategyType PodUpdateStrategyType = "InPlaceOnly"

// CollaSetReplaceUpdatePodUpdateStrategyType indicates that CollaSet will always update Pod by replace, it will
// create a new Pod and delete update pod when new created pod service available.
CollaSetReplaceUpdatePodUpdateStrategyType PodUpdateStrategyType = "ReplaceUpdate"
// CollaSetReplacePodUpdateStrategyType indicates that CollaSet will always update Pod by replace, it will
// create a new Pod and delete the old pod when the new one service available.
CollaSetReplacePodUpdateStrategyType PodUpdateStrategyType = "Replace"
)

// CollaSetSpec defines the desired state of CollaSet
Expand Down
10 changes: 5 additions & 5 deletions pkg/controllers/collaset/collaset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ var _ = Describe("collaset controller", func() {
},
UpdateStrategy: appsv1alpha1.UpdateStrategy{
OperationDelaySeconds: int32Pointer(1),
PodUpdatePolicy: appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType,
PodUpdatePolicy: appsv1alpha1.CollaSetReplacePodUpdateStrategyType,
},
},
}
Expand Down Expand Up @@ -786,7 +786,7 @@ var _ = Describe("collaset controller", func() {
},
UpdateStrategy: appsv1alpha1.UpdateStrategy{
OperationDelaySeconds: int32Pointer(1),
PodUpdatePolicy: appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType,
PodUpdatePolicy: appsv1alpha1.CollaSetReplacePodUpdateStrategyType,
},
},
}
Expand Down Expand Up @@ -940,7 +940,7 @@ var _ = Describe("collaset controller", func() {
},
UpdateStrategy: appsv1alpha1.UpdateStrategy{
OperationDelaySeconds: int32Pointer(1),
PodUpdatePolicy: appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType,
PodUpdatePolicy: appsv1alpha1.CollaSetReplacePodUpdateStrategyType,
},
},
}
Expand Down Expand Up @@ -1041,7 +1041,7 @@ var _ = Describe("collaset controller", func() {
},
UpdateStrategy: appsv1alpha1.UpdateStrategy{
OperationDelaySeconds: int32Pointer(1),
PodUpdatePolicy: appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType,
PodUpdatePolicy: appsv1alpha1.CollaSetReplacePodUpdateStrategyType,
},
},
}
Expand Down Expand Up @@ -1599,7 +1599,7 @@ var _ = Describe("collaset controller", func() {
Partition: &partition,
},
}
cls.Spec.UpdateStrategy.PodUpdatePolicy = appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType
cls.Spec.UpdateStrategy.PodUpdatePolicy = appsv1alpha1.CollaSetReplacePodUpdateStrategyType
cls.Spec.ScaleStrategy.OperationDelaySeconds = int32Pointer(1)
cls.Spec.Template.Spec.Containers[0].Image = "nginx:v2"
return true
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/collaset/synccontrol/sync_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func dealReplacePods(pods []*corev1.Pod, instance *appsv1alpha1.CollaSet) (needR

needReplacePods = append(needReplacePods, pod)
}
isReplaceUpdate := instance.Spec.UpdateStrategy.PodUpdatePolicy == appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType
isReplaceUpdate := instance.Spec.UpdateStrategy.PodUpdatePolicy == appsv1alpha1.CollaSetReplacePodUpdateStrategyType
// deal pods need to delete when pod update strategy is not replace update

for _, pod := range pods {
Expand Down Expand Up @@ -709,7 +709,7 @@ func (r *RealSyncControl) Update(
updating := false
analysedPod := sets.NewString()

if cls.Spec.UpdateStrategy.PodUpdatePolicy != appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType {
if cls.Spec.UpdateStrategy.PodUpdatePolicy != appsv1alpha1.CollaSetReplacePodUpdateStrategyType {
// 3. prepare Pods to begin PodOpsLifecycle
for i, podInfo := range podToUpdate {
if podInfo.IsUpdatedRevision && !podInfo.PodDecorationChanged {
Expand Down Expand Up @@ -852,7 +852,7 @@ func (r *RealSyncControl) Update(
return err
}
}
} else if cls.Spec.UpdateStrategy.PodUpdatePolicy == appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType {
} else if cls.Spec.UpdateStrategy.PodUpdatePolicy == appsv1alpha1.CollaSetReplacePodUpdateStrategyType {
return nil
} else {
// 6.2 if pod has changes not in-place supported, recreate it
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/collaset/synccontrol/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func newPodUpdater(ctx context.Context, client client.Client, cls *appsv1alpha1.
// In case of using native K8s, Pod is only allowed to update with container image, so InPlaceOnly policy is
// implemented with InPlaceIfPossible policy as default for compatibility.
return &inPlaceIfPossibleUpdater{collaSet: cls, ctx: ctx, Client: client}
case appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType:
case appsv1alpha1.CollaSetReplacePodUpdateStrategyType:
return &replaceUpdatePodUpdater{collaSet: cls, ctx: ctx, Client: client}
default:
return &inPlaceIfPossibleUpdater{collaSet: cls, ctx: ctx, Client: client}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ func (h *ValidatingHandler) validateUpdateStrategy(cls *appsv1alpha1.CollaSet, f
case appsv1alpha1.CollaSetRecreatePodUpdateStrategyType,
appsv1alpha1.CollaSetInPlaceOnlyPodUpdateStrategyType,
appsv1alpha1.CollaSetInPlaceIfPossiblePodUpdateStrategyType,
appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType:
appsv1alpha1.CollaSetReplacePodUpdateStrategyType:
default:
allErrs = append(allErrs, field.NotSupported(fSpec.Child("updateStrategy", "podUpdatePolicy"),
cls.Spec.UpdateStrategy.PodUpdatePolicy, []string{string(appsv1alpha1.CollaSetRecreatePodUpdateStrategyType),
string(appsv1alpha1.CollaSetInPlaceIfPossiblePodUpdateStrategyType),
string(appsv1alpha1.CollaSetInPlaceOnlyPodUpdateStrategyType),
string(appsv1alpha1.CollaSetReplaceUpdatePodUpdateStrategyType)}))
string(appsv1alpha1.CollaSetReplacePodUpdateStrategyType)}))
}

if cls.Spec.UpdateStrategy.RollingUpdate != nil && cls.Spec.UpdateStrategy.RollingUpdate.ByPartition != nil &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestValidatingCollaSet(t *testing.T) {
},
},
"invalid-update-policy": {
messageKeyWords: "supported values: \"ReCreate\", \"InPlaceIfPossible\", \"InPlaceOnly\", \"ReplaceUpdate\"",
messageKeyWords: "supported values: \"ReCreate\", \"InPlaceIfPossible\", \"InPlaceOnly\", \"Replace\"",
cls: &appsv1alpha1.CollaSet{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Expand Down

0 comments on commit d8f290b

Please sign in to comment.