Skip to content

Commit

Permalink
Sort AdmissionChecks in a Workload
Browse files Browse the repository at this point in the history
  • Loading branch information
PBundyra committed Apr 16, 2024
1 parent 2dfd74d commit b80d470
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 7 additions & 2 deletions pkg/controller/core/workload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ limitations under the License.
package core

import (
"cmp"
"context"
"fmt"
"slices"
"time"

"github.com/go-logr/logr"
"github.com/google/go-cmp/cmp"
gocmp "github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
nodev1 "k8s.io/api/node/v1"
"k8s.io/apimachinery/pkg/api/equality"
Expand Down Expand Up @@ -338,6 +340,9 @@ func syncAdmissionCheckConditions(conds []kueue.AdmissionCheckState, admissionCh
}
conds = newConds
}
slices.SortFunc(conds, func(state1, state2 kueue.AdmissionCheckState) int {
return cmp.Compare(state1.Name, state2.Name)
})
return conds, shouldUpdate
}

Expand Down Expand Up @@ -752,7 +757,7 @@ func (w *workloadCqHandler) Update(ctx context.Context, ev event.UpdateEvent, wq

if !newCq.DeletionTimestamp.IsZero() ||
!utilslices.CmpNoOrder(oldCq.Spec.AdmissionChecks, newCq.Spec.AdmissionChecks) ||
!cmp.Equal(oldCq.Spec.AdmissionChecksStrategy, newCq.Spec.AdmissionChecksStrategy) ||
!gocmp.Equal(oldCq.Spec.AdmissionChecksStrategy, newCq.Spec.AdmissionChecksStrategy) ||
!ptr.Equal(oldCq.Spec.StopPolicy, newCq.Spec.StopPolicy) {
w.queueReconcileForWorkloads(ctx, newCq.Name, wq)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/controller/core/workload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ func TestSyncCheckStates(t *testing.T) {
t.Errorf("Unexpected should change, want=%v", tc.wantChange)
}

opts := []cmp.Option{
cmpopts.SortSlices(func(a, b kueue.AdmissionCheckState) bool { return a.Name < b.Name }),
}
opts := []cmp.Option{}
if tc.ignoreTransitionTime {
opts = append(opts, cmpopts.IgnoreFields(kueue.AdmissionCheckState{}, "LastTransitionTime"))
}
Expand All @@ -314,7 +312,6 @@ var (
cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime"),
cmpopts.IgnoreFields(kueue.AdmissionCheckState{}, "LastTransitionTime"),
cmpopts.SortSlices(func(a, b metav1.Condition) bool { return a.Type < b.Type }),
cmpopts.SortSlices(func(a, b kueue.AdmissionCheckState) bool { return a.Name < b.Name }),
}
)

Expand Down

0 comments on commit b80d470

Please sign in to comment.