mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #80233 from alculquicondor/refactor/configurator
Remove NodeLister from Scheduler Configurator
This commit is contained in:
commit
d248bd099d
@ -152,9 +152,7 @@ type Configurator interface {
|
|||||||
// Exposed for testing
|
// Exposed for testing
|
||||||
GetClient() clientset.Interface
|
GetClient() clientset.Interface
|
||||||
|
|
||||||
// TODO(#80216): Remove these methods from the interface.
|
// TODO(#80216): Remove GetScheduledPodLister from the interface.
|
||||||
// Needs to be exposed for things like integration tests where we want to make fake nodes.
|
|
||||||
GetNodeLister() corelisters.NodeLister
|
|
||||||
// Exposed for testing
|
// Exposed for testing
|
||||||
GetScheduledPodLister() corelisters.PodLister
|
GetScheduledPodLister() corelisters.PodLister
|
||||||
|
|
||||||
@ -165,13 +163,11 @@ type Configurator interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configFactory is the default implementation of the scheduler.Configurator interface.
|
// configFactory is the default implementation of the scheduler.Configurator interface.
|
||||||
// TODO(#80216): Remove pod and node listers.
|
// TODO(#80216): Remove pod lister.
|
||||||
type configFactory struct {
|
type configFactory struct {
|
||||||
client clientset.Interface
|
client clientset.Interface
|
||||||
// a means to list all known scheduled pods.
|
// a means to list all known scheduled pods.
|
||||||
scheduledPodLister corelisters.PodLister
|
scheduledPodLister corelisters.PodLister
|
||||||
// a means to list all nodes
|
|
||||||
nodeLister corelisters.NodeLister
|
|
||||||
// a means to list all PersistentVolumes
|
// a means to list all PersistentVolumes
|
||||||
pVLister corelisters.PersistentVolumeLister
|
pVLister corelisters.PersistentVolumeLister
|
||||||
// a means to list all PersistentVolumeClaims
|
// a means to list all PersistentVolumeClaims
|
||||||
@ -281,7 +277,6 @@ func NewConfigFactory(args *ConfigFactoryArgs) Configurator {
|
|||||||
c := &configFactory{
|
c := &configFactory{
|
||||||
client: args.Client,
|
client: args.Client,
|
||||||
podQueue: internalqueue.NewSchedulingQueue(stopEverything, framework),
|
podQueue: internalqueue.NewSchedulingQueue(stopEverything, framework),
|
||||||
nodeLister: args.NodeInformer.Lister(),
|
|
||||||
pVLister: args.PvInformer.Lister(),
|
pVLister: args.PvInformer.Lister(),
|
||||||
pVCLister: args.PvcInformer.Lister(),
|
pVCLister: args.PvcInformer.Lister(),
|
||||||
serviceLister: args.ServiceInformer.Lister(),
|
serviceLister: args.ServiceInformer.Lister(),
|
||||||
@ -324,11 +319,6 @@ func NewConfigFactory(args *ConfigFactoryArgs) Configurator {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNodeStore provides the cache to the nodes, mostly internal use, but may also be called by mock-tests.
|
|
||||||
func (c *configFactory) GetNodeLister() corelisters.NodeLister {
|
|
||||||
return c.nodeLister
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *configFactory) GetHardPodAffinitySymmetricWeight() int32 {
|
func (c *configFactory) GetHardPodAffinitySymmetricWeight() int32 {
|
||||||
return c.hardPodAffinitySymmetricWeight
|
return c.hardPodAffinitySymmetricWeight
|
||||||
}
|
}
|
||||||
|
@ -56,11 +56,6 @@ func (fc *FakeConfigurator) MakeDefaultErrorFunc(backoff *internalqueue.PodBacko
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNodeLister is not implemented yet.
|
|
||||||
func (fc *FakeConfigurator) GetNodeLister() corelisters.NodeLister {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetClient is not implemented yet.
|
// GetClient is not implemented yet.
|
||||||
func (fc *FakeConfigurator) GetClient() clientset.Interface {
|
func (fc *FakeConfigurator) GetClient() clientset.Interface {
|
||||||
return nil
|
return nil
|
||||||
|
@ -354,7 +354,7 @@ func TestUnschedulableNodes(t *testing.T) {
|
|||||||
context := initTest(t, "unschedulable-nodes")
|
context := initTest(t, "unschedulable-nodes")
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
nodeLister := context.schedulerConfigFactory.GetNodeLister()
|
nodeLister := context.schedulerConfigArgs.NodeInformer.Lister()
|
||||||
// NOTE: This test cannot run in parallel, because it is creating and deleting
|
// NOTE: This test cannot run in parallel, because it is creating and deleting
|
||||||
// non-namespaced objects (Nodes).
|
// non-namespaced objects (Nodes).
|
||||||
defer context.clientSet.CoreV1().Nodes().DeleteCollection(nil, metav1.ListOptions{})
|
defer context.clientSet.CoreV1().Nodes().DeleteCollection(nil, metav1.ListOptions{})
|
||||||
@ -605,8 +605,8 @@ func TestMultiScheduler(t *testing.T) {
|
|||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
defer close(stopCh)
|
defer close(stopCh)
|
||||||
|
|
||||||
schedulerConfigFactory2 := createConfiguratorWithPodInformer(fooScheduler, clientSet2, podInformer2, informerFactory2, schedulerframework.NewRegistry(),
|
schedulerConfigFactory2 := factory.NewConfigFactory(createConfiguratorArgsWithPodInformer(fooScheduler, clientSet2, podInformer2, informerFactory2, schedulerframework.NewRegistry(),
|
||||||
nil, []kubeschedulerconfig.PluginConfig{}, stopCh)
|
nil, []kubeschedulerconfig.PluginConfig{}, stopCh))
|
||||||
schedulerConfig2, err := schedulerConfigFactory2.Create()
|
schedulerConfig2, err := schedulerConfigFactory2.Create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Couldn't create scheduler config: %v", err)
|
t.Errorf("Couldn't create scheduler config: %v", err)
|
||||||
|
@ -66,14 +66,14 @@ type testContext struct {
|
|||||||
ns *v1.Namespace
|
ns *v1.Namespace
|
||||||
clientSet *clientset.Clientset
|
clientSet *clientset.Clientset
|
||||||
informerFactory informers.SharedInformerFactory
|
informerFactory informers.SharedInformerFactory
|
||||||
schedulerConfigFactory factory.Configurator
|
schedulerConfigArgs *factory.ConfigFactoryArgs
|
||||||
schedulerConfig *factory.Config
|
schedulerConfig *factory.Config
|
||||||
scheduler *scheduler.Scheduler
|
scheduler *scheduler.Scheduler
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// createConfiguratorWithPodInformer creates a configurator for scheduler.
|
// createConfiguratorWithPodInformer creates a configurator for scheduler.
|
||||||
func createConfiguratorWithPodInformer(
|
func createConfiguratorArgsWithPodInformer(
|
||||||
schedulerName string,
|
schedulerName string,
|
||||||
clientSet clientset.Interface,
|
clientSet clientset.Interface,
|
||||||
podInformer coreinformers.PodInformer,
|
podInformer coreinformers.PodInformer,
|
||||||
@ -82,8 +82,8 @@ func createConfiguratorWithPodInformer(
|
|||||||
plugins *schedulerconfig.Plugins,
|
plugins *schedulerconfig.Plugins,
|
||||||
pluginConfig []schedulerconfig.PluginConfig,
|
pluginConfig []schedulerconfig.PluginConfig,
|
||||||
stopCh <-chan struct{},
|
stopCh <-chan struct{},
|
||||||
) factory.Configurator {
|
) *factory.ConfigFactoryArgs {
|
||||||
return factory.NewConfigFactory(&factory.ConfigFactoryArgs{
|
return &factory.ConfigFactoryArgs{
|
||||||
SchedulerName: schedulerName,
|
SchedulerName: schedulerName,
|
||||||
Client: clientSet,
|
Client: clientSet,
|
||||||
NodeInformer: informerFactory.Core().V1().Nodes(),
|
NodeInformer: informerFactory.Core().V1().Nodes(),
|
||||||
@ -105,7 +105,7 @@ func createConfiguratorWithPodInformer(
|
|||||||
PercentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
|
PercentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
|
||||||
BindTimeoutSeconds: 600,
|
BindTimeoutSeconds: 600,
|
||||||
StopCh: stopCh,
|
StopCh: stopCh,
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initTestMasterAndScheduler initializes a test environment and creates a master with default
|
// initTestMasterAndScheduler initializes a test environment and creates a master with default
|
||||||
@ -186,16 +186,17 @@ func initTestSchedulerWithOptions(
|
|||||||
podInformer = context.informerFactory.Core().V1().Pods()
|
podInformer = context.informerFactory.Core().V1().Pods()
|
||||||
}
|
}
|
||||||
|
|
||||||
context.schedulerConfigFactory = createConfiguratorWithPodInformer(
|
context.schedulerConfigArgs = createConfiguratorArgsWithPodInformer(
|
||||||
v1.DefaultSchedulerName, context.clientSet, podInformer, context.informerFactory, pluginRegistry, plugins,
|
v1.DefaultSchedulerName, context.clientSet, podInformer, context.informerFactory, pluginRegistry, plugins,
|
||||||
pluginConfig, context.stopCh)
|
pluginConfig, context.stopCh)
|
||||||
|
configFactory := factory.NewConfigFactory(context.schedulerConfigArgs)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if policy != nil {
|
if policy != nil {
|
||||||
context.schedulerConfig, err = context.schedulerConfigFactory.CreateFromConfig(*policy)
|
context.schedulerConfig, err = configFactory.CreateFromConfig(*policy)
|
||||||
} else {
|
} else {
|
||||||
context.schedulerConfig, err = context.schedulerConfigFactory.Create()
|
context.schedulerConfig, err = configFactory.Create()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user