Skip to content

Commit

Permalink
Merge pull request #1129 from yanggangtony/code-clean
Browse files Browse the repository at this point in the history
Do some code cleans.
  • Loading branch information
k8s-ci-robot authored May 2, 2023
2 parents 776f196 + 71fb4a2 commit 5ba1fef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
43 changes: 16 additions & 27 deletions pkg/descheduler/policyconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func setDefaultEvictor(profile api.DeschedulerProfile, client clientset.Interfac
idx = 0
}

thresholdPriority, err := utils.GetPriorityFromStrategyParams(context.TODO(), client, defaultevictorPluginConfig.Args.(*defaultevictor.DefaultEvictorArgs).PriorityThreshold)
thresholdPriority, err := utils.GetPriorityValueFromPriorityThreshold(context.TODO(), client, defaultevictorPluginConfig.Args.(*defaultevictor.DefaultEvictorArgs).PriorityThreshold)
if err != nil {
klog.Error(err, "Failed to get threshold priority from args")
}
Expand All @@ -137,36 +137,25 @@ func validateDeschedulerConfiguration(in api.DeschedulerPolicy, registry pluginr
for _, profile := range in.Profiles {
for _, pluginConfig := range profile.PluginConfigs {
if _, ok := registry[pluginConfig.Name]; ok {
if _, ok := registry[pluginConfig.Name]; !ok {
errorsInProfiles = fmt.Errorf("%w: %s", errorsInProfiles, fmt.Sprintf("in profile %s: plugin %s in pluginConfig not registered", profile.Name, pluginConfig.Name))
continue
}

pluginUtilities := registry[pluginConfig.Name]
if pluginUtilities.PluginArgValidator != nil {
err := pluginUtilities.PluginArgValidator(pluginConfig.Args)
errorsInProfiles = setErrorsInProfiles(err, profile.Name, errorsInProfiles)
if pluginUtilities.PluginArgValidator == nil {
continue
}
err := pluginUtilities.PluginArgValidator(pluginConfig.Args)
if err != nil {
if errorsInProfiles == nil {
errorsInProfiles = fmt.Errorf("in profile %s: %s", profile.Name, err.Error())
} else {
errorsInProfiles = fmt.Errorf("%w: %s", errorsInProfiles, fmt.Sprintf("in profile %s: %s", profile.Name, err.Error()))
}
}
}
}
}
if errorsInProfiles != nil {
return errorsInProfiles
}
return nil
}

func setErrorsInProfiles(err error, profileName string, errorsInProfiles error) error {
if err != nil {
if errorsInProfiles == nil {
errorsInProfiles = fmt.Errorf("in profile %s: %s", profileName, err.Error())
} else {
errorsInProfiles = fmt.Errorf("%w: %s", errorsInProfiles, fmt.Sprintf("in profile %s: %s", profileName, err.Error()))
}
}
return errorsInProfiles
}

func hasPluginConfigsWithSameName(newPluginConfig api.PluginConfig, pluginConfigs []api.PluginConfig) bool {
for _, pluginConfig := range pluginConfigs {
if newPluginConfig.Name == pluginConfig.Name {
return true
}
}
return false
}
20 changes: 0 additions & 20 deletions pkg/utils/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,6 @@ func GetPriorityFromPriorityClass(ctx context.Context, client clientset.Interfac
return SystemCriticalPriority, nil
}

// GetPriorityFromStrategyParams gets priority from the given StrategyParameters.
// It will return SystemCriticalPriority by default.
func GetPriorityFromStrategyParams(ctx context.Context, client clientset.Interface, priorityThreshold *api.PriorityThreshold) (priority int32, err error) {
if priorityThreshold == nil {
return SystemCriticalPriority, nil
}
if priorityThreshold.Value != nil {
priority = *priorityThreshold.Value
} else {
priority, err = GetPriorityFromPriorityClass(ctx, client, priorityThreshold.Name)
if err != nil {
return
}
}
if priority > SystemCriticalPriority {
return 0, fmt.Errorf("Priority threshold can't be greater than %d", SystemCriticalPriority)
}
return
}

// GetPriorityValueFromPriorityThreshold gets priority from the given PriorityThreshold.
// It will return SystemCriticalPriority by default.
func GetPriorityValueFromPriorityThreshold(ctx context.Context, client clientset.Interface, priorityThreshold *api.PriorityThreshold) (priority int32, err error) {
Expand Down

0 comments on commit 5ba1fef

Please sign in to comment.