@@ -23,7 +23,6 @@ import (
23
23
corev1 "k8s.io/api/core/v1"
24
24
"k8s.io/apimachinery/pkg/api/resource"
25
25
26
- policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
27
26
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
28
27
)
29
28
@@ -35,9 +34,18 @@ func TestCalculateUsedWithResourceBinding(t *testing.T) {
35
34
expected corev1.ResourceList
36
35
}{
37
36
{
38
- name : "single binding, 3 replicas " ,
37
+ name : "single binding" ,
39
38
bindings : []workv1alpha2.ResourceBinding {
40
- makeBinding ("500m" , "128Mi" , int32 (3 ), policyv1alpha1 .ReplicaSchedulingTypeDivided ),
39
+ makeBinding ("500m" , "128Mi" , []workv1alpha2.TargetCluster {
40
+ {
41
+ Name : "Cluster1" ,
42
+ Replicas : int32 (1 ),
43
+ },
44
+ {
45
+ Name : "Cluster2" ,
46
+ Replicas : int32 (2 ),
47
+ },
48
+ }),
41
49
},
42
50
overall : makeResourceRequest ("2000m" , "1Gi" ),
43
51
expected : corev1.ResourceList {
@@ -46,11 +54,38 @@ func TestCalculateUsedWithResourceBinding(t *testing.T) {
46
54
},
47
55
},
48
56
{
49
- name : "multiple bindings, mixed scheduling strategies " ,
57
+ name : "multiple bindings" ,
50
58
bindings : []workv1alpha2.ResourceBinding {
51
- makeBinding ("1" , "2Gi" , 2 , policyv1alpha1 .ReplicaSchedulingTypeDivided ),
52
- makeBinding ("500m" , "500Mi" , 2 , policyv1alpha1 .ReplicaSchedulingTypeDuplicated ),
53
- makeBinding ("2" , "1Gi" , 2 , policyv1alpha1 .ReplicaSchedulingTypeDivided ),
59
+ makeBinding ("1" , "2Gi" , []workv1alpha2.TargetCluster {
60
+ {
61
+ Name : "Cluster1" ,
62
+ Replicas : int32 (1 ),
63
+ },
64
+ {
65
+ Name : "Cluster2" ,
66
+ Replicas : int32 (1 ),
67
+ },
68
+ }),
69
+ makeBinding ("500m" , "500Mi" , []workv1alpha2.TargetCluster {
70
+ {
71
+ Name : "Cluster1" ,
72
+ Replicas : int32 (2 ),
73
+ },
74
+ {
75
+ Name : "Cluster2" ,
76
+ Replicas : int32 (2 ),
77
+ },
78
+ }),
79
+ makeBinding ("2" , "1Gi" , []workv1alpha2.TargetCluster {
80
+ {
81
+ Name : "Cluster1" ,
82
+ Replicas : int32 (1 ),
83
+ },
84
+ {
85
+ Name : "Cluster2" ,
86
+ Replicas : int32 (1 ),
87
+ },
88
+ }),
54
89
},
55
90
overall : makeResourceRequest ("10" , "10Gi" ),
56
91
expected : corev1.ResourceList {
@@ -61,7 +96,16 @@ func TestCalculateUsedWithResourceBinding(t *testing.T) {
61
96
{
62
97
name : "single binding, overall only includes cpu" ,
63
98
bindings : []workv1alpha2.ResourceBinding {
64
- makeBinding ("500m" , "1Gi" , int32 (3 ), policyv1alpha1 .ReplicaSchedulingTypeDivided ),
99
+ makeBinding ("500m" , "1Gi" , []workv1alpha2.TargetCluster {
100
+ {
101
+ Name : "Cluster1" ,
102
+ Replicas : int32 (1 ),
103
+ },
104
+ {
105
+ Name : "Cluster2" ,
106
+ Replicas : int32 (2 ),
107
+ },
108
+ }),
65
109
},
66
110
overall : makeResourceRequest ("10" , "" ),
67
111
expected : corev1.ResourceList {
@@ -80,15 +124,18 @@ func TestCalculateUsedWithResourceBinding(t *testing.T) {
80
124
ReplicaRequirements : & workv1alpha2.ReplicaRequirements {
81
125
ResourceRequest : nil ,
82
126
},
83
- Replicas : 2 ,
84
- Placement : & policyv1alpha1.Placement {
85
- ReplicaScheduling : & policyv1alpha1.ReplicaSchedulingStrategy {
86
- ReplicaSchedulingType : policyv1alpha1 .ReplicaSchedulingTypeDuplicated ,
87
- },
88
- },
89
127
},
90
128
},
91
- makeBinding ("200m" , "128Mi" , 2 , policyv1alpha1 .ReplicaSchedulingTypeDivided ),
129
+ makeBinding ("200m" , "128Mi" , []workv1alpha2.TargetCluster {
130
+ {
131
+ Name : "Cluster1" ,
132
+ Replicas : int32 (1 ),
133
+ },
134
+ {
135
+ Name : "Cluster2" ,
136
+ Replicas : int32 (1 ),
137
+ },
138
+ }),
92
139
},
93
140
overall : makeResourceRequest ("10" , "10Gi" ),
94
141
expected : corev1.ResourceList {
@@ -118,23 +165,13 @@ func TestCalculateUsedWithResourceBinding(t *testing.T) {
118
165
}
119
166
}
120
167
121
- func makeBinding (cpu string , memory string , replicas int32 , strategy policyv1alpha1.ReplicaSchedulingType ) workv1alpha2.ResourceBinding {
122
- schedulingStrategy := & policyv1alpha1.ReplicaSchedulingStrategy {
123
- ReplicaSchedulingType : strategy ,
124
- }
168
+ func makeBinding (cpu string , memory string , clusters []workv1alpha2.TargetCluster ) workv1alpha2.ResourceBinding {
125
169
return workv1alpha2.ResourceBinding {
126
170
Spec : workv1alpha2.ResourceBindingSpec {
127
- Clusters : []workv1alpha2.TargetCluster {
128
- {Name : "cluster1" },
129
- {Name : "cluster2" },
130
- },
171
+ Clusters : clusters ,
131
172
ReplicaRequirements : & workv1alpha2.ReplicaRequirements {
132
173
ResourceRequest : makeResourceRequest (cpu , memory ),
133
174
},
134
- Replicas : replicas ,
135
- Placement : & policyv1alpha1.Placement {
136
- ReplicaScheduling : schedulingStrategy ,
137
- },
138
175
},
139
176
}
140
177
}
0 commit comments