Skip to content
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

Fix validation of container-runtime config #5964

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var settings = []Setting{
{
name: "container-runtime",
set: SetString,
validations: []setFn{IsContainerdRuntime},
validations: []setFn{IsValidRuntime},
callbacks: []setFn{RequiresRestartMsg},
},
{
Expand Down
9 changes: 9 additions & 0 deletions cmd/minikube/cmd/config/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func IsValidAddon(name string, val string) error {
return errors.Errorf("Cannot enable/disable invalid addon %s", name)
}

// IsValidRuntime checks if a string is a valid runtime
func IsValidRuntime(name string, runtime string) error {
_, err := cruntime.New(cruntime.Config{Type: runtime})
if err != nil {
return fmt.Errorf("invalid runtime: %v", err)
}
return nil
}

// IsContainerdRuntime is a validator which returns an error if the current runtime is not containerd
func IsContainerdRuntime(_, _ string) error {
config, err := config.Load()
Expand Down
27 changes: 27 additions & 0 deletions cmd/minikube/cmd/config/validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ func TestValidCIDR(t *testing.T) {
runValidations(t, tests, "cidr", IsValidCIDR)
}

func TestValidRuntime(t *testing.T) {
var tests = []validationTest{
{
value: "", // default
shouldErr: false,
},
{
value: "invalid",
shouldErr: true,
},
{
value: "containerd",
shouldErr: false,
},
{
value: "crio",
shouldErr: false,
},
{
value: "docker",
shouldErr: false,
},
}

runValidations(t, tests, "container-runtime", IsValidRuntime)
}

func TestIsURLExists(t *testing.T) {

self, err := os.Executable()
Expand Down