volcano icon indicating copy to clipboard operation
volcano copied to clipboard

❇️ add vcinformer.SharedInformerFactory, vcClient vcclient.Interface to framework.Session

Open kingeasternsun opened this issue 1 year ago • 5 comments

What would you like to be added:

add

vcinformer.SharedInformerFactory
vcClient     vcclient.Interface 

to framework.Sesstion

type Session struct {
	UID types.UID

	kubeClient      kubernetes.Interface
	recorder        record.EventRecorder
	cache           cache.Cache
	restConfig      *rest.Config
	informerFactory informers.SharedInformerFactory

	vcinformer.SharedInformerFactory
	vcClient     vcclient.Interface 

Why is this needed:

Some plugin need get vcClient and vcinformer from session, otherwise they have to create a separate vcClient and vcinformer.

for example, in ascend-volcano-plugin https://gitee.com/ascend/ascend-for-volcano/blob/branch_v6.0.0-RC1/plugin/factory.go#L426 , they have to create a a separate vcClient and vcinformer, these vcinfomer cannot share indexer cache with the informer in scheduler.


func (sHandle *ScheduleHandler) initNSLB2(ssn *framework.Session) error {
	vcClient, err := NewVCClinetk8s()
	if err != nil {
		klog.V(util.LogErrorLev).Infof("create vc client err: %v.", err)
		return err
	}
	factory := externalversions.NewSharedInformerFactory(vcClient, 0)
	pgInformer := factory.Scheduling().V1beta1().PodGroups()
	cacheIndexer := pgInformer.Informer().GetIndexer()
	agents, err := NewAgent(ssn.KubeClient(), newConfig())
	if err != nil {
		klog.V(util.LogErrorLev).Infof("create agent err: %v", err)
		return err
	}
	...
}

kingeasternsun avatar Jul 01 '24 09:07 kingeasternsun

I think it's reasonable.

Monokaix avatar Jul 02 '24 06:07 Monokaix

Why informer is used instead of snapshot of that?

lowang-bh avatar Jul 08 '24 06:07 lowang-bh

Does this feature need to be added? I have proposed a PR.

Prepmachine4 avatar Aug 06 '24 14:08 Prepmachine4

Why informer is used instead of snapshot of that?

+1, IMO, I also think it is more reasonable to use snapshot.

But I am not sure about the purpose of these two variables introduced by this plugin. I think if we need to obtain resource objects from k8s, we should use snapshot instead of introducing informerFactory again, because snapshot is originally a cache obtained by informerFactory. Excessive introduction of other variables is not a good design method, especially the informerFactory cache, which may also increase memory usage.

googs1025 avatar Aug 06 '24 14:08 googs1025

I think the key problem is the purpose of the plugin using the informer, if it's a generic scenario, it can be provided in the session, if the plugin has additional processing logic, it can be placed in the snapshot, but this will also increase the cache.

Monokaix avatar Aug 08 '24 02:08 Monokaix

I think the key problem is the purpose of the plugin using the informer, if it's a generic scenario, it can be provided in the session, if the plugin has additional processing logic, it can be placed in the snapshot, but this will also increase the cache.

yep, so far I know that the ascend-volcano-plugin https://gitee.com/ascend/ascend-for-volcano/blob/branch_v6.0.0-RC1/plugin/factory.go#L426 has this requeirement. But many complex plugin I known, they need keep their own cache by informer eventhandler, so they need a infomer factory. If volcano not give this , each plugin have to construct a individual shared informer factory, could not share informer cache with each other. @Monokaix @googs1025 @lowang-bh

kingeasternsun avatar Nov 26 '24 15:11 kingeasternsun