-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add --vm flag for users who want to autoselect only VM's #7068
Changes from all commits
e053e4f
3216a03
37b23cf
6ee7e6f
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 |
---|---|---|
|
@@ -24,6 +24,40 @@ import ( | |
"github.com/golang/glog" | ||
) | ||
|
||
const ( | ||
// Podman is Kubernetes in container using podman driver | ||
Podman = "podman" | ||
// Docker is Kubernetes in container using docker driver | ||
Docker = "docker" | ||
// Mock driver | ||
Mock = "mock" | ||
// None driver | ||
None = "none" | ||
) | ||
|
||
// IsKIC checks if the driver is a kubernetes in container | ||
func IsKIC(name string) bool { | ||
return name == Docker || name == Podman | ||
} | ||
|
||
// IsMock checks if the driver is a mock | ||
func IsMock(name string) bool { | ||
return name == Mock | ||
} | ||
|
||
// IsVM checks if the driver is a VM | ||
func IsVM(name string) bool { | ||
if IsKIC(name) || IsMock(name) || BareMetal(name) { | ||
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. I know you just copy and pasted the previous function, but because the other functions aren't used, just inline it:
|
||
return false | ||
} | ||
return true | ||
} | ||
|
||
// BareMetal returns if this driver is unisolated | ||
func BareMetal(name string) bool { | ||
return name == None || name == Mock | ||
} | ||
|
||
var ( | ||
// globalRegistry is a globally accessible driver registry | ||
globalRegistry = newRegistry() | ||
|
@@ -59,7 +93,7 @@ func Driver(name string) DriverDef { | |
} | ||
|
||
// Available returns a list of available drivers in the global registry | ||
func Available() []DriverState { | ||
func Available(vm bool) []DriverState { | ||
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. this might be clearer if it was named |
||
sts := []DriverState{} | ||
glog.Infof("Querying for installed drivers using PATH=%s", os.Getenv("PATH")) | ||
|
||
|
@@ -76,7 +110,13 @@ func Available() []DriverState { | |
priority = Unhealthy | ||
} | ||
|
||
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s}) | ||
if vm { | ||
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. With go, we try to avoid if/else statements when possible, particularly in a loop. Kind of along the lines of https://github.com/golang/go/wiki/CodeReviewComments#indent-error-flow This would be clearer:
|
||
if IsVM(d.Name) { | ||
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s}) | ||
} | ||
} else { | ||
sts = append(sts, DriverState{Name: d.Name, Priority: priority, State: s}) | ||
} | ||
} | ||
|
||
// Descending priority for predictability | ||
|
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.
rename this to
isVM
-- it does not need to be made public.