Skip to content

Commit

Permalink
make candidates order stable (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdsteelRail authored Sep 26, 2024
1 parent 8baf05f commit d3d15f2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/controllers/operationjob/operationjob_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ var _ = Describe("operationjob controller", func() {
Expect(c.Get(ctx, types.NamespacedName{Namespace: oj.Namespace, Name: oj.Name}, oj)).Should(BeNil())
replacingPod := 0
for i := range podList.Items {
if _, exist := podList.Items[i].Labels[appsv1alpha1.PodReplacePairOriginName]; exist {
if name, exist := podList.Items[i].Labels[appsv1alpha1.PodReplacePairOriginName]; exist {
Expect(name).Should(BeEquivalentTo(oj.Spec.Targets[partition-1].Name))
replacingPod++
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controllers/operationjob/operationjob_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ func (r *ReconcileOperationJob) getActionHandler(operationJob *appsv1alpha1.Oper
func (r *ReconcileOperationJob) listTargets(ctx context.Context, operationJob *appsv1alpha1.OperationJob) ([]*OpsCandidate, error) {
var candidates []*OpsCandidate
podOpsStatusMap := ojutils.MapOpsStatusByPod(operationJob)
for _, target := range operationJob.Spec.Targets {
for idx := range operationJob.Spec.Targets {
target := operationJob.Spec.Targets[idx]
var candidate OpsCandidate
var pod corev1.Pod

candidate.Idx = idx
// fulfil target pod
candidate.PodName = target.Name
err := r.Client.Get(ctx, types.NamespacedName{Namespace: operationJob.Namespace, Name: target.Name}, &pod)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/operationjob/opscore/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

type OpsCandidate struct {
Idx int
*corev1.Pod
PodName string
Containers []string
Expand Down Expand Up @@ -62,7 +63,7 @@ func (o activeCandidateToStart) Less(i, j int) bool {
if lNotStarted != rNotStarted {
return rNotStarted
}
return true
return l.Idx < r.Idx
}

func IsCandidateOpsPending(candidate *OpsCandidate) bool {
Expand Down

0 comments on commit d3d15f2

Please sign in to comment.