Skip to content

Commit d535523

Browse files
authored
Merge pull request #836 from alexandear/refactor/sets-set
refactor: replace deprecated sets.String with sets.Set
2 parents b9bb804 + 6b81e87 commit d535523

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

pkg/capacityscheduling/capacity_scheduling_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func TestReserve(t *testing.T) {
385385
elasticQuotas: map[string]*ElasticQuotaInfo{
386386
"ns1": {
387387
Namespace: "ns1",
388-
pods: sets.String{},
388+
pods: sets.Set[string]{},
389389
Min: &framework.Resource{
390390
Memory: 1000,
391391
},
@@ -405,7 +405,7 @@ func TestReserve(t *testing.T) {
405405
{
406406
"ns1": {
407407
Namespace: "ns1",
408-
pods: sets.NewString("t1-p1"),
408+
pods: sets.New("t1-p1"),
409409
Min: &framework.Resource{
410410
Memory: 1000,
411411
},
@@ -423,7 +423,7 @@ func TestReserve(t *testing.T) {
423423
{
424424
"ns1": {
425425
Namespace: "ns1",
426-
pods: sets.NewString("t1-p1"),
426+
pods: sets.New("t1-p1"),
427427
Min: &framework.Resource{
428428
Memory: 1000,
429429
},
@@ -499,7 +499,7 @@ func TestUnreserve(t *testing.T) {
499499
elasticQuotas: map[string]*ElasticQuotaInfo{
500500
"ns1": {
501501
Namespace: "ns1",
502-
pods: sets.NewString("t1-p3", "t1-p4"),
502+
pods: sets.New("t1-p3", "t1-p4"),
503503
Min: &framework.Resource{
504504
Memory: 1000,
505505
},
@@ -515,7 +515,7 @@ func TestUnreserve(t *testing.T) {
515515
{
516516
"ns1": {
517517
Namespace: "ns1",
518-
pods: sets.NewString("t1-p3", "t1-p4"),
518+
pods: sets.New("t1-p3", "t1-p4"),
519519
Min: &framework.Resource{
520520
Memory: 1000,
521521
},
@@ -530,7 +530,7 @@ func TestUnreserve(t *testing.T) {
530530
{
531531
"ns1": {
532532
Namespace: "ns1",
533-
pods: sets.NewString("t1-p3", "t1-p4"),
533+
pods: sets.New("t1-p3", "t1-p4"),
534534
Min: &framework.Resource{
535535
Memory: 1000,
536536
},
@@ -545,7 +545,7 @@ func TestUnreserve(t *testing.T) {
545545
{
546546
"ns1": {
547547
Namespace: "ns1",
548-
pods: sets.NewString("t1-p4"),
548+
pods: sets.New("t1-p4"),
549549
Min: &framework.Resource{
550550
Memory: 1000,
551551
},
@@ -1030,7 +1030,7 @@ func TestAddElasticQuota(t *testing.T) {
10301030
expected: map[string]*ElasticQuotaInfo{
10311031
"ns1": {
10321032
Namespace: "ns1",
1033-
pods: sets.String{},
1033+
pods: sets.Set[string]{},
10341034
Max: &framework.Resource{
10351035
MilliCPU: 100,
10361036
Memory: 1000,
@@ -1055,7 +1055,7 @@ func TestAddElasticQuota(t *testing.T) {
10551055
expected: map[string]*ElasticQuotaInfo{
10561056
"ns1": {
10571057
Namespace: "ns1",
1058-
pods: sets.String{},
1058+
pods: sets.Set[string]{},
10591059
Max: &framework.Resource{
10601060
MilliCPU: UpperBoundOfMax,
10611061
Memory: UpperBoundOfMax,
@@ -1081,7 +1081,7 @@ func TestAddElasticQuota(t *testing.T) {
10811081
expected: map[string]*ElasticQuotaInfo{
10821082
"ns1": {
10831083
Namespace: "ns1",
1084-
pods: sets.String{},
1084+
pods: sets.Set[string]{},
10851085
Max: &framework.Resource{
10861086
MilliCPU: 100,
10871087
Memory: 1000,
@@ -1107,7 +1107,7 @@ func TestAddElasticQuota(t *testing.T) {
11071107
expected: map[string]*ElasticQuotaInfo{
11081108
"ns1": {
11091109
Namespace: "ns1",
1110-
pods: sets.String{},
1110+
pods: sets.Set[string]{},
11111111
Max: &framework.Resource{
11121112
MilliCPU: UpperBoundOfMax,
11131113
Memory: UpperBoundOfMax,
@@ -1182,7 +1182,7 @@ func TestUpdateElasticQuota(t *testing.T) {
11821182
expected: map[string]*ElasticQuotaInfo{
11831183
"ns1": {
11841184
Namespace: "ns1",
1185-
pods: sets.String{},
1185+
pods: sets.Set[string]{},
11861186
Max: &framework.Resource{
11871187
MilliCPU: 300,
11881188
Memory: 1000,
@@ -1309,7 +1309,7 @@ func TestAddPod(t *testing.T) {
13091309
expected: map[string]*ElasticQuotaInfo{
13101310
"ns1": {
13111311
Namespace: "ns1",
1312-
pods: sets.NewString("t1-p1", "t1-p2", "t1-p3"),
1312+
pods: sets.New("t1-p1", "t1-p2", "t1-p3"),
13131313
Max: &framework.Resource{
13141314
MilliCPU: 100,
13151315
Memory: 1000,
@@ -1389,7 +1389,7 @@ func TestUpdatePod(t *testing.T) {
13891389
expected: map[string]*ElasticQuotaInfo{
13901390
"ns1": {
13911391
Namespace: "ns1",
1392-
pods: sets.NewString("t1-p1"),
1392+
pods: sets.New("t1-p1"),
13931393
Max: &framework.Resource{
13941394
MilliCPU: 100,
13951395
Memory: 1000,
@@ -1421,7 +1421,7 @@ func TestUpdatePod(t *testing.T) {
14211421
expected: map[string]*ElasticQuotaInfo{
14221422
"ns1": {
14231423
Namespace: "ns1",
1424-
pods: sets.String{},
1424+
pods: sets.Set[string]{},
14251425
Max: &framework.Resource{
14261426
MilliCPU: 100,
14271427
Memory: 1000,
@@ -1505,7 +1505,7 @@ func TestDeletePod(t *testing.T) {
15051505
expected: map[string]*ElasticQuotaInfo{
15061506
"ns1": {
15071507
Namespace: "ns1",
1508-
pods: sets.NewString(),
1508+
pods: sets.New[string](),
15091509
Max: &framework.Resource{
15101510
MilliCPU: 100,
15111511
Memory: 1000,
@@ -1538,7 +1538,7 @@ func TestDeletePod(t *testing.T) {
15381538
expected: map[string]*ElasticQuotaInfo{
15391539
"ns1": {
15401540
Namespace: "ns1",
1541-
pods: sets.NewString("t1-p2"),
1541+
pods: sets.New("t1-p2"),
15421542
Max: &framework.Resource{
15431543
MilliCPU: 100,
15441544
Memory: 1000,

pkg/capacityscheduling/elasticquota.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (e ElasticQuotaInfos) aggregatedUsedOverMinWith(podRequest framework.Resour
6262
// Each namespace can only have one ElasticQuota.
6363
type ElasticQuotaInfo struct {
6464
Namespace string
65-
pods sets.String
65+
pods sets.Set[string]
6666
Min *framework.Resource
6767
Max *framework.Resource
6868
Used *framework.Resource
@@ -78,7 +78,7 @@ func newElasticQuotaInfo(namespace string, min, max, used v1.ResourceList) *Elas
7878

7979
elasticQuotaInfo := &ElasticQuotaInfo{
8080
Namespace: namespace,
81-
pods: sets.NewString(),
81+
pods: sets.New[string](),
8282
Min: framework.NewResource(min),
8383
Max: framework.NewResource(max),
8484
Used: framework.NewResource(used),
@@ -133,7 +133,7 @@ func (e *ElasticQuotaInfo) usedOverMin() bool {
133133
func (e *ElasticQuotaInfo) clone() *ElasticQuotaInfo {
134134
newEQInfo := &ElasticQuotaInfo{
135135
Namespace: e.Namespace,
136-
pods: sets.NewString(),
136+
pods: sets.New[string](),
137137
}
138138

139139
if e.Min != nil {
@@ -145,11 +145,8 @@ func (e *ElasticQuotaInfo) clone() *ElasticQuotaInfo {
145145
if e.Used != nil {
146146
newEQInfo.Used = e.Used.Clone()
147147
}
148-
if len(e.pods) > 0 {
149-
pods := e.pods.List()
150-
for _, pod := range pods {
151-
newEQInfo.pods.Insert(pod)
152-
}
148+
for pod := range e.pods {
149+
newEQInfo.pods.Insert(pod)
153150
}
154151

155152
return newEQInfo

pkg/capacityscheduling/elasticquota_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func TestNewElasticQuotaInfo(t *testing.T) {
526526
},
527527
expected: &ElasticQuotaInfo{
528528
Namespace: "ns1",
529-
pods: sets.String{},
529+
pods: sets.Set[string]{},
530530
Max: &framework.Resource{
531531
MilliCPU: 100,
532532
Memory: 1000,
@@ -551,7 +551,7 @@ func TestNewElasticQuotaInfo(t *testing.T) {
551551
},
552552
expected: &ElasticQuotaInfo{
553553
Namespace: "ns1",
554-
pods: sets.String{},
554+
pods: sets.Set[string]{},
555555
Max: &framework.Resource{
556556
MilliCPU: UpperBoundOfMax,
557557
Memory: UpperBoundOfMax,
@@ -577,7 +577,7 @@ func TestNewElasticQuotaInfo(t *testing.T) {
577577
},
578578
expected: &ElasticQuotaInfo{
579579
Namespace: "ns1",
580-
pods: sets.String{},
580+
pods: sets.Set[string]{},
581581
Max: &framework.Resource{
582582
MilliCPU: 100,
583583
Memory: 1000,
@@ -603,7 +603,7 @@ func TestNewElasticQuotaInfo(t *testing.T) {
603603
},
604604
expected: &ElasticQuotaInfo{
605605
Namespace: "ns1",
606-
pods: sets.String{},
606+
pods: sets.Set[string]{},
607607
Max: &framework.Resource{
608608
MilliCPU: UpperBoundOfMax,
609609
Memory: UpperBoundOfMax,

pkg/noderesourcetopology/cache/foreign_pods.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
// Note this is NOT lock-protected because the scheduling framework calls New() sequentially,
3636
// and plugin instances are meant to register their name using SetupForeignPodsDetector inside their New()
3737
var (
38-
schedProfileNames = sets.String{}
38+
schedProfileNames = sets.Set[string]{}
3939
onlyExclusiveResources = false
4040
)
4141

@@ -75,7 +75,7 @@ func RegisterSchedulerProfileName(lh logr.Logger, schedProfileName string) {
7575
lh.Info("setting up detection", "profile", schedProfileName)
7676
schedProfileNames.Insert(schedProfileName)
7777

78-
lh.V(5).Info("registered scheduler profiles", "names", schedProfileNames.List())
78+
lh.V(5).Info("registered scheduler profiles", "names", schedProfileNames.UnsortedList())
7979
}
8080

8181
func IsForeignPod(pod *corev1.Pod) bool {
@@ -95,5 +95,5 @@ func IsForeignPod(pod *corev1.Pod) bool {
9595

9696
// for testing only; NOT thread safe
9797
func CleanRegisteredSchedulerProfileNames() {
98-
schedProfileNames = sets.String{}
98+
schedProfileNames = sets.Set[string]{}
9999
}

0 commit comments

Comments
 (0)