Use RawExtension and Object for external and internal scheduling plugin args, respectively

Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
Aldo Culquicondor 2020-04-08 13:47:52 -04:00
parent ec00b4fcc2
commit ce05382b58
45 changed files with 148 additions and 111 deletions

View File

@ -204,6 +204,8 @@ profiles:
- name: baz
pluginConfig:
- name: foo
args:
bar: baz
`, configKubeconfig)), os.FileMode(0600)); err != nil {
t.Fatal(err)
}
@ -543,7 +545,10 @@ profiles:
PluginConfig: []kubeschedulerconfig.PluginConfig{
{
Name: "foo",
Args: runtime.Unknown{},
Args: &runtime.Unknown{
Raw: []byte(`{"bar":"baz"}`),
ContentType: "application/json",
},
},
},
},
@ -608,7 +613,6 @@ profiles:
PluginConfig: []kubeschedulerconfig.PluginConfig{
{
Name: "foo",
Args: runtime.Unknown{},
},
},
},
@ -666,7 +670,7 @@ profiles:
PluginConfig: []kubeschedulerconfig.PluginConfig{
{
Name: "InterPodAffinity",
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{"hardPodAffinityWeight":5}`),
},
},
@ -760,7 +764,7 @@ profiles:
}
if diff := cmp.Diff(tc.expectedConfig, config.ComponentConfig); diff != "" {
t.Errorf("incorrect config (-want, +got):\n%s", diff)
t.Errorf("incorrect config (-want,+got):\n%s", diff)
}
// ensure we have a client

View File

@ -1598,7 +1598,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
pluginConfig: []config.PluginConfig{
{
Name: "NodeResourcesFit",
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{
"ignoredResources": [
"foo",
@ -1609,7 +1609,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
},
{
Name: "PodTopologySpread",
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{
"defaultConstraints": [
{
@ -1628,7 +1628,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
},
{
Name: "RequestedToCapacityRatio",
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{
"shape":[
"Utilization": 5,
@ -1643,7 +1643,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
},
{
Name: "InterPodAffinity",
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{
"HardPodAffinityWeight": 100
}`),
@ -1651,7 +1651,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
},
{
Name: "NodeLabel",
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{
"presentLabels": [
"foo",
@ -1671,7 +1671,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) {
},
{
Name: "ServiceAffinity",
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{
affinityLabels: [
"foo",

View File

@ -237,7 +237,7 @@ type PluginConfig struct {
// Name defines the name of plugin being configured
Name string
// Args defines the arguments passed to the plugins at the time of initialization. Args can have arbitrary structure.
Args runtime.Unknown
Args runtime.Object
}
/*

View File

@ -336,7 +336,17 @@ func autoConvert_v1alpha2_KubeSchedulerProfile_To_config_KubeSchedulerProfile(in
} else {
out.Plugins = nil
}
out.PluginConfig = *(*[]config.PluginConfig)(unsafe.Pointer(&in.PluginConfig))
if in.PluginConfig != nil {
in, out := &in.PluginConfig, &out.PluginConfig
*out = make([]config.PluginConfig, len(*in))
for i := range *in {
if err := Convert_v1alpha2_PluginConfig_To_config_PluginConfig(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.PluginConfig = nil
}
return nil
}
@ -358,7 +368,17 @@ func autoConvert_config_KubeSchedulerProfile_To_v1alpha2_KubeSchedulerProfile(in
} else {
out.Plugins = nil
}
out.PluginConfig = *(*[]v1alpha2.PluginConfig)(unsafe.Pointer(&in.PluginConfig))
if in.PluginConfig != nil {
in, out := &in.PluginConfig, &out.PluginConfig
*out = make([]v1alpha2.PluginConfig, len(*in))
for i := range *in {
if err := Convert_config_PluginConfig_To_v1alpha2_PluginConfig(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.PluginConfig = nil
}
return nil
}
@ -441,7 +461,9 @@ func Convert_config_Plugin_To_v1alpha2_Plugin(in *config.Plugin, out *v1alpha2.P
func autoConvert_v1alpha2_PluginConfig_To_config_PluginConfig(in *v1alpha2.PluginConfig, out *config.PluginConfig, s conversion.Scope) error {
out.Name = in.Name
out.Args = in.Args
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Args, &out.Args, s); err != nil {
return err
}
return nil
}
@ -452,7 +474,9 @@ func Convert_v1alpha2_PluginConfig_To_config_PluginConfig(in *v1alpha2.PluginCon
func autoConvert_config_PluginConfig_To_v1alpha2_PluginConfig(in *config.PluginConfig, out *v1alpha2.PluginConfig, s conversion.Scope) error {
out.Name = in.Name
out.Args = in.Args
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Args, &out.Args, s); err != nil {
return err
}
return nil
}

View File

@ -341,7 +341,9 @@ func (in *Plugin) DeepCopy() *Plugin {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PluginConfig) DeepCopyInto(out *PluginConfig) {
*out = *in
in.Args.DeepCopyInto(&out.Args)
if in.Args != nil {
out.Args = in.Args.DeepCopyObject()
}
return
}

View File

@ -110,7 +110,7 @@ func machine2PrioritizerExtender(pod *v1.Pod, nodes []*v1.Node) (*framework.Node
type machine2PrioritizerPlugin struct{}
func newMachine2PrioritizerPlugin() framework.PluginFactory {
return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &machine2PrioritizerPlugin{}, nil
}
}

View File

@ -81,7 +81,7 @@ func (pl *trueFilterPlugin) Filter(_ context.Context, _ *framework.CycleState, p
}
// NewTrueFilterPlugin initializes a trueFilterPlugin and returns it.
func NewTrueFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func NewTrueFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &trueFilterPlugin{}, nil
}
@ -98,7 +98,7 @@ func (pl *falseFilterPlugin) Filter(_ context.Context, _ *framework.CycleState,
}
// NewFalseFilterPlugin initializes a falseFilterPlugin and returns it.
func NewFalseFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func NewFalseFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &falseFilterPlugin{}, nil
}
@ -122,7 +122,7 @@ func (pl *matchFilterPlugin) Filter(_ context.Context, _ *framework.CycleState,
}
// NewMatchFilterPlugin initializes a matchFilterPlugin and returns it.
func NewMatchFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func NewMatchFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &matchFilterPlugin{}, nil
}
@ -142,7 +142,7 @@ func (pl *noPodsFilterPlugin) Filter(_ context.Context, _ *framework.CycleState,
}
// NewNoPodsFilterPlugin initializes a noPodsFilterPlugin and returns it.
func NewNoPodsFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func NewNoPodsFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &noPodsFilterPlugin{}, nil
}
@ -171,7 +171,7 @@ func (pl *fakeFilterPlugin) Filter(_ context.Context, _ *framework.CycleState, p
// NewFakeFilterPlugin initializes a fakeFilterPlugin and returns it.
func NewFakeFilterPlugin(failedNodeReturnCodeMap map[string]framework.Code) framework.PluginFactory {
return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &fakeFilterPlugin{
failedNodeReturnCodeMap: failedNodeReturnCodeMap,
}, nil
@ -181,7 +181,7 @@ func NewFakeFilterPlugin(failedNodeReturnCodeMap map[string]framework.Code) fram
type numericMapPlugin struct{}
func newNumericMapPlugin() framework.PluginFactory {
return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &numericMapPlugin{}, nil
}
}
@ -205,7 +205,7 @@ func (pl *numericMapPlugin) ScoreExtensions() framework.ScoreExtensions {
type reverseNumericMapPlugin struct{}
func newReverseNumericMapPlugin() framework.PluginFactory {
return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &reverseNumericMapPlugin{}, nil
}
}
@ -246,7 +246,7 @@ func (pl *reverseNumericMapPlugin) NormalizeScore(_ context.Context, _ *framewor
type trueMapPlugin struct{}
func newTrueMapPlugin() framework.PluginFactory {
return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &trueMapPlugin{}, nil
}
}
@ -275,7 +275,7 @@ func (pl *trueMapPlugin) NormalizeScore(_ context.Context, _ *framework.CycleSta
type falseMapPlugin struct{}
func newFalseMapPlugin() framework.PluginFactory {
return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &falseMapPlugin{}, nil
}
}
@ -962,7 +962,7 @@ func TestFindFitPredicateCallCounts(t *testing.T) {
plugin := fakeFilterPlugin{}
registerFakeFilterFunc := st.RegisterFilterPlugin(
"FakeFilter",
func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
return &plugin, nil
},
)
@ -1598,7 +1598,7 @@ func TestSelectNodesForPreemption(t *testing.T) {
fakePlugin.failedNodeReturnCodeMap = filterFailedNodeReturnCodeMap
registerFakeFilterFunc := st.RegisterFilterPlugin(
"FakeFilter",
func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
return &fakePlugin, nil
},
)

View File

@ -342,7 +342,7 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler,
// mergePluginConfigsFromPolicy merges the giving plugin configs ensuring that,
// if a plugin name is repeated, the arguments are the same.
func mergePluginConfigsFromPolicy(pc1, pc2 []schedulerapi.PluginConfig) ([]schedulerapi.PluginConfig, error) {
args := make(map[string]runtime.Unknown)
args := make(map[string]runtime.Object)
for _, c := range pc1 {
args[c.Name] = c.Args
}

View File

@ -251,7 +251,7 @@ func TestCreateFromConfigWithHardPodAffinitySymmetricWeight(t *testing.T) {
for _, cfg := range factory.profiles[0].PluginConfig {
if cfg.Name == interpodaffinity.Name {
foundAffinityCfg = true
wantArgs := runtime.Unknown{Raw: []byte(`{"hardPodAffinityWeight":10}`)}
wantArgs := &runtime.Unknown{Raw: []byte(`{"hardPodAffinityWeight":10}`)}
if diff := cmp.Diff(wantArgs, cfg.Args); diff != "" {
t.Errorf("wrong InterPodAffinity args (-want, +got): %s", diff)

View File

@ -37,7 +37,7 @@ type DefaultBinder struct {
var _ framework.BindPlugin = &DefaultBinder{}
// New creates a DefaultBinder.
func New(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
return &DefaultBinder{handle: handle}, nil
}

View File

@ -188,7 +188,7 @@ func (pl *DefaultPodTopologySpread) PreScore(ctx context.Context, cycleState *fr
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
return &DefaultPodTopologySpread{
handle: handle,
}, nil

View File

@ -74,7 +74,7 @@ func (pl *ImageLocality) ScoreExtensions() framework.ScoreExtensions {
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
return &ImageLocality{handle: h}, nil
}

View File

@ -62,7 +62,7 @@ func (pl *InterPodAffinity) BuildArgs() interface{} {
}
// New initializes a new plugin and returns it.
func New(plArgs *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func New(plArgs runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
if h.SnapshotSharedLister() == nil {
return nil, fmt.Errorf("SnapshotSharedlister is nil")
}

View File

@ -496,7 +496,7 @@ func NewPluginConfig(pluginName string, args interface{}) config.PluginConfig {
}
return config.PluginConfig{
Name: pluginName,
Args: runtime.Unknown{Raw: encoding},
Args: &runtime.Unknown{Raw: encoding},
}
}

View File

@ -113,6 +113,6 @@ func (pl *NodeAffinity) ScoreExtensions() framework.ScoreExtensions {
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
return &NodeAffinity{handle: h}, nil
}

View File

@ -50,7 +50,7 @@ func validateNoConflict(presentLabels []string, absentLabels []string) error {
}
// New initializes a new plugin and returns it.
func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func New(plArgs runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
args := schedulerv1alpha2.NodeLabelArgs{}
if err := framework.DecodeInto(plArgs, &args); err != nil {
return nil, err

View File

@ -59,6 +59,6 @@ func Fits(pod *v1.Pod, nodeInfo *framework.NodeInfo) bool {
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &NodeName{}, nil
}

View File

@ -128,6 +128,6 @@ func fitsPorts(wantPorts []*v1.ContainerPort, nodeInfo *framework.NodeInfo) bool
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &NodePorts{}, nil
}

View File

@ -87,6 +87,6 @@ func (pl *NodePreferAvoidPods) ScoreExtensions() framework.ScoreExtensions {
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
return &NodePreferAvoidPods{handle: h}, nil
}

View File

@ -68,7 +68,7 @@ func (ba *BalancedAllocation) ScoreExtensions() framework.ScoreExtensions {
}
// NewBalancedAllocation initializes a new plugin and returns it.
func NewBalancedAllocation(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func NewBalancedAllocation(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
return &BalancedAllocation{
handle: h,
resourceAllocationScorer: resourceAllocationScorer{

View File

@ -63,7 +63,7 @@ func (f *Fit) Name() string {
}
// NewFit initializes a new plugin and returns it.
func NewFit(plArgs *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func NewFit(plArgs runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
args := &schedulerv1alpha2.NodeResourcesFitArgs{}
if err := framework.DecodeInto(plArgs, args); err != nil {
return nil, err

View File

@ -63,7 +63,7 @@ func (la *LeastAllocated) ScoreExtensions() framework.ScoreExtensions {
}
// NewLeastAllocated initializes a new plugin and returns it.
func NewLeastAllocated(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func NewLeastAllocated(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
return &LeastAllocated{
handle: h,
resourceAllocationScorer: resourceAllocationScorer{

View File

@ -61,7 +61,7 @@ func (ma *MostAllocated) ScoreExtensions() framework.ScoreExtensions {
}
// NewMostAllocated initializes a new plugin and returns it.
func NewMostAllocated(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func NewMostAllocated(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
return &MostAllocated{
handle: h,
resourceAllocationScorer: resourceAllocationScorer{

View File

@ -48,7 +48,7 @@ type functionShapePoint struct {
}
// NewRequestedToCapacityRatio initializes a new plugin and returns it.
func NewRequestedToCapacityRatio(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func NewRequestedToCapacityRatio(plArgs runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{}
if err := framework.DecodeInto(plArgs, args); err != nil {
return nil, err

View File

@ -128,7 +128,7 @@ func (rl *ResourceLimits) ScoreExtensions() framework.ScoreExtensions {
}
// NewResourceLimits initializes a new plugin and returns it.
func NewResourceLimits(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func NewResourceLimits(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
return &ResourceLimits{handle: h}, nil
}

View File

@ -65,6 +65,6 @@ func (pl *NodeUnschedulable) Filter(ctx context.Context, _ *framework.CycleState
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &NodeUnschedulable{}, nil
}

View File

@ -268,7 +268,7 @@ func (pl *CSILimits) getCSIDriverInfoFromSC(csiNode *storagev1.CSINode, pvc *v1.
}
// NewCSI initializes a new plugin and returns it.
func NewCSI(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func NewCSI(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
informerFactory := handle.SharedInformerFactory()
pvLister := informerFactory.Core().V1().PersistentVolumes().Lister()
pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister()

View File

@ -68,7 +68,7 @@ const (
const AzureDiskName = "AzureDiskLimits"
// NewAzureDisk returns function that initializes a new plugin and returns it.
func NewAzureDisk(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func NewAzureDisk(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
informerFactory := handle.SharedInformerFactory()
return newNonCSILimitsWithInformerFactory(azureDiskVolumeFilterType, informerFactory), nil
}
@ -77,7 +77,7 @@ func NewAzureDisk(_ *runtime.Unknown, handle framework.FrameworkHandle) (framewo
const CinderName = "CinderLimits"
// NewCinder returns function that initializes a new plugin and returns it.
func NewCinder(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func NewCinder(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
informerFactory := handle.SharedInformerFactory()
return newNonCSILimitsWithInformerFactory(cinderVolumeFilterType, informerFactory), nil
}
@ -86,7 +86,7 @@ func NewCinder(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.
const EBSName = "EBSLimits"
// NewEBS returns function that initializes a new plugin and returns it.
func NewEBS(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func NewEBS(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
informerFactory := handle.SharedInformerFactory()
return newNonCSILimitsWithInformerFactory(ebsVolumeFilterType, informerFactory), nil
}
@ -95,7 +95,7 @@ func NewEBS(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plu
const GCEPDName = "GCEPDLimits"
// NewGCEPD returns function that initializes a new plugin and returns it.
func NewGCEPD(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func NewGCEPD(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
informerFactory := handle.SharedInformerFactory()
return newNonCSILimitsWithInformerFactory(gcePDVolumeFilterType, informerFactory), nil
}

View File

@ -83,7 +83,7 @@ func (pl *PodTopologySpread) BuildArgs() interface{} {
}
// New initializes a new plugin and returns it.
func New(args *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func New(args runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
if h.SnapshotSharedLister() == nil {
return nil, fmt.Errorf("SnapshotSharedlister is nil")
}

View File

@ -45,6 +45,6 @@ func (pl *PrioritySort) Less(pInfo1, pInfo2 *framework.PodInfo) bool {
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
return &PrioritySort{}, nil
}

View File

@ -63,7 +63,7 @@ func (s *preFilterState) Clone() framework.StateData {
}
// New initializes a new plugin and returns it.
func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func New(plArgs runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
args := schedulerv1alpha2.ServiceAffinityArgs{}
if err := framework.DecodeInto(plArgs, &args); err != nil {
return nil, err

View File

@ -167,6 +167,6 @@ func (pl *TaintToleration) ScoreExtensions() framework.ScoreExtensions {
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) {
return &TaintToleration{handle: h}, nil
}

View File

@ -88,7 +88,7 @@ func (pl *VolumeBinding) Filter(ctx context.Context, cs *framework.CycleState, p
}
// New initializes a new plugin with volume binder and returns it.
func New(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
return &VolumeBinding{
binder: fh.VolumeBinder(),
}, nil

View File

@ -129,6 +129,6 @@ func (pl *VolumeRestrictions) Filter(ctx context.Context, _ *framework.CycleStat
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &VolumeRestrictions{}, nil
}

View File

@ -172,7 +172,7 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod *
}
// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
func New(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) {
informerFactory := handle.SharedInformerFactory()
pvLister := informerFactory.Core().V1().PersistentVolumes().Lister()
pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister()

View File

@ -197,13 +197,13 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
// get needed plugins from config
pg := f.pluginsNeeded(plugins)
pluginConfig := make(map[string]*runtime.Unknown, 0)
pluginConfig := make(map[string]runtime.Object, 0)
for i := range args {
name := args[i].Name
if _, ok := pluginConfig[name]; ok {
return nil, fmt.Errorf("repeated config for plugin %s", name)
}
pluginConfig[name] = &args[i].Args
pluginConfig[name] = args[i].Args
}
pluginsMap := make(map[string]Plugin)

View File

@ -53,7 +53,7 @@ const (
var _ ScorePlugin = &TestScoreWithNormalizePlugin{}
var _ ScorePlugin = &TestScorePlugin{}
func newScoreWithNormalizePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error) {
func newScoreWithNormalizePlugin1(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) {
var inj injectedResult
if err := DecodeInto(injArgs, &inj); err != nil {
return nil, err
@ -61,7 +61,7 @@ func newScoreWithNormalizePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (
return &TestScoreWithNormalizePlugin{scoreWithNormalizePlugin1, inj}, nil
}
func newScoreWithNormalizePlugin2(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error) {
func newScoreWithNormalizePlugin2(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) {
var inj injectedResult
if err := DecodeInto(injArgs, &inj); err != nil {
return nil, err
@ -69,7 +69,7 @@ func newScoreWithNormalizePlugin2(injArgs *runtime.Unknown, f FrameworkHandle) (
return &TestScoreWithNormalizePlugin{scoreWithNormalizePlugin2, inj}, nil
}
func newScorePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error) {
func newScorePlugin1(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) {
var inj injectedResult
if err := DecodeInto(injArgs, &inj); err != nil {
return nil, err
@ -77,7 +77,7 @@ func newScorePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error
return &TestScorePlugin{scorePlugin1, inj}, nil
}
func newPluginNotImplementingScore(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
func newPluginNotImplementingScore(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return &PluginNotImplementingScore{}, nil
}
@ -259,7 +259,7 @@ func (dp *TestDuplicatePlugin) PreFilterExtensions() PreFilterExtensions {
var _ PreFilterPlugin = &TestDuplicatePlugin{}
func newDuplicatePlugin(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
func newDuplicatePlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return &TestDuplicatePlugin{}, nil
}
@ -277,7 +277,7 @@ func (pp *TestPermitPlugin) Permit(ctx context.Context, state *CycleState, p *v1
var _ QueueSortPlugin = &TestQueueSortPlugin{}
func newQueueSortPlugin(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
func newQueueSortPlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return &TestQueueSortPlugin{}, nil
}
@ -294,7 +294,7 @@ func (pl *TestQueueSortPlugin) Less(_, _ *PodInfo) bool {
var _ BindPlugin = &TestBindPlugin{}
func newBindPlugin(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
func newBindPlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return &TestBindPlugin{}, nil
}
@ -479,7 +479,7 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scorePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{ "scoreRes": 1 }`),
},
},
@ -496,7 +496,7 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scoreWithNormalizePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{ "scoreRes": 10, "normalizeRes": 5 }`),
},
},
@ -512,19 +512,19 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scorePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{ "scoreRes": 1 }`),
},
},
{
Name: scoreWithNormalizePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{ "scoreRes": 3, "normalizeRes": 4}`),
},
},
{
Name: scoreWithNormalizePlugin2,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{ "scoreRes": 4, "normalizeRes": 5}`),
},
},
@ -543,7 +543,7 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scoreWithNormalizePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{ "scoreStatus": 1 }`),
},
},
@ -556,7 +556,7 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scoreWithNormalizePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(`{ "normalizeStatus": 1 }`),
},
},
@ -570,7 +570,7 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scorePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(fmt.Sprintf(`{ "scoreRes": %d }`, MaxNodeScore+1)),
},
},
@ -583,7 +583,7 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scorePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(fmt.Sprintf(`{ "scoreRes": %d }`, MinNodeScore-1)),
},
},
@ -596,7 +596,7 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scoreWithNormalizePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(fmt.Sprintf(`{ "normalizeRes": %d }`, MaxNodeScore+1)),
},
},
@ -609,7 +609,7 @@ func TestRunScorePlugins(t *testing.T) {
pluginConfigs: []config.PluginConfig{
{
Name: scoreWithNormalizePlugin1,
Args: runtime.Unknown{
Args: &runtime.Unknown{
Raw: []byte(fmt.Sprintf(`{ "normalizeRes": %d }`, MinNodeScore-1)),
},
},
@ -650,11 +650,11 @@ func TestPreFilterPlugins(t *testing.T) {
preFilter2 := &TestPreFilterWithExtensionsPlugin{}
r := make(Registry)
r.Register(preFilterPluginName,
func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) {
func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) {
return preFilter1, nil
})
r.Register(preFilterWithExtensionsPluginName,
func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) {
func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) {
return preFilter2, nil
})
plugins := &config.Plugins{PreFilter: &config.PluginSet{Enabled: []config.Plugin{{Name: preFilterWithExtensionsPluginName}, {Name: preFilterPluginName}}}}
@ -874,7 +874,7 @@ func TestFilterPlugins(t *testing.T) {
// register all plugins
tmpPl := pl
if err := registry.Register(pl.name,
func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return tmpPl, nil
}); err != nil {
t.Fatalf("fail to register filter plugin (%s)", pl.name)
@ -1032,7 +1032,7 @@ func TestPreBindPlugins(t *testing.T) {
for _, pl := range tt.plugins {
tmpPl := pl
if err := registry.Register(pl.name, func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return tmpPl, nil
}); err != nil {
t.Fatalf("Unable to register pre bind plugins: %s", pl.name)
@ -1188,7 +1188,7 @@ func TestReservePlugins(t *testing.T) {
for _, pl := range tt.plugins {
tmpPl := pl
if err := registry.Register(pl.name, func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return tmpPl, nil
}); err != nil {
t.Fatalf("Unable to register pre bind plugins: %s", pl.name)
@ -1311,7 +1311,7 @@ func TestPermitPlugins(t *testing.T) {
for _, pl := range tt.plugins {
tmpPl := pl
if err := registry.Register(pl.name, func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return tmpPl, nil
}); err != nil {
t.Fatalf("Unable to register Permit plugin: %s", pl.name)
@ -1469,7 +1469,7 @@ func TestRecordingMetrics(t *testing.T) {
plugin := &TestPlugin{name: testPlugin, inj: tt.inject}
r := make(Registry)
r.Register(testPlugin,
func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) {
func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) {
return plugin, nil
})
pluginSet := &config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin, Weight: 1}}}
@ -1584,7 +1584,7 @@ func TestRunBindPlugins(t *testing.T) {
name := fmt.Sprintf("bind-%d", i)
plugin := &TestPlugin{name: name, inj: injectedResult{BindStatus: int(inj)}}
r.Register(name,
func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) {
func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) {
return plugin, nil
})
pluginSet.Enabled = append(pluginSet.Enabled, config.Plugin{Name: name})
@ -1635,7 +1635,7 @@ func TestPermitWaitDurationMetric(t *testing.T) {
plugin := &TestPlugin{name: testPlugin, inj: tt.inject}
r := make(Registry)
err := r.Register(testPlugin,
func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) {
func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) {
return plugin, nil
})
if err != nil {
@ -1694,7 +1694,7 @@ func TestWaitOnPermit(t *testing.T) {
testPermitPlugin := &TestPermitPlugin{}
r := make(Registry)
r.Register(permitPlugin,
func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) {
func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) {
return testPermitPlugin, nil
})
plugins := &config.Plugins{

View File

@ -25,11 +25,18 @@ import (
)
// PluginFactory is a function that builds a plugin.
type PluginFactory = func(configuration *runtime.Unknown, f FrameworkHandle) (Plugin, error)
type PluginFactory = func(configuration runtime.Object, f FrameworkHandle) (Plugin, error)
// DecodeInto decodes configuration whose type is *runtime.Unknown to the interface into.
func DecodeInto(configuration *runtime.Unknown, into interface{}) error {
if configuration == nil || configuration.Raw == nil {
func DecodeInto(obj runtime.Object, into interface{}) error {
if obj == nil {
return nil
}
configuration, ok := obj.(*runtime.Unknown)
if !ok {
return fmt.Errorf("want args of type runtime.Unknown, got %T", obj)
}
if configuration.Raw == nil {
return nil
}

View File

@ -102,7 +102,7 @@ func (p *mockNoopPlugin) Name() string {
}
func NewMockNoopPluginFactory() PluginFactory {
return func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
return func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) {
return &mockNoopPlugin{}, nil
}
}

View File

@ -91,7 +91,7 @@ func NewRecorderFactory(b events.EventBroadcaster) RecorderFactory {
type cfgValidator struct {
m Map
queueSort string
queueSortArgs runtime.Unknown
queueSortArgs runtime.Object
}
func (v *cfgValidator) validate(cfg config.KubeSchedulerProfile) error {
@ -108,7 +108,7 @@ func (v *cfgValidator) validate(cfg config.KubeSchedulerProfile) error {
return fmt.Errorf("one queue sort plugin required for profile with scheduler name %q", cfg.SchedulerName)
}
queueSort := cfg.Plugins.QueueSort.Enabled[0].Name
var queueSortArgs runtime.Unknown
var queueSortArgs runtime.Object
for _, plCfg := range cfg.PluginConfig {
if plCfg.Name == queueSort {
queueSortArgs = plCfg.Args
@ -123,7 +123,7 @@ func (v *cfgValidator) validate(cfg config.KubeSchedulerProfile) error {
return fmt.Errorf("different queue sort plugins for profile %q: %q, first: %q", cfg.SchedulerName, queueSort, v.queueSort)
}
if !cmp.Equal(v.queueSortArgs, queueSortArgs) {
return fmt.Errorf("different queue sort plugin args for profile %q: %s", cfg.SchedulerName, queueSortArgs.Raw)
return fmt.Errorf("different queue sort plugin args for profile %q", cfg.SchedulerName)
}
return nil
}

View File

@ -63,7 +63,7 @@ func TestNewProfile(t *testing.T) {
PluginConfig: []config.PluginConfig{
{
Name: "QueueSort",
Args: runtime.Unknown{Raw: []byte("{}")},
Args: &runtime.Unknown{Raw: []byte("{}")},
},
},
},
@ -153,7 +153,7 @@ func TestNewMap(t *testing.T) {
PluginConfig: []config.PluginConfig{
{
Name: "Bind2",
Args: runtime.Unknown{Raw: []byte("{}")},
Args: &runtime.Unknown{Raw: []byte("{}")},
},
},
},
@ -215,7 +215,7 @@ func TestNewMap(t *testing.T) {
PluginConfig: []config.PluginConfig{
{
Name: "QueueSort",
Args: runtime.Unknown{Raw: []byte("{}")},
Args: &runtime.Unknown{Raw: []byte("{}")},
},
},
},
@ -304,7 +304,7 @@ func (p *fakePlugin) Bind(context.Context, *framework.CycleState, *v1.Pod, strin
return nil
}
func newFakePlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func newFakePlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &fakePlugin{}, nil
}

View File

@ -388,7 +388,7 @@ type fakeNodeSelector struct {
fakeNodeSelectorArgs
}
func newFakeNodeSelector(args *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
func newFakeNodeSelector(args runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
pl := &fakeNodeSelector{}
if err := framework.DecodeInto(args, &pl.fakeNodeSelectorArgs); err != nil {
return nil, err
@ -455,7 +455,7 @@ func TestSchedulerMultipleProfilesScheduling(t *testing.T) {
}},
PluginConfig: []schedulerapi.PluginConfig{
{Name: "FakeNodeSelector",
Args: runtime.Unknown{Raw: []byte(`{"nodeName":"machine2"}`)},
Args: &runtime.Unknown{Raw: []byte(`{"nodeName":"machine2"}`)},
},
},
},
@ -468,7 +468,7 @@ func TestSchedulerMultipleProfilesScheduling(t *testing.T) {
}},
PluginConfig: []schedulerapi.PluginConfig{
{Name: "FakeNodeSelector",
Args: runtime.Unknown{Raw: []byte(`{"nodeName":"machine3"}`)},
Args: &runtime.Unknown{Raw: []byte(`{"nodeName":"machine3"}`)},
},
},
},

View File

@ -200,5 +200,5 @@ type PluginConfig struct {
// Name defines the name of plugin being configured
Name string `json:"name"`
// Args defines the arguments passed to the plugins at the time of initialization. Args can have arbitrary structure.
Args runtime.Unknown `json:"args,omitempty"`
Args runtime.RawExtension `json:"args,omitempty"`
}

View File

@ -136,7 +136,7 @@ var _ framework.PermitPlugin = &PermitPlugin{}
// newPlugin returns a plugin factory with specified Plugin.
func newPlugin(plugin framework.Plugin) framework.PluginFactory {
return func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
return plugin, nil
}
}
@ -454,7 +454,7 @@ func (pp *PermitPlugin) reset() {
// newPermitPlugin returns a factory for permit plugin with specified PermitPlugin.
func newPermitPlugin(permitPlugin *PermitPlugin) framework.PluginFactory {
return func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
permitPlugin.fh = fh
return permitPlugin, nil
}
@ -860,16 +860,16 @@ func TestBindPlugin(t *testing.T) {
postBindPlugin := &PostBindPlugin{name: "mock-post-bind-plugin"}
// Create a plugin registry for testing. Register an unreserve, a bind plugin and a postBind plugin.
registry := framework.Registry{
unreservePlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
unreservePlugin.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return unreservePlugin, nil
},
bindPlugin1.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
bindPlugin1.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return bindPlugin1, nil
},
bindPlugin2.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
bindPlugin2.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return bindPlugin2, nil
},
postBindPlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
postBindPlugin.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return postBindPlugin, nil
},
}

View File

@ -122,7 +122,7 @@ func TestPreemption(t *testing.T) {
// Initialize scheduler with a filter plugin.
var filter tokenFilter
registry := make(framework.Registry)
err := registry.Register(filterPluginName, func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
err := registry.Register(filterPluginName, func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
return &filter, nil
})
if err != nil {