-
Notifications
You must be signed in to change notification settings - Fork 1k
remark the workload for resourcebinding #6881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
bea8285
a9ec2e2
1acbc39
45bda3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -441,3 +441,34 @@ func TestResourceBindingSpec_SchedulingSuspended(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestResourceBindingSpec_IsBindingWorkload(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| spec *ResourceBindingSpec | ||
| want bool | ||
| }{ | ||
| { | ||
| name: "binding a workload", | ||
| spec: &ResourceBindingSpec{ | ||
| Replicas: 1, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "not binding a workload when replicas is 0", | ||
| spec: &ResourceBindingSpec{ | ||
| Replicas: 0, | ||
| }, | ||
| want: false, | ||
| }, | ||
|
Comment on lines
453
to
466
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test cases for {
name: "binding a workload by replicas",
spec: &ResourceBindingSpec{
Replicas: 1,
},
want: true,
},
{
name: "binding a workload by replica requirements",
spec: &ResourceBindingSpec{
ReplicaRequirements: &ReplicaRequirements{},
},
want: true,
},
{
name: "binding a workload by components",
spec: &ResourceBindingSpec{
Components: []Component{{Name: "test"}},
},
want: true,
},
{
name: "not a workload",
spec: &ResourceBindingSpec{
Replicas: 0,
},
want: false,
},
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| ret := tt.spec.IsBindingWorkload() | ||
| if ret != tt.want { | ||
| t.Fatalf("test case %s failed, want %v, got %v", tt.name, tt.want, ret) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -66,9 +66,12 @@ func AssignReplicas( | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // If not workload, assign all clusters without considering replicas. | ||||||||||||||||||||||||
| targetClusters := make([]workv1alpha2.TargetCluster, len(clusters)) | ||||||||||||||||||||||||
| for i, cluster := range clusters { | ||||||||||||||||||||||||
| targetClusters[i] = workv1alpha2.TargetCluster{Name: cluster.Cluster.Name} | ||||||||||||||||||||||||
| var targetClusters []workv1alpha2.TargetCluster | ||||||||||||||||||||||||
| if !spec.IsBindingWorkload() { | ||||||||||||||||||||||||
| for _, cluster := range clusters { | ||||||||||||||||||||||||
| targetClusters = append(targetClusters, workv1alpha2.TargetCluster{Name: cluster.Cluster.Name}) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| if !spec.IsBindingWorkload() { | |
| for _, cluster := range clusters { | |
| targetClusters = append(targetClusters, workv1alpha2.TargetCluster{Name: cluster.Cluster.Name}) | |
| } | |
| } | |
| if !spec.IsBindingWorkload() { | |
| targetClusters = make([]workv1alpha2.TargetCluster, len(clusters)) | |
| for i, cluster := range clusters { | |
| targetClusters[i] = workv1alpha2.TargetCluster{Name: cluster.Cluster.Name} | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability and conciseness, you can directly return the result of the boolean expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I‘m ok with the current implementation, which I think is clear and easy to understand.
But I'm suggesting changing the method name, since
Bindingis a bit redundant. Like: