Fix validation of container-runtime config
It was trying to load (non-existing) config, and also confusingly looking for containerd. Add a unit test as well.pull/5964/head
parent
b96bb0e4f1
commit
3451320ad2
|
@ -51,7 +51,7 @@ var settings = []Setting{
|
||||||
{
|
{
|
||||||
name: "container-runtime",
|
name: "container-runtime",
|
||||||
set: SetString,
|
set: SetString,
|
||||||
validations: []setFn{IsContainerdRuntime},
|
validations: []setFn{IsValidRuntime},
|
||||||
callbacks: []setFn{RequiresRestartMsg},
|
callbacks: []setFn{RequiresRestartMsg},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -147,6 +147,15 @@ func IsValidAddon(name string, val string) error {
|
||||||
return errors.Errorf("Cannot enable/disable invalid addon %s", name)
|
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
|
// IsContainerdRuntime is a validator which returns an error if the current runtime is not containerd
|
||||||
func IsContainerdRuntime(_, _ string) error {
|
func IsContainerdRuntime(_, _ string) error {
|
||||||
config, err := config.Load()
|
config, err := config.Load()
|
||||||
|
|
|
@ -98,6 +98,33 @@ func TestValidCIDR(t *testing.T) {
|
||||||
runValidations(t, tests, "cidr", IsValidCIDR)
|
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) {
|
func TestIsURLExists(t *testing.T) {
|
||||||
|
|
||||||
self, err := os.Executable()
|
self, err := os.Executable()
|
||||||
|
|
Loading…
Reference in New Issue