Skip to content

Commit c462862

Browse files
authored
Merge pull request #5964 from afbjorklund/config-runtime
Fix validation of container-runtime config
2 parents 8a4c7d3 + 3451320 commit c462862

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

cmd/minikube/cmd/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var settings = []Setting{
5151
{
5252
name: "container-runtime",
5353
set: SetString,
54-
validations: []setFn{IsContainerdRuntime},
54+
validations: []setFn{IsValidRuntime},
5555
callbacks: []setFn{RequiresRestartMsg},
5656
},
5757
{

cmd/minikube/cmd/config/validations.go

+9
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ func IsValidAddon(name string, val string) error {
147147
return errors.Errorf("Cannot enable/disable invalid addon %s", name)
148148
}
149149

150+
// IsValidRuntime checks if a string is a valid runtime
151+
func IsValidRuntime(name string, runtime string) error {
152+
_, err := cruntime.New(cruntime.Config{Type: runtime})
153+
if err != nil {
154+
return fmt.Errorf("invalid runtime: %v", err)
155+
}
156+
return nil
157+
}
158+
150159
// IsContainerdRuntime is a validator which returns an error if the current runtime is not containerd
151160
func IsContainerdRuntime(_, _ string) error {
152161
config, err := config.Load()

cmd/minikube/cmd/config/validations_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@ func TestValidCIDR(t *testing.T) {
9898
runValidations(t, tests, "cidr", IsValidCIDR)
9999
}
100100

101+
func TestValidRuntime(t *testing.T) {
102+
var tests = []validationTest{
103+
{
104+
value: "", // default
105+
shouldErr: false,
106+
},
107+
{
108+
value: "invalid",
109+
shouldErr: true,
110+
},
111+
{
112+
value: "containerd",
113+
shouldErr: false,
114+
},
115+
{
116+
value: "crio",
117+
shouldErr: false,
118+
},
119+
{
120+
value: "docker",
121+
shouldErr: false,
122+
},
123+
}
124+
125+
runValidations(t, tests, "container-runtime", IsValidRuntime)
126+
}
127+
101128
func TestIsURLExists(t *testing.T) {
102129

103130
self, err := os.Executable()

0 commit comments

Comments
 (0)