Skip to content

Commit

Permalink
optimize workloadspread when suitable subset maxReplicas is niil
Browse files Browse the repository at this point in the history
Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
  • Loading branch information
mingzhou.swx committed Aug 26, 2022
1 parent bdd3efb commit 5369da5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 7 additions & 0 deletions pkg/util/workloadspread/workloadspread.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ func (h *Handler) updateSubsetForPod(ws *appsv1alpha1.WorkloadSpread,
ws.Namespace, ws.Name, pod.Name)
return false, nil, ""
}
// no need to update WorkloadSpread status if MaxReplicas == nil
if suitableSubset.MissingReplicas == -1 {
return false, suitableSubset, ""
}
if suitableSubset.CreatingPods == nil {
suitableSubset.CreatingPods = map[string]metav1.Time{}
}
Expand All @@ -483,6 +487,9 @@ func (h *Handler) updateSubsetForPod(ws *appsv1alpha1.WorkloadSpread,
klog.V(5).Infof("Pod (%s/%s) matched WorkloadSpread (%s) not found Subset(%s)", ws.Namespace, pod.Name, ws.Name, injectWS.Subset)
return false, nil, ""
}
if suitableSubset.MissingReplicas == -1 {
return false, suitableSubset, ""
}
if suitableSubset.DeletingPods == nil {
suitableSubset.DeletingPods = map[string]metav1.Time{}
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/util/workloadspread/workloadspread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ func TestWorkloadSpreadCreatePodWithoutFullName(t *testing.T) {
ws := workloadSpreadDemo.DeepCopy()
ws.Status.SubsetStatuses[0].MissingReplicas = 0
subset := appsv1alpha1.WorkloadSpreadSubset{
Name: "subset-b",
Name: "subset-b",
MaxReplicas: &intstr.IntOrString{Type: intstr.Int, IntVal: 2},
RequiredNodeSelectorTerm: &corev1.NodeSelectorTerm{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Expand All @@ -177,7 +178,7 @@ func TestWorkloadSpreadCreatePodWithoutFullName(t *testing.T) {
ws.Spec.Subsets = append(ws.Spec.Subsets, subset)
status := appsv1alpha1.WorkloadSpreadSubsetStatus{
Name: "subset-b",
MissingReplicas: -1,
MissingReplicas: 2,
CreatingPods: map[string]metav1.Time{},
DeletingPods: map[string]metav1.Time{},
}
Expand Down Expand Up @@ -365,7 +366,6 @@ func TestWorkloadSpreadMutatingPod(t *testing.T) {
}
demo.Status.SubsetStatuses = append(demo.Status.SubsetStatuses, status)
demo.ResourceVersion = "1"
demo.Status.SubsetStatuses[1].CreatingPods[podDemo.Name] = metav1.Time{Time: defaultTime}
return demo
},
},
Expand Down Expand Up @@ -493,7 +493,6 @@ func TestWorkloadSpreadMutatingPod(t *testing.T) {
workloadSpread := workloadSpreadDemo.DeepCopy()
workloadSpread.ResourceVersion = "1"
workloadSpread.Status.SubsetStatuses[0].MissingReplicas = -1
workloadSpread.Status.SubsetStatuses[0].CreatingPods[podDemo.Name] = metav1.Time{Time: defaultTime}
return workloadSpread
},
},
Expand Down Expand Up @@ -738,7 +737,6 @@ func TestWorkloadSpreadMutatingPod(t *testing.T) {
expectWorkloadSpread: func() *appsv1alpha1.WorkloadSpread {
workloadSpread := workloadSpreadDemo.DeepCopy()
workloadSpread.Status.SubsetStatuses[0].MissingReplicas = -1
workloadSpread.Status.SubsetStatuses[0].DeletingPods[podDemo.Name] = metav1.Time{Time: defaultTime}
return workloadSpread
},
},
Expand Down

0 comments on commit 5369da5

Please sign in to comment.