mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Don't return in api validation
This commit is contained in:
parent
5ea9460234
commit
823a0f101a
@ -227,8 +227,6 @@ func validatePluginConfig(path *field.Path, apiVersion string, profile *config.K
|
|||||||
|
|
||||||
seenPluginConfig := make(sets.String)
|
seenPluginConfig := make(sets.String)
|
||||||
|
|
||||||
// validate plugin config at the end because we will return the aggregated errors early if type of args doesn't match.
|
|
||||||
// validate plugin config at the end will will help to collect as much as misconfiguration as possible.
|
|
||||||
for i := range profile.PluginConfig {
|
for i := range profile.PluginConfig {
|
||||||
pluginConfigPath := path.Child("pluginConfig").Index(i)
|
pluginConfigPath := path.Child("pluginConfig").Index(i)
|
||||||
name := profile.PluginConfig[i].Name
|
name := profile.PluginConfig[i].Name
|
||||||
@ -244,8 +242,7 @@ func validatePluginConfig(path *field.Path, apiVersion string, profile *config.K
|
|||||||
// type mismatch, no need to validate the `args`.
|
// type mismatch, no need to validate the `args`.
|
||||||
if reflect.TypeOf(args) != reflect.ValueOf(validateFunc).Type().In(1) {
|
if reflect.TypeOf(args) != reflect.ValueOf(validateFunc).Type().In(1) {
|
||||||
errs = append(errs, field.Invalid(pluginConfigPath.Child("args"), args, "has to match plugin args"))
|
errs = append(errs, field.Invalid(pluginConfigPath.Child("args"), args, "has to match plugin args"))
|
||||||
return errs
|
} else {
|
||||||
}
|
|
||||||
in := []reflect.Value{reflect.ValueOf(pluginConfigPath.Child("args")), reflect.ValueOf(args)}
|
in := []reflect.Value{reflect.ValueOf(pluginConfigPath.Child("args")), reflect.ValueOf(args)}
|
||||||
res := reflect.ValueOf(validateFunc).Call(in)
|
res := reflect.ValueOf(validateFunc).Call(in)
|
||||||
// It's possible that validation function return a Aggregate, just append here and it will be flattened at the end of CC validation.
|
// It's possible that validation function return a Aggregate, just append here and it will be flattened at the end of CC validation.
|
||||||
@ -254,6 +251,7 @@ func validatePluginConfig(path *field.Path, apiVersion string, profile *config.K
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,8 +254,8 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
|
|||||||
goodConflictPlugins2.Profiles[0].Plugins.Score.Enabled = append(goodConflictPlugins2.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "NodeResourcesMostAllocated", Weight: 2})
|
goodConflictPlugins2.Profiles[0].Plugins.Score.Enabled = append(goodConflictPlugins2.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "NodeResourcesMostAllocated", Weight: 2})
|
||||||
goodConflictPlugins2.Profiles[0].Plugins.Score.Enabled = append(goodConflictPlugins2.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "RequestedToCapacityRatio", Weight: 2})
|
goodConflictPlugins2.Profiles[0].Plugins.Score.Enabled = append(goodConflictPlugins2.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "RequestedToCapacityRatio", Weight: 2})
|
||||||
|
|
||||||
badPluginsConfig := validConfig.DeepCopy()
|
deprecatedPluginsConfig := validConfig.DeepCopy()
|
||||||
badPluginsConfig.Profiles[0].PluginConfig = append(badPluginsConfig.Profiles[0].PluginConfig, config.PluginConfig{
|
deprecatedPluginsConfig.Profiles[0].PluginConfig = append(deprecatedPluginsConfig.Profiles[0].PluginConfig, config.PluginConfig{
|
||||||
Name: "NodeResourcesLeastAllocated",
|
Name: "NodeResourcesLeastAllocated",
|
||||||
Args: &config.NodeResourcesLeastAllocatedArgs{},
|
Args: &config.NodeResourcesLeastAllocatedArgs{},
|
||||||
})
|
})
|
||||||
@ -392,7 +392,7 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"bad-plugins-config": {
|
"bad-plugins-config": {
|
||||||
expectedToFail: true,
|
expectedToFail: true,
|
||||||
config: badPluginsConfig,
|
config: deprecatedPluginsConfig,
|
||||||
errorString: "profiles[0].pluginConfig[1]: Invalid value: \"NodeResourcesLeastAllocated\": was removed in version \"kubescheduler.config.k8s.io/v1beta2\" (KubeSchedulerConfiguration is version \"kubescheduler.config.k8s.io/v1beta2\")",
|
errorString: "profiles[0].pluginConfig[1]: Invalid value: \"NodeResourcesLeastAllocated\": was removed in version \"kubescheduler.config.k8s.io/v1beta2\" (KubeSchedulerConfiguration is version \"kubescheduler.config.k8s.io/v1beta2\")",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user