Skip to content

Commit de1dcae

Browse files
authored
Merge pull request #1158 from a7i/fix-plugin-arg-copy-release-1.27
fix plugin arg conversion when using multiple profiles with same plugin
2 parents 4cae47f + c6c2e2d commit de1dcae

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

pkg/api/v1alpha2/conversion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func convertToInternalPluginConfigArgs(out *api.DeschedulerPolicy) error {
8888
func Convert_v1alpha2_PluginConfig_To_api_PluginConfig(in *PluginConfig, out *api.PluginConfig, s conversion.Scope) error {
8989
out.Name = in.Name
9090
if _, ok := pluginregistry.PluginRegistry[in.Name]; ok {
91-
out.Args = pluginregistry.PluginRegistry[in.Name].PluginArgInstance
91+
out.Args = pluginregistry.PluginRegistry[in.Name].PluginArgInstance.DeepCopyObject()
9292
if in.Args.Raw != nil {
9393
_, _, err := Codecs.UniversalDecoder().Decode(in.Args.Raw, nil, out.Args)
9494
if err != nil {

pkg/descheduler/policyconfig.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222
"os"
2323

24+
utilerrors "k8s.io/apimachinery/pkg/util/errors"
25+
2426
"k8s.io/apimachinery/pkg/runtime"
2527
clientset "k8s.io/client-go/kubernetes"
2628
"k8s.io/klog/v2"
@@ -133,29 +135,22 @@ func setDefaultEvictor(profile api.DeschedulerProfile, client clientset.Interfac
133135
}
134136

135137
func validateDeschedulerConfiguration(in api.DeschedulerPolicy, registry pluginregistry.Registry) error {
136-
var errorsInProfiles error
138+
var errorsInProfiles []error
137139
for _, profile := range in.Profiles {
138140
for _, pluginConfig := range profile.PluginConfigs {
139-
if _, ok := registry[pluginConfig.Name]; ok {
140-
if _, ok := registry[pluginConfig.Name]; !ok {
141-
errorsInProfiles = fmt.Errorf("%w: %s", errorsInProfiles, fmt.Sprintf("in profile %s: plugin %s in pluginConfig not registered", profile.Name, pluginConfig.Name))
142-
continue
143-
}
144-
145-
pluginUtilities := registry[pluginConfig.Name]
146-
if pluginUtilities.PluginArgValidator == nil {
147-
continue
148-
}
149-
err := pluginUtilities.PluginArgValidator(pluginConfig.Args)
150-
if err != nil {
151-
if errorsInProfiles == nil {
152-
errorsInProfiles = fmt.Errorf("in profile %s: %s", profile.Name, err.Error())
153-
} else {
154-
errorsInProfiles = fmt.Errorf("%w: %s", errorsInProfiles, fmt.Sprintf("in profile %s: %s", profile.Name, err.Error()))
155-
}
156-
}
141+
if _, ok := registry[pluginConfig.Name]; !ok {
142+
errorsInProfiles = append(errorsInProfiles, fmt.Errorf("in profile %s: plugin %s in pluginConfig not registered", profile.Name, pluginConfig.Name))
143+
continue
144+
}
145+
146+
pluginUtilities := registry[pluginConfig.Name]
147+
if pluginUtilities.PluginArgValidator == nil {
148+
continue
149+
}
150+
if err := pluginUtilities.PluginArgValidator(pluginConfig.Args); err != nil {
151+
errorsInProfiles = append(errorsInProfiles, fmt.Errorf("in profile %s: %s", profile.Name, err.Error()))
157152
}
158153
}
159154
}
160-
return errorsInProfiles
155+
return utilerrors.NewAggregate(errorsInProfiles)
161156
}

pkg/descheduler/policyconfig_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ func TestValidateDeschedulerConfiguration(t *testing.T) {
985985
},
986986
},
987987
},
988-
result: fmt.Errorf("in profile RemoveFailedPods: only one of Include/Exclude namespaces can be set: in profile RemovePodsViolatingTopologySpreadConstraint: only one of Include/Exclude namespaces can be set"),
988+
result: fmt.Errorf("[in profile RemoveFailedPods: only one of Include/Exclude namespaces can be set, in profile RemovePodsViolatingTopologySpreadConstraint: only one of Include/Exclude namespaces can be set]"),
989989
},
990990
}
991991

0 commit comments

Comments
 (0)