Skip to content

Commit

Permalink
Use maps.Clone when snapshotting (kubernetes#1743)
Browse files Browse the repository at this point in the history
Change-Id: Ia1bf11a582edd14ad10edb6b1bb2018169ed21d2
  • Loading branch information
alculquicondor authored Feb 15, 2024
1 parent 01bd532 commit 8c65a23
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions pkg/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ limitations under the License.
package cache

import (
"maps"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"

kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
"sigs.k8s.io/kueue/pkg/features"
"sigs.k8s.io/kueue/pkg/util/maps"
utilmaps "sigs.k8s.io/kueue/pkg/util/maps"
"sigs.k8s.io/kueue/pkg/workload"
)

Expand Down Expand Up @@ -70,7 +72,7 @@ func (s *Snapshot) Log(log logr.Logger) {
"cohort", cohortName,
"resourceGroups", cq.ResourceGroups,
"usage", cq.Usage,
"workloads", maps.Keys(cq.Workloads),
"workloads", utilmaps.Keys(cq.Workloads),
)
}
for name, cohort := range cohorts {
Expand Down Expand Up @@ -128,24 +130,15 @@ func (c *ClusterQueue) snapshot() *ClusterQueue {
FlavorFungibility: c.FlavorFungibility,
AllocatableResourceGeneration: c.AllocatableResourceGeneration,
Usage: make(FlavorResourceQuantities, len(c.Usage)),
Workloads: make(map[string]*workload.Info, len(c.Workloads)),
Workloads: maps.Clone(c.Workloads),
Preemption: c.Preemption,
NamespaceSelector: c.NamespaceSelector,
Status: c.Status,
AdmissionChecks: c.AdmissionChecks.Clone(),
}
for fName, rUsage := range c.Usage {
rUsageCopy := make(map[corev1.ResourceName]int64, len(rUsage))
for k, v := range rUsage {
rUsageCopy[k] = v
}
cc.Usage[fName] = rUsageCopy
cc.Usage[fName] = maps.Clone(rUsage)
}
for k, v := range c.Workloads {
// Shallow copy is enough.
cc.Workloads[k] = v
}

if features.Enabled(features.LendingLimit) {
cc.GuaranteedQuota = c.GuaranteedQuota
}
Expand Down

0 comments on commit 8c65a23

Please sign in to comment.