-
Notifications
You must be signed in to change notification settings - Fork 500
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
Serial scheduling #266
Serial scheduling #266
Conversation
/run-e2e-tests |
2 similar comments
/run-e2e-tests |
/run-e2e-tests |
pkg/scheduler/predicates/ha.go
Outdated
var schedulingPVC *apiv1.PersistentVolumeClaim | ||
for i := 0; i < len(pvcList.Items); i++ { | ||
pvc := pvcList.Items[i] | ||
if pvc.GetName() == currentPVCName && currentPVC == nil { |
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.
Why do you want to add the condition currentPVC == nil
, will there be multiple PVCs with the same 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.
Removed.
pkg/scheduler/predicates/ha.go
Outdated
currentPVCName := pvcName(component, podName) | ||
var currentPVC *apiv1.PersistentVolumeClaim | ||
var schedulingPVC *apiv1.PersistentVolumeClaim | ||
for i := 0; i < len(pvcList.Items); i++ { |
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 i := 0; i < len(pvcList.Items); i++ { | |
for _, pvc := range pvcList.Items { |
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.
Use this style to avoid the golang common mistakes
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.
There is not use closures running as goroutines,If there is such a scene, then the way to use range can also avoid this problem.
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.
currentPVC
and schedulingPVC
are pointers, the pvc
in the for range block is a variable, if we use the for range style, then these two variables will get the same address.
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 example:
package main
import "fmt"
func main() {
arr := []string{"a", "b", "c"}
var pa *string
var pb *string
for _, item := range arr {
if item == "a" {
pa = &item
}
if item == "b" {
pb = &item
}
}
fmt.Println(pa)
fmt.Println(pb)
fmt.Println(pa == pb)
var ppa *string
var ppb *string
for i := 0; i < len(arr); i++ {
if arr[i] == "a" {
ppa = &arr[i]
}
if arr[i] == "b" {
ppb = &arr[i]
}
}
fmt.Println(ppa)
fmt.Println(ppb)
fmt.Println(ppa == ppb)
}
Outputs:
0xc00005e1c0
0xc00005e1c0
true
0xc000060180
0xc000060190
false
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.
You can create a new variable to fix this problem. such as follow:
for i := 0; i < len(pvcList.Items); i++ {
pvc := pvcList.Items[i]
...
}
------
for _, pvc := range pvcList.Items {
pvc := pvc
...
}
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.
Style for i:=0; i<n; i++
is equivalent to the for range
style, but using for i:=0; i<n; i++
is more clear at this situation.
pvc := pvc
looks weird.
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.
LGTM
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.
LGTM
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.
LGTM
/run-e2e-tests |
91a2c4a
/run-e2e-tests |
This pr fixes: #264, make sure only one pod can be scheduled at the same time.