Skip to content

Commit

Permalink
unexport cache ClusterQueue and Cohort (#2547)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabesaba authored Jul 8, 2024
1 parent a94a6bb commit 17db756
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 66 deletions.
20 changes: 10 additions & 10 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ type Cache struct {
podsReadyCond sync.Cond

client client.Client
clusterQueues map[string]*ClusterQueue
cohorts map[string]*Cohort
clusterQueues map[string]*clusterQueue
cohorts map[string]*cohort
assumedWorkloads map[string]string
resourceFlavors map[kueue.ResourceFlavorReference]*kueue.ResourceFlavor
podsReadyTracking bool
Expand All @@ -106,8 +106,8 @@ func New(client client.Client, opts ...Option) *Cache {
}
c := &Cache{
client: client,
clusterQueues: make(map[string]*ClusterQueue),
cohorts: make(map[string]*Cohort),
clusterQueues: make(map[string]*clusterQueue),
cohorts: make(map[string]*cohort),
assumedWorkloads: make(map[string]string),
resourceFlavors: make(map[kueue.ResourceFlavorReference]*kueue.ResourceFlavor),
admissionChecks: make(map[string]AdmissionCheck),
Expand All @@ -119,8 +119,8 @@ func New(client client.Client, opts ...Option) *Cache {
return c
}

func (c *Cache) newClusterQueue(cq *kueue.ClusterQueue) (*ClusterQueue, error) {
cqImpl := &ClusterQueue{
func (c *Cache) newClusterQueue(cq *kueue.ClusterQueue) (*clusterQueue, error) {
cqImpl := &clusterQueue{
Name: cq.Name,
Workloads: make(map[string]*workload.Info),
WorkloadsNotReady: sets.New[string](),
Expand Down Expand Up @@ -615,7 +615,7 @@ func (c *Cache) Usage(cqObj *kueue.ClusterQueue) (*ClusterQueueUsageStats, error
return stats, nil
}

func getUsage(frq resources.FlavorResourceQuantities, rgs []ResourceGroup, cohort *Cohort) []kueue.FlavorUsage {
func getUsage(frq resources.FlavorResourceQuantities, rgs []ResourceGroup, cohort *cohort) []kueue.FlavorUsage {
usage := make([]kueue.FlavorUsage, 0, len(frq))
for _, rg := range rgs {
for _, flvQuotas := range rg.Flavors {
Expand Down Expand Up @@ -717,7 +717,7 @@ func (c *Cache) cleanupAssumedState(w *kueue.Workload) {
}
}

func (c *Cache) clusterQueueForWorkload(w *kueue.Workload) *ClusterQueue {
func (c *Cache) clusterQueueForWorkload(w *kueue.Workload) *clusterQueue {
if workload.HasQuotaReservation(w) {
return c.clusterQueues[string(w.Status.Admission.ClusterQueue)]
}
Expand All @@ -730,7 +730,7 @@ func (c *Cache) clusterQueueForWorkload(w *kueue.Workload) *ClusterQueue {
return nil
}

func (c *Cache) addClusterQueueToCohort(cq *ClusterQueue, cohortName string) {
func (c *Cache) addClusterQueueToCohort(cq *clusterQueue, cohortName string) {
if cohortName == "" {
return
}
Expand All @@ -743,7 +743,7 @@ func (c *Cache) addClusterQueueToCohort(cq *ClusterQueue, cohortName string) {
cq.Cohort = cohort
}

func (c *Cache) deleteClusterQueueFromCohort(cq *ClusterQueue) {
func (c *Cache) deleteClusterQueueFromCohort(cq *clusterQueue) {
if cq.Cohort == nil {
return
}
Expand Down
40 changes: 20 additions & 20 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
name string
operation func(*Cache) error
clientObjects []client.Object
wantClusterQueues map[string]*ClusterQueue
wantClusterQueues map[string]*clusterQueue
wantCohorts map[string]sets.Set[string]
enableLendingLimit bool
}{
Expand All @@ -104,7 +104,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
operation: func(cache *Cache) error {
return setup(cache)
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 1,
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
}
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
AllocatableResourceGeneration: 1,
Expand All @@ -234,7 +234,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
}
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
AllocatableResourceGeneration: 1,
Expand All @@ -260,7 +260,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
Obj())
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 1,
Expand Down Expand Up @@ -391,7 +391,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
Obj())
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 2,
Expand Down Expand Up @@ -497,7 +497,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
}
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"b": {
Name: "b",
AllocatableResourceGeneration: 1,
Expand Down Expand Up @@ -575,7 +575,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
})
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 1,
Expand Down Expand Up @@ -694,7 +694,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
}
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
NamespaceSelector: labels.Everything(),
Expand Down Expand Up @@ -739,7 +739,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
}
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
NamespaceSelector: labels.Everything(),
Expand Down Expand Up @@ -771,7 +771,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
cache.AddOrUpdateAdmissionCheck(utiltesting.MakeAdmissionCheck("check2").Active(metav1.ConditionTrue).Obj())
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
NamespaceSelector: labels.Everything(),
Expand Down Expand Up @@ -804,7 +804,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
cache.DeleteAdmissionCheck(utiltesting.MakeAdmissionCheck("check2").Obj())
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
NamespaceSelector: labels.Everything(),
Expand Down Expand Up @@ -837,7 +837,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
cache.AddOrUpdateAdmissionCheck(utiltesting.MakeAdmissionCheck("check2").Active(metav1.ConditionFalse).Obj())
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
NamespaceSelector: labels.Everything(),
Expand Down Expand Up @@ -888,7 +888,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
}
return nil
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"cq1": {
Name: "cq1",
NamespaceSelector: labels.Everything(),
Expand Down Expand Up @@ -990,7 +990,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
Obj()
return cache.AddClusterQueue(context.Background(), cq)
},
wantClusterQueues: map[string]*ClusterQueue{
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
NamespaceSelector: labels.Everything(),
Expand Down Expand Up @@ -1038,9 +1038,9 @@ func TestCacheClusterQueueOperations(t *testing.T) {
t.Errorf("Unexpected error during test operation: %s", err)
}
if diff := cmp.Diff(tc.wantClusterQueues, cache.clusterQueues,
cmpopts.IgnoreFields(ClusterQueue{}, "Cohort", "ResourceGroups"),
cmpopts.IgnoreFields(clusterQueue{}, "Cohort", "ResourceGroups"),
cmpopts.IgnoreFields(workload.Info{}, "Obj", "LastAssignment"),
cmpopts.IgnoreUnexported(ClusterQueue{}),
cmpopts.IgnoreUnexported(clusterQueue{}),
cmpopts.EquateEmpty()); diff != "" {
t.Errorf("Unexpected clusterQueues (-want,+got):\n%s", diff)
}
Expand Down Expand Up @@ -2949,7 +2949,7 @@ func TestIsAssumedOrAdmittedCheckWorkload(t *testing.T) {
}, {
name: "Workload Is not Assumed but is Admitted",
cache: &Cache{
clusterQueues: map[string]*ClusterQueue{
clusterQueues: map[string]*clusterQueue{
"ClusterQueue1": {
Name: "ClusterQueue1",
Workloads: map[string]*workload.Info{"workload_namespace/workload_name": {
Expand All @@ -2976,7 +2976,7 @@ func TestIsAssumedOrAdmittedCheckWorkload(t *testing.T) {
}, {
name: "Workload Is Assumed and Admitted",
cache: &Cache{
clusterQueues: map[string]*ClusterQueue{
clusterQueues: map[string]*clusterQueue{
"ClusterQueue1": {
Name: "ClusterQueue1",
Workloads: map[string]*workload.Info{"workload_namespace/workload_name": {
Expand All @@ -3003,7 +3003,7 @@ func TestIsAssumedOrAdmittedCheckWorkload(t *testing.T) {
}, {
name: "Workload Is not Assumed and is not Admitted",
cache: &Cache{
clusterQueues: map[string]*ClusterQueue{
clusterQueues: map[string]*clusterQueue{
"ClusterQueue1": {
Name: "ClusterQueue1",
Workloads: map[string]*workload.Info{"workload_namespace2/workload_name2": {
Expand Down
Loading

0 comments on commit 17db756

Please sign in to comment.