Skip to content

Commit

Permalink
Refactor cmpopts
Browse files Browse the repository at this point in the history
  • Loading branch information
PBundyra committed Nov 29, 2023
1 parent 051c9a6 commit d9bd130
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 30 deletions.
43 changes: 13 additions & 30 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package e2e

import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand All @@ -43,6 +44,13 @@ import (

var _ = ginkgo.Describe("Kueue visibility server", func() {
const defaultFlavor = "default-flavor"

// We do not check Name and OwnerReference's UID as they are generated
var pendingWorkloadsCmpOpts = []cmp.Option{
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Name"),
cmpopts.IgnoreFields(metav1.OwnerReference{}, "UID"),
}

var (
defaultRF *kueue.ResourceFlavor
localQueueA *kueue.LocalQueue
Expand Down Expand Up @@ -245,12 +253,7 @@ var _ = ginkgo.Describe("Kueue visibility server", func() {
info, err := visibilityClient.ClusterQueues().GetPendingWorkloadsSummary(ctx, clusterQueue.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return info.Items
// We do not check Name and OwnerReference's UID as they are generated
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(
wantPendingWorkloads,
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Name"),
cmpopts.IgnoreFields(metav1.OwnerReference{}, "UID"),
))
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(wantPendingWorkloads, pendingWorkloadsCmpOpts...))
})
})

Expand Down Expand Up @@ -351,12 +354,7 @@ var _ = ginkgo.Describe("Kueue visibility server", func() {
info, err := visibilityClient.LocalQueues(nsA.Name).GetPendingWorkloadsSummary(ctx, localQueueA.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return info.Items
// We do not check Name as it's generated for workloads
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(
wantPendingWorkloads,
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Name"),
cmpopts.IgnoreFields(metav1.OwnerReference{}, "UID"),
))
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(wantPendingWorkloads, pendingWorkloadsCmpOpts...))
})

ginkgo.By("Verify their positions and priorities in LocalQueueB", func() {
Expand Down Expand Up @@ -386,12 +384,7 @@ var _ = ginkgo.Describe("Kueue visibility server", func() {
info, err := visibilityClient.LocalQueues(nsA.Name).GetPendingWorkloadsSummary(ctx, localQueueB.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return info.Items
// We do not check Name as it's generated for workloads
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(
wantPendingWorkloads,
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Name"),
cmpopts.IgnoreFields(metav1.OwnerReference{}, "UID"),
))
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(wantPendingWorkloads, pendingWorkloadsCmpOpts...))
})
})
ginkgo.It("Should allow fetching information about position of pending workloads from different LocalQueues from different Namespaces", func() {
Expand Down Expand Up @@ -455,12 +448,7 @@ var _ = ginkgo.Describe("Kueue visibility server", func() {
info, err := visibilityClient.LocalQueues(nsA.Name).GetPendingWorkloadsSummary(ctx, localQueueA.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return info.Items
// We do not check Name as it's generated for workloads
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(
wantPendingWorkloads,
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Name"),
cmpopts.IgnoreFields(metav1.OwnerReference{}, "UID"),
))
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(wantPendingWorkloads, pendingWorkloadsCmpOpts...))
})

ginkgo.By("Verify their positions and priorities in LocalQueueB", func() {
Expand Down Expand Up @@ -490,12 +478,7 @@ var _ = ginkgo.Describe("Kueue visibility server", func() {
info, err := visibilityClient.LocalQueues(nsA.Name).GetPendingWorkloadsSummary(ctx, localQueueB.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return info.Items
// We do not check Name as it's generated for workloads
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(
wantPendingWorkloads,
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Name"),
cmpopts.IgnoreFields(metav1.OwnerReference{}, "UID"),
))
}, util.Timeout, util.Interval).Should(gomega.BeComparableTo(wantPendingWorkloads, pendingWorkloadsCmpOpts...))
})
})
})
Expand Down
47 changes: 47 additions & 0 deletions test/e2e/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# my-ksa.yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: test-pending-workloads-CQ-viewer-role
subjects:
- kind: ServiceAccount
name: my-ksa
namespace: default
roleRef:
kind: ClusterRole
name: pending-workloads-CQ-viewer-role
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: test-pending-workloads-LQ-viewer-role
subjects:
- kind: ServiceAccount
name: my-ksa
namespace: default
roleRef:
kind: Role
name: pending-workloads-LQ-viewer-role
apiGroup: rbac.authorization.k8s.io
# ---
# kind: ClusterRole
# apiVersion: rbac.authorization.k8s.io/v1
# metadata:
# name: my-cluster-role
# rules:
# - apiGroups: [""]
# # intentionally missing configmaps
# resources: ["namespaces", "pods", "secrets", "services"]
# verbs: ["get", "list", "watch"]
# - apiGroups: ["apps"]
# # intentionally missing deployments
# resources: ["daemonsets", "replicasets", "statefulsets"]
# verbs: ["get", "list", "watch"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-ksa
namespace: default

0 comments on commit d9bd130

Please sign in to comment.