Refactor: rename removedPlugin to invalidPlugin

Signed-off-by: kerthcet <kerthcet@gmail.com>
This commit is contained in:
kerthcet 2022-07-25 11:19:44 +08:00
parent a2229691a9
commit aa04472f54
2 changed files with 21 additions and 21 deletions

View File

@ -117,15 +117,15 @@ func splitHostIntPort(s string) (string, int, error) {
return host, portInt, err return host, portInt, err
} }
type removedPlugins struct { type invalidPlugins struct {
schemeGroupVersion string schemeGroupVersion string
plugins []string plugins []string
} }
// removedPluginsByVersion maintains a list of removed plugins in each version. // invalidPluginsByVersion maintains a list of removed/deprecated plugins in each version.
// Remember to add an entry to that list when creating a new component config // Remember to add an entry to that list when creating a new component config
// version (even if the list of removed plugins is empty). // version (even if the list of invalid plugins is empty).
var removedPluginsByVersion = []removedPlugins{ var invalidPluginsByVersion = []invalidPlugins{
{ {
schemeGroupVersion: v1beta2.SchemeGroupVersion.String(), schemeGroupVersion: v1beta2.SchemeGroupVersion.String(),
plugins: []string{}, plugins: []string{},
@ -136,10 +136,10 @@ var removedPluginsByVersion = []removedPlugins{
}, },
} }
// isPluginRemoved checks if a given plugin was removed in the given component // isPluginInvalid checks if a given plugin was removed/deprecated in the given component
// config version or earlier. // config version or earlier.
func isPluginRemoved(apiVersion string, name string) (bool, string) { func isPluginInvalid(apiVersion string, name string) (bool, string) {
for _, dp := range removedPluginsByVersion { for _, dp := range invalidPluginsByVersion {
for _, plugin := range dp.plugins { for _, plugin := range dp.plugins {
if name == plugin { if name == plugin {
return true, dp.schemeGroupVersion return true, dp.schemeGroupVersion
@ -152,11 +152,11 @@ func isPluginRemoved(apiVersion string, name string) (bool, string) {
return false, "" return false, ""
} }
func validatePluginSetForRemovedPlugins(path *field.Path, apiVersion string, ps config.PluginSet) []error { func validatePluginSetForInvalidPlugins(path *field.Path, apiVersion string, ps config.PluginSet) []error {
var errs []error var errs []error
for i, plugin := range ps.Enabled { for i, plugin := range ps.Enabled {
if removed, removedVersion := isPluginRemoved(apiVersion, plugin.Name); removed { if invalid, invalidVersion := isPluginInvalid(apiVersion, plugin.Name); invalid {
errs = append(errs, field.Invalid(path.Child("enabled").Index(i), plugin.Name, fmt.Sprintf("was removed in version %q (KubeSchedulerConfiguration is version %q)", removedVersion, apiVersion))) errs = append(errs, field.Invalid(path.Child("enabled").Index(i), plugin.Name, fmt.Sprintf("was invalid in version %q (KubeSchedulerConfiguration is version %q)", invalidVersion, apiVersion)))
} }
} }
return errs return errs
@ -200,7 +200,7 @@ func validatePluginConfig(path *field.Path, apiVersion string, profile *config.K
pluginsPath := path.Child("plugins") pluginsPath := path.Child("plugins")
for s, p := range stagesToPluginSet { for s, p := range stagesToPluginSet {
errs = append(errs, validatePluginSetForRemovedPlugins( errs = append(errs, validatePluginSetForInvalidPlugins(
pluginsPath.Child(s), apiVersion, p)...) pluginsPath.Child(s), apiVersion, p)...)
} }
} }
@ -216,8 +216,8 @@ func validatePluginConfig(path *field.Path, apiVersion string, profile *config.K
} else { } else {
seenPluginConfig.Insert(name) seenPluginConfig.Insert(name)
} }
if removed, removedVersion := isPluginRemoved(apiVersion, name); removed { if invalid, invalidVersion := isPluginInvalid(apiVersion, name); invalid {
errs = append(errs, field.Invalid(pluginConfigPath, name, fmt.Sprintf("was removed in version %q (KubeSchedulerConfiguration is version %q)", removedVersion, apiVersion))) errs = append(errs, field.Invalid(pluginConfigPath, name, fmt.Sprintf("was invalid in version %q (KubeSchedulerConfiguration is version %q)", invalidVersion, apiVersion)))
} else if validateFunc, ok := m[name]; ok { } else if validateFunc, ok := m[name]; ok {
// 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) {

View File

@ -198,8 +198,8 @@ func TestValidateKubeSchedulerConfigurationV1beta2(t *testing.T) {
BindVerb: "bar", BindVerb: "bar",
}) })
goodRemovedPlugins2 := validConfig.DeepCopy() goodInvalidPlugins := validConfig.DeepCopy()
goodRemovedPlugins2.Profiles[0].Plugins.Score.Enabled = append(goodRemovedPlugins2.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "PodTopologySpread", Weight: 2}) goodInvalidPlugins.Profiles[0].Plugins.Score.Enabled = append(goodInvalidPlugins.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "PodTopologySpread", Weight: 2})
scenarios := map[string]struct { scenarios := map[string]struct {
expectedToFail bool expectedToFail bool
@ -278,9 +278,9 @@ func TestValidateKubeSchedulerConfigurationV1beta2(t *testing.T) {
expectedToFail: true, expectedToFail: true,
config: mismatchQueueSort, config: mismatchQueueSort,
}, },
"good-removed-plugins-2": { "good-invalid-plugins": {
expectedToFail: false, expectedToFail: false,
config: goodRemovedPlugins2, config: goodInvalidPlugins,
}, },
} }
@ -472,8 +472,8 @@ func TestValidateKubeSchedulerConfigurationV1beta3(t *testing.T) {
BindVerb: "bar", BindVerb: "bar",
}) })
goodRemovedPlugins2 := validConfig.DeepCopy() goodInvalidPlugins := validConfig.DeepCopy()
goodRemovedPlugins2.Profiles[0].Plugins.Score.Enabled = append(goodRemovedPlugins2.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "PodTopologySpread", Weight: 2}) goodInvalidPlugins.Profiles[0].Plugins.Score.Enabled = append(goodInvalidPlugins.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "PodTopologySpread", Weight: 2})
scenarios := map[string]struct { scenarios := map[string]struct {
expectedToFail bool expectedToFail bool
@ -552,9 +552,9 @@ func TestValidateKubeSchedulerConfigurationV1beta3(t *testing.T) {
expectedToFail: true, expectedToFail: true,
config: mismatchQueueSort, config: mismatchQueueSort,
}, },
"good-removed-plugins-2": { "good-invalid-plugins": {
expectedToFail: false, expectedToFail: false,
config: goodRemovedPlugins2, config: goodInvalidPlugins,
}, },
} }