mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Remove wrappers around storage-related listers in the predicate
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
This commit is contained in:
parent
e4bb49a231
commit
3bfdcf56e6
@ -23,6 +23,9 @@ import (
|
||||
storagev1beta1 "k8s.io/api/storage/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
corelisters "k8s.io/client-go/listers/core/v1"
|
||||
storagelisters "k8s.io/client-go/listers/storage/v1"
|
||||
v1beta1storagelisters "k8s.io/client-go/listers/storage/v1beta1"
|
||||
csitrans "k8s.io/csi-translation-lib"
|
||||
"k8s.io/klog"
|
||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
@ -43,10 +46,10 @@ type InTreeToCSITranslator interface {
|
||||
|
||||
// CSIMaxVolumeLimitChecker defines predicate needed for counting CSI volumes
|
||||
type CSIMaxVolumeLimitChecker struct {
|
||||
csiNodeInfo CSINodeInfo
|
||||
pvInfo PersistentVolumeInfo
|
||||
pvcInfo PersistentVolumeClaimInfo
|
||||
scInfo StorageClassInfo
|
||||
csiNodeLister v1beta1storagelisters.CSINodeLister
|
||||
pvLister corelisters.PersistentVolumeLister
|
||||
pvcLister corelisters.PersistentVolumeClaimLister
|
||||
scLister storagelisters.StorageClassLister
|
||||
|
||||
randomVolumeIDPrefix string
|
||||
|
||||
@ -55,12 +58,12 @@ type CSIMaxVolumeLimitChecker struct {
|
||||
|
||||
// NewCSIMaxVolumeLimitPredicate returns a predicate for counting CSI volumes
|
||||
func NewCSIMaxVolumeLimitPredicate(
|
||||
csiNodeInfo CSINodeInfo, pvInfo PersistentVolumeInfo, pvcInfo PersistentVolumeClaimInfo, scInfo StorageClassInfo) FitPredicate {
|
||||
csiNodeLister v1beta1storagelisters.CSINodeLister, pvLister corelisters.PersistentVolumeLister, pvcLister corelisters.PersistentVolumeClaimLister, scLister storagelisters.StorageClassLister) FitPredicate {
|
||||
c := &CSIMaxVolumeLimitChecker{
|
||||
csiNodeInfo: csiNodeInfo,
|
||||
pvInfo: pvInfo,
|
||||
pvcInfo: pvcInfo,
|
||||
scInfo: scInfo,
|
||||
csiNodeLister: csiNodeLister,
|
||||
pvLister: pvLister,
|
||||
pvcLister: pvcLister,
|
||||
scLister: scLister,
|
||||
randomVolumeIDPrefix: rand.String(32),
|
||||
translator: csitrans.New(),
|
||||
}
|
||||
@ -100,7 +103,7 @@ func (c *CSIMaxVolumeLimitChecker) attachableLimitPredicate(
|
||||
}
|
||||
|
||||
// If CSINode doesn't exist, the predicate may read the limits from Node object
|
||||
csiNode, err := c.csiNodeInfo.GetCSINodeInfo(node.Name)
|
||||
csiNode, err := c.csiNodeLister.Get(node.Name)
|
||||
if err != nil {
|
||||
// TODO: return the error once CSINode is created by default (2 releases)
|
||||
klog.V(5).Infof("Could not get a CSINode object for the node: %v", err)
|
||||
@ -169,7 +172,7 @@ func (c *CSIMaxVolumeLimitChecker) filterAttachableVolumes(
|
||||
return fmt.Errorf("PersistentVolumeClaim had no name")
|
||||
}
|
||||
|
||||
pvc, err := c.pvcInfo.GetPersistentVolumeClaimInfo(namespace, pvcName)
|
||||
pvc, err := c.pvcLister.PersistentVolumeClaims(namespace).Get(pvcName)
|
||||
|
||||
if err != nil {
|
||||
klog.V(5).Infof("Unable to look up PVC info for %s/%s", namespace, pvcName)
|
||||
@ -202,7 +205,7 @@ func (c *CSIMaxVolumeLimitChecker) getCSIDriverInfo(csiNode *storagev1beta1.CSIN
|
||||
return c.getCSIDriverInfoFromSC(csiNode, pvc)
|
||||
}
|
||||
|
||||
pv, err := c.pvInfo.GetPersistentVolumeInfo(pvName)
|
||||
pv, err := c.pvLister.Get(pvName)
|
||||
if err != nil {
|
||||
klog.V(5).Infof("Unable to look up PV info for PVC %s/%s and PV %s", namespace, pvcName, pvName)
|
||||
// If we can't fetch PV associated with PVC, may be it got deleted
|
||||
@ -259,7 +262,7 @@ func (c *CSIMaxVolumeLimitChecker) getCSIDriverInfoFromSC(csiNode *storagev1beta
|
||||
return "", ""
|
||||
}
|
||||
|
||||
storageClass, err := c.scInfo.GetStorageClassInfo(scName)
|
||||
storageClass, err := c.scLister.Get(scName)
|
||||
if err != nil {
|
||||
klog.V(5).Infof("Could not get StorageClass for PVC %s/%s: %v", namespace, pvcName, err)
|
||||
return "", ""
|
||||
|
@ -160,75 +160,6 @@ type NodeInfo interface {
|
||||
// The failure information is given by the error.
|
||||
type FitPredicate func(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error)
|
||||
|
||||
// CSINodeInfo interface represents anything that can get CSINode object from node name.
|
||||
type CSINodeInfo interface {
|
||||
GetCSINodeInfo(nodeName string) (*v1beta1storage.CSINode, error)
|
||||
}
|
||||
|
||||
var _ CSINodeInfo = &CachedCSINodeInfo{}
|
||||
|
||||
// CachedCSINodeInfo implements CSINodeInfoInfo
|
||||
type CachedCSINodeInfo struct {
|
||||
v1beta1storagelisters.CSINodeLister
|
||||
}
|
||||
|
||||
// GetCSINodeInfo returns a persistent volume object by PV ID.
|
||||
func (c *CachedCSINodeInfo) GetCSINodeInfo(nodeName string) (*v1beta1storage.CSINode, error) {
|
||||
return c.Get(nodeName)
|
||||
}
|
||||
|
||||
// PersistentVolumeInfo interface represents anything that can get persistent volume object by PV ID.
|
||||
type PersistentVolumeInfo interface {
|
||||
GetPersistentVolumeInfo(pvID string) (*v1.PersistentVolume, error)
|
||||
}
|
||||
|
||||
var _ PersistentVolumeInfo = &CachedPersistentVolumeInfo{}
|
||||
|
||||
// CachedPersistentVolumeInfo implements PersistentVolumeInfo
|
||||
type CachedPersistentVolumeInfo struct {
|
||||
corelisters.PersistentVolumeLister
|
||||
}
|
||||
|
||||
// GetPersistentVolumeInfo returns a persistent volume object by PV ID.
|
||||
func (c *CachedPersistentVolumeInfo) GetPersistentVolumeInfo(pvID string) (*v1.PersistentVolume, error) {
|
||||
return c.Get(pvID)
|
||||
}
|
||||
|
||||
// PersistentVolumeClaimInfo interface represents anything that can get a PVC object in
|
||||
// specified namespace with specified name.
|
||||
type PersistentVolumeClaimInfo interface {
|
||||
GetPersistentVolumeClaimInfo(namespace string, name string) (*v1.PersistentVolumeClaim, error)
|
||||
}
|
||||
|
||||
var _ PersistentVolumeClaimInfo = &CachedPersistentVolumeClaimInfo{}
|
||||
|
||||
// CachedPersistentVolumeClaimInfo implements PersistentVolumeClaimInfo
|
||||
type CachedPersistentVolumeClaimInfo struct {
|
||||
corelisters.PersistentVolumeClaimLister
|
||||
}
|
||||
|
||||
// GetPersistentVolumeClaimInfo fetches the claim in specified namespace with specified name.
|
||||
func (c *CachedPersistentVolumeClaimInfo) GetPersistentVolumeClaimInfo(namespace string, name string) (*v1.PersistentVolumeClaim, error) {
|
||||
return c.PersistentVolumeClaims(namespace).Get(name)
|
||||
}
|
||||
|
||||
// StorageClassInfo interface represents anything that can get a storage class object by class name.
|
||||
type StorageClassInfo interface {
|
||||
GetStorageClassInfo(className string) (*storage.StorageClass, error)
|
||||
}
|
||||
|
||||
var _ StorageClassInfo = &CachedStorageClassInfo{}
|
||||
|
||||
// CachedStorageClassInfo implements StorageClassInfo
|
||||
type CachedStorageClassInfo struct {
|
||||
storagelisters.StorageClassLister
|
||||
}
|
||||
|
||||
// GetStorageClassInfo get StorageClass by class name.
|
||||
func (c *CachedStorageClassInfo) GetStorageClassInfo(className string) (*storage.StorageClass, error) {
|
||||
return c.Get(className)
|
||||
}
|
||||
|
||||
func isVolumeConflict(volume v1.Volume, pod *v1.Pod) bool {
|
||||
// fast path if there is no conflict checking targets.
|
||||
if volume.GCEPersistentDisk == nil && volume.AWSElasticBlockStore == nil && volume.RBD == nil && volume.ISCSI == nil {
|
||||
@ -301,10 +232,10 @@ type MaxPDVolumeCountChecker struct {
|
||||
filter VolumeFilter
|
||||
volumeLimitKey v1.ResourceName
|
||||
maxVolumeFunc func(node *v1.Node) int
|
||||
csiNodeInfo CSINodeInfo
|
||||
pvInfo PersistentVolumeInfo
|
||||
pvcInfo PersistentVolumeClaimInfo
|
||||
scInfo StorageClassInfo
|
||||
csiNodeLister v1beta1storagelisters.CSINodeLister
|
||||
pvLister corelisters.PersistentVolumeLister
|
||||
pvcLister corelisters.PersistentVolumeClaimLister
|
||||
scLister storagelisters.StorageClassLister
|
||||
|
||||
// The string below is generated randomly during the struct's initialization.
|
||||
// It is used to prefix volumeID generated inside the predicate() method to
|
||||
@ -333,8 +264,8 @@ type VolumeFilter struct {
|
||||
// The predicate looks for both volumes used directly, as well as PVC volumes that are backed by relevant volume
|
||||
// types, counts the number of unique volumes, and rejects the new pod if it would place the total count over
|
||||
// the maximum.
|
||||
func NewMaxPDVolumeCountPredicate(filterName string, csiNodeInfo CSINodeInfo, scInfo StorageClassInfo,
|
||||
pvInfo PersistentVolumeInfo, pvcInfo PersistentVolumeClaimInfo) FitPredicate {
|
||||
func NewMaxPDVolumeCountPredicate(filterName string, csiNodeLister v1beta1storagelisters.CSINodeLister, scLister storagelisters.StorageClassLister,
|
||||
pvLister corelisters.PersistentVolumeLister, pvcLister corelisters.PersistentVolumeClaimLister) FitPredicate {
|
||||
var filter VolumeFilter
|
||||
var volumeLimitKey v1.ResourceName
|
||||
|
||||
@ -362,10 +293,10 @@ func NewMaxPDVolumeCountPredicate(filterName string, csiNodeInfo CSINodeInfo, sc
|
||||
filter: filter,
|
||||
volumeLimitKey: volumeLimitKey,
|
||||
maxVolumeFunc: getMaxVolumeFunc(filterName),
|
||||
csiNodeInfo: csiNodeInfo,
|
||||
pvInfo: pvInfo,
|
||||
pvcInfo: pvcInfo,
|
||||
scInfo: scInfo,
|
||||
csiNodeLister: csiNodeLister,
|
||||
pvLister: pvLister,
|
||||
pvcLister: pvcLister,
|
||||
scLister: scLister,
|
||||
randomVolumeIDPrefix: rand.String(32),
|
||||
}
|
||||
|
||||
@ -438,7 +369,7 @@ func (c *MaxPDVolumeCountChecker) filterVolumes(volumes []v1.Volume, namespace s
|
||||
// to avoid conflicts with existing volume IDs.
|
||||
pvID := fmt.Sprintf("%s-%s/%s", c.randomVolumeIDPrefix, namespace, pvcName)
|
||||
|
||||
pvc, err := c.pvcInfo.GetPersistentVolumeClaimInfo(namespace, pvcName)
|
||||
pvc, err := c.pvcLister.PersistentVolumeClaims(namespace).Get(pvcName)
|
||||
if err != nil || pvc == nil {
|
||||
// If the PVC is invalid, we don't count the volume because
|
||||
// there's no guarantee that it belongs to the running predicate.
|
||||
@ -459,7 +390,7 @@ func (c *MaxPDVolumeCountChecker) filterVolumes(volumes []v1.Volume, namespace s
|
||||
continue
|
||||
}
|
||||
|
||||
pv, err := c.pvInfo.GetPersistentVolumeInfo(pvName)
|
||||
pv, err := c.pvLister.Get(pvName)
|
||||
if err != nil || pv == nil {
|
||||
// If the PV is invalid and PVC belongs to the running predicate,
|
||||
// log the error and count the PV towards the PV limit.
|
||||
@ -485,7 +416,7 @@ func (c *MaxPDVolumeCountChecker) matchProvisioner(pvc *v1.PersistentVolumeClaim
|
||||
return false
|
||||
}
|
||||
|
||||
storageClass, err := c.scInfo.GetStorageClassInfo(*pvc.Spec.StorageClassName)
|
||||
storageClass, err := c.scLister.Get(*pvc.Spec.StorageClassName)
|
||||
if err != nil || storageClass == nil {
|
||||
return false
|
||||
}
|
||||
@ -515,7 +446,7 @@ func (c *MaxPDVolumeCountChecker) predicate(pod *v1.Pod, meta PredicateMetadata,
|
||||
return false, nil, fmt.Errorf("node not found")
|
||||
}
|
||||
|
||||
csiNode, err := c.csiNodeInfo.GetCSINodeInfo(node.Name)
|
||||
csiNode, err := c.csiNodeLister.Get(node.Name)
|
||||
if err != nil {
|
||||
// we don't fail here because the CSINode object is only necessary
|
||||
// for determining whether the migration is enabled or not
|
||||
@ -681,9 +612,9 @@ var CinderVolumeFilter = VolumeFilter{
|
||||
|
||||
// VolumeZoneChecker contains information to check the volume zone for a predicate.
|
||||
type VolumeZoneChecker struct {
|
||||
pvInfo PersistentVolumeInfo
|
||||
pvcInfo PersistentVolumeClaimInfo
|
||||
classInfo StorageClassInfo
|
||||
pvLister corelisters.PersistentVolumeLister
|
||||
pvcLister corelisters.PersistentVolumeClaimLister
|
||||
scLister storagelisters.StorageClassLister
|
||||
}
|
||||
|
||||
// NewVolumeZonePredicate evaluates if a pod can fit due to the volumes it requests, given
|
||||
@ -700,11 +631,11 @@ type VolumeZoneChecker struct {
|
||||
// determining the zone of a volume during scheduling, and that is likely to
|
||||
// require calling out to the cloud provider. It seems that we are moving away
|
||||
// from inline volume declarations anyway.
|
||||
func NewVolumeZonePredicate(pvInfo PersistentVolumeInfo, pvcInfo PersistentVolumeClaimInfo, classInfo StorageClassInfo) FitPredicate {
|
||||
func NewVolumeZonePredicate(pvLister corelisters.PersistentVolumeLister, pvcLister corelisters.PersistentVolumeClaimLister, scLister storagelisters.StorageClassLister) FitPredicate {
|
||||
c := &VolumeZoneChecker{
|
||||
pvInfo: pvInfo,
|
||||
pvcInfo: pvcInfo,
|
||||
classInfo: classInfo,
|
||||
pvLister: pvLister,
|
||||
pvcLister: pvcLister,
|
||||
scLister: scLister,
|
||||
}
|
||||
return c.predicate
|
||||
}
|
||||
@ -745,7 +676,7 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta PredicateMetadata, nodeI
|
||||
if pvcName == "" {
|
||||
return false, nil, fmt.Errorf("PersistentVolumeClaim had no name")
|
||||
}
|
||||
pvc, err := c.pvcInfo.GetPersistentVolumeClaimInfo(namespace, pvcName)
|
||||
pvc, err := c.pvcLister.PersistentVolumeClaims(namespace).Get(pvcName)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
@ -758,7 +689,7 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta PredicateMetadata, nodeI
|
||||
if pvName == "" {
|
||||
scName := v1helper.GetPersistentVolumeClaimClass(pvc)
|
||||
if len(scName) > 0 {
|
||||
class, _ := c.classInfo.GetStorageClassInfo(scName)
|
||||
class, _ := c.scLister.Get(scName)
|
||||
if class != nil {
|
||||
if class.VolumeBindingMode == nil {
|
||||
return false, nil, fmt.Errorf("VolumeBindingMode not set for StorageClass %q", scName)
|
||||
@ -772,7 +703,7 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta PredicateMetadata, nodeI
|
||||
return false, nil, fmt.Errorf("PersistentVolumeClaim was not found: %q", pvcName)
|
||||
}
|
||||
|
||||
pv, err := c.pvInfo.GetPersistentVolumeInfo(pvName)
|
||||
pv, err := c.pvLister.Get(pvName)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ import (
|
||||
appslisters "k8s.io/client-go/listers/apps/v1"
|
||||
corelisters "k8s.io/client-go/listers/core/v1"
|
||||
policylisters "k8s.io/client-go/listers/policy/v1beta1"
|
||||
storagelisters "k8s.io/client-go/listers/storage/v1"
|
||||
v1beta1storagelisters "k8s.io/client-go/listers/storage/v1beta1"
|
||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||
@ -46,10 +48,10 @@ type PluginFactoryArgs struct {
|
||||
StatefulSetLister appslisters.StatefulSetLister
|
||||
PDBLister policylisters.PodDisruptionBudgetLister
|
||||
NodeLister schedulerlisters.NodeLister
|
||||
CSINodeInfo predicates.CSINodeInfo
|
||||
PVInfo predicates.PersistentVolumeInfo
|
||||
PVCInfo predicates.PersistentVolumeClaimInfo
|
||||
StorageClassInfo predicates.StorageClassInfo
|
||||
CSINodeLister v1beta1storagelisters.CSINodeLister
|
||||
PVLister corelisters.PersistentVolumeLister
|
||||
PVCLister corelisters.PersistentVolumeClaimLister
|
||||
StorageClassLister storagelisters.StorageClassLister
|
||||
VolumeBinder *volumebinder.VolumeBinder
|
||||
HardPodAffinitySymmetricWeight int32
|
||||
}
|
||||
|
@ -51,40 +51,40 @@ func init() {
|
||||
scheduler.RegisterFitPredicateFactory(
|
||||
predicates.NoVolumeZoneConflictPred,
|
||||
func(args scheduler.PluginFactoryArgs) predicates.FitPredicate {
|
||||
return predicates.NewVolumeZonePredicate(args.PVInfo, args.PVCInfo, args.StorageClassInfo)
|
||||
return predicates.NewVolumeZonePredicate(args.PVLister, args.PVCLister, args.StorageClassLister)
|
||||
},
|
||||
)
|
||||
// Fit is determined by whether or not there would be too many AWS EBS volumes attached to the node
|
||||
scheduler.RegisterFitPredicateFactory(
|
||||
predicates.MaxEBSVolumeCountPred,
|
||||
func(args scheduler.PluginFactoryArgs) predicates.FitPredicate {
|
||||
return predicates.NewMaxPDVolumeCountPredicate(predicates.EBSVolumeFilterType, args.CSINodeInfo, args.StorageClassInfo, args.PVInfo, args.PVCInfo)
|
||||
return predicates.NewMaxPDVolumeCountPredicate(predicates.EBSVolumeFilterType, args.CSINodeLister, args.StorageClassLister, args.PVLister, args.PVCLister)
|
||||
},
|
||||
)
|
||||
// Fit is determined by whether or not there would be too many GCE PD volumes attached to the node
|
||||
scheduler.RegisterFitPredicateFactory(
|
||||
predicates.MaxGCEPDVolumeCountPred,
|
||||
func(args scheduler.PluginFactoryArgs) predicates.FitPredicate {
|
||||
return predicates.NewMaxPDVolumeCountPredicate(predicates.GCEPDVolumeFilterType, args.CSINodeInfo, args.StorageClassInfo, args.PVInfo, args.PVCInfo)
|
||||
return predicates.NewMaxPDVolumeCountPredicate(predicates.GCEPDVolumeFilterType, args.CSINodeLister, args.StorageClassLister, args.PVLister, args.PVCLister)
|
||||
},
|
||||
)
|
||||
// Fit is determined by whether or not there would be too many Azure Disk volumes attached to the node
|
||||
scheduler.RegisterFitPredicateFactory(
|
||||
predicates.MaxAzureDiskVolumeCountPred,
|
||||
func(args scheduler.PluginFactoryArgs) predicates.FitPredicate {
|
||||
return predicates.NewMaxPDVolumeCountPredicate(predicates.AzureDiskVolumeFilterType, args.CSINodeInfo, args.StorageClassInfo, args.PVInfo, args.PVCInfo)
|
||||
return predicates.NewMaxPDVolumeCountPredicate(predicates.AzureDiskVolumeFilterType, args.CSINodeLister, args.StorageClassLister, args.PVLister, args.PVCLister)
|
||||
},
|
||||
)
|
||||
scheduler.RegisterFitPredicateFactory(
|
||||
predicates.MaxCSIVolumeCountPred,
|
||||
func(args scheduler.PluginFactoryArgs) predicates.FitPredicate {
|
||||
return predicates.NewCSIMaxVolumeLimitPredicate(args.CSINodeInfo, args.PVInfo, args.PVCInfo, args.StorageClassInfo)
|
||||
return predicates.NewCSIMaxVolumeLimitPredicate(args.CSINodeLister, args.PVLister, args.PVCLister, args.StorageClassLister)
|
||||
},
|
||||
)
|
||||
scheduler.RegisterFitPredicateFactory(
|
||||
predicates.MaxCinderVolumeCountPred,
|
||||
func(args scheduler.PluginFactoryArgs) predicates.FitPredicate {
|
||||
return predicates.NewMaxPDVolumeCountPredicate(predicates.CinderVolumeFilterType, args.CSINodeInfo, args.StorageClassInfo, args.PVInfo, args.PVCInfo)
|
||||
return predicates.NewMaxPDVolumeCountPredicate(predicates.CinderVolumeFilterType, args.CSINodeLister, args.StorageClassLister, args.PVLister, args.PVCLister)
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -594,10 +594,10 @@ func (c *Configurator) getAlgorithmArgs() (*PluginFactoryArgs, *plugins.ConfigPr
|
||||
StatefulSetLister: c.statefulSetLister,
|
||||
PDBLister: c.pdbLister,
|
||||
NodeLister: c.schedulerCache,
|
||||
CSINodeInfo: &predicates.CachedCSINodeInfo{CSINodeLister: c.csiNodeLister},
|
||||
PVInfo: &predicates.CachedPersistentVolumeInfo{PersistentVolumeLister: c.pVLister},
|
||||
PVCInfo: &predicates.CachedPersistentVolumeClaimInfo{PersistentVolumeClaimLister: c.pVCLister},
|
||||
StorageClassInfo: &predicates.CachedStorageClassInfo{StorageClassLister: c.storageClassLister},
|
||||
CSINodeLister: c.csiNodeLister,
|
||||
PVLister: c.pVLister,
|
||||
PVCLister: c.pVCLister,
|
||||
StorageClassLister: c.storageClassLister,
|
||||
VolumeBinder: c.volumeBinder,
|
||||
HardPodAffinitySymmetricWeight: c.hardPodAffinitySymmetricWeight,
|
||||
}, &plugins.ConfigProducerArgs{}
|
||||
|
@ -52,20 +52,12 @@ func (pl *AzureDiskLimits) Filter(ctx context.Context, _ *framework.CycleState,
|
||||
// NewAzureDisk returns function that initializes a new plugin and returns it.
|
||||
func NewAzureDisk(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
|
||||
informerFactory := handle.SharedInformerFactory()
|
||||
csiNodeInfo := &predicates.CachedCSINodeInfo{
|
||||
CSINodeLister: informerFactory.Storage().V1beta1().CSINodes().Lister(),
|
||||
}
|
||||
pvInfo := &predicates.CachedPersistentVolumeInfo{
|
||||
PersistentVolumeLister: informerFactory.Core().V1().PersistentVolumes().Lister(),
|
||||
}
|
||||
pvcInfo := &predicates.CachedPersistentVolumeClaimInfo{
|
||||
PersistentVolumeClaimLister: informerFactory.Core().V1().PersistentVolumeClaims().Lister(),
|
||||
}
|
||||
classInfo := &predicates.CachedStorageClassInfo{
|
||||
StorageClassLister: informerFactory.Storage().V1().StorageClasses().Lister(),
|
||||
}
|
||||
csiNodeLister := informerFactory.Storage().V1beta1().CSINodes().Lister()
|
||||
pvLister := informerFactory.Core().V1().PersistentVolumes().Lister()
|
||||
pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister()
|
||||
scLister := informerFactory.Storage().V1().StorageClasses().Lister()
|
||||
|
||||
return &AzureDiskLimits{
|
||||
predicate: predicates.NewMaxPDVolumeCountPredicate(predicates.AzureDiskVolumeFilterType, csiNodeInfo, classInfo, pvInfo, pvcInfo),
|
||||
predicate: predicates.NewMaxPDVolumeCountPredicate(predicates.AzureDiskVolumeFilterType, csiNodeLister, scLister, pvLister, pvcLister),
|
||||
}, nil
|
||||
}
|
||||
|
@ -52,20 +52,11 @@ func (pl *CinderLimits) Filter(ctx context.Context, _ *framework.CycleState, pod
|
||||
// NewCinder returns function that initializes a new plugin and returns it.
|
||||
func NewCinder(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
|
||||
informerFactory := handle.SharedInformerFactory()
|
||||
csiNodeInfo := &predicates.CachedCSINodeInfo{
|
||||
CSINodeLister: informerFactory.Storage().V1beta1().CSINodes().Lister(),
|
||||
}
|
||||
pvInfo := &predicates.CachedPersistentVolumeInfo{
|
||||
PersistentVolumeLister: informerFactory.Core().V1().PersistentVolumes().Lister(),
|
||||
}
|
||||
pvcInfo := &predicates.CachedPersistentVolumeClaimInfo{
|
||||
PersistentVolumeClaimLister: informerFactory.Core().V1().PersistentVolumeClaims().Lister(),
|
||||
}
|
||||
classInfo := &predicates.CachedStorageClassInfo{
|
||||
StorageClassLister: informerFactory.Storage().V1().StorageClasses().Lister(),
|
||||
}
|
||||
|
||||
csiNodeLister := informerFactory.Storage().V1beta1().CSINodes().Lister()
|
||||
pvLister := informerFactory.Core().V1().PersistentVolumes().Lister()
|
||||
pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister()
|
||||
scLister := informerFactory.Storage().V1().StorageClasses().Lister()
|
||||
return &CinderLimits{
|
||||
predicate: predicates.NewMaxPDVolumeCountPredicate(predicates.CinderVolumeFilterType, csiNodeInfo, classInfo, pvInfo, pvcInfo),
|
||||
predicate: predicates.NewMaxPDVolumeCountPredicate(predicates.CinderVolumeFilterType, csiNodeLister, scLister, pvLister, pvcLister),
|
||||
}, nil
|
||||
}
|
||||
|
@ -52,20 +52,12 @@ func (pl *CSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod *v
|
||||
// NewCSI initializes a new plugin and returns it.
|
||||
func NewCSI(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
|
||||
informerFactory := handle.SharedInformerFactory()
|
||||
csiNodeInfo := &predicates.CachedCSINodeInfo{
|
||||
CSINodeLister: informerFactory.Storage().V1beta1().CSINodes().Lister(),
|
||||
}
|
||||
pvInfo := &predicates.CachedPersistentVolumeInfo{
|
||||
PersistentVolumeLister: informerFactory.Core().V1().PersistentVolumes().Lister(),
|
||||
}
|
||||
pvcInfo := &predicates.CachedPersistentVolumeClaimInfo{
|
||||
PersistentVolumeClaimLister: informerFactory.Core().V1().PersistentVolumeClaims().Lister(),
|
||||
}
|
||||
classInfo := &predicates.CachedStorageClassInfo{
|
||||
StorageClassLister: informerFactory.Storage().V1().StorageClasses().Lister(),
|
||||
}
|
||||
csiNodeLister := informerFactory.Storage().V1beta1().CSINodes().Lister()
|
||||
pvLister := informerFactory.Core().V1().PersistentVolumes().Lister()
|
||||
pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister()
|
||||
scLister := informerFactory.Storage().V1().StorageClasses().Lister()
|
||||
|
||||
return &CSILimits{
|
||||
predicate: predicates.NewCSIMaxVolumeLimitPredicate(csiNodeInfo, pvInfo, pvcInfo, classInfo),
|
||||
predicate: predicates.NewCSIMaxVolumeLimitPredicate(csiNodeLister, pvLister, pvcLister, scLister),
|
||||
}, nil
|
||||
}
|
||||
|
@ -52,20 +52,12 @@ func (pl *EBSLimits) Filter(ctx context.Context, _ *framework.CycleState, pod *v
|
||||
// NewEBS returns function that initializes a new plugin and returns it.
|
||||
func NewEBS(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
|
||||
informerFactory := handle.SharedInformerFactory()
|
||||
csiNodeInfo := &predicates.CachedCSINodeInfo{
|
||||
CSINodeLister: informerFactory.Storage().V1beta1().CSINodes().Lister(),
|
||||
}
|
||||
pvInfo := &predicates.CachedPersistentVolumeInfo{
|
||||
PersistentVolumeLister: informerFactory.Core().V1().PersistentVolumes().Lister(),
|
||||
}
|
||||
pvcInfo := &predicates.CachedPersistentVolumeClaimInfo{
|
||||
PersistentVolumeClaimLister: informerFactory.Core().V1().PersistentVolumeClaims().Lister(),
|
||||
}
|
||||
classInfo := &predicates.CachedStorageClassInfo{
|
||||
StorageClassLister: informerFactory.Storage().V1().StorageClasses().Lister(),
|
||||
}
|
||||
csiNodeLister := informerFactory.Storage().V1beta1().CSINodes().Lister()
|
||||
pvLister := informerFactory.Core().V1().PersistentVolumes().Lister()
|
||||
pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister()
|
||||
scLister := informerFactory.Storage().V1().StorageClasses().Lister()
|
||||
|
||||
return &EBSLimits{
|
||||
predicate: predicates.NewMaxPDVolumeCountPredicate(predicates.EBSVolumeFilterType, csiNodeInfo, classInfo, pvInfo, pvcInfo),
|
||||
predicate: predicates.NewMaxPDVolumeCountPredicate(predicates.EBSVolumeFilterType, csiNodeLister, scLister, pvLister, pvcLister),
|
||||
}, nil
|
||||
}
|
||||
|
@ -52,20 +52,12 @@ func (pl *GCEPDLimits) Filter(ctx context.Context, _ *framework.CycleState, pod
|
||||
// NewGCEPD returns function that initializes a new plugin and returns it.
|
||||
func NewGCEPD(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
|
||||
informerFactory := handle.SharedInformerFactory()
|
||||
csiNodeInfo := &predicates.CachedCSINodeInfo{
|
||||
CSINodeLister: informerFactory.Storage().V1beta1().CSINodes().Lister(),
|
||||
}
|
||||
pvInfo := &predicates.CachedPersistentVolumeInfo{
|
||||
PersistentVolumeLister: informerFactory.Core().V1().PersistentVolumes().Lister(),
|
||||
}
|
||||
pvcInfo := &predicates.CachedPersistentVolumeClaimInfo{
|
||||
PersistentVolumeClaimLister: informerFactory.Core().V1().PersistentVolumeClaims().Lister(),
|
||||
}
|
||||
classInfo := &predicates.CachedStorageClassInfo{
|
||||
StorageClassLister: informerFactory.Storage().V1().StorageClasses().Lister(),
|
||||
}
|
||||
csiNodeLister := informerFactory.Storage().V1beta1().CSINodes().Lister()
|
||||
pvLister := informerFactory.Core().V1().PersistentVolumes().Lister()
|
||||
pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister()
|
||||
scLister := informerFactory.Storage().V1().StorageClasses().Lister()
|
||||
|
||||
return &GCEPDLimits{
|
||||
predicate: predicates.NewMaxPDVolumeCountPredicate(predicates.GCEPDVolumeFilterType, csiNodeInfo, classInfo, pvInfo, pvcInfo),
|
||||
predicate: predicates.NewMaxPDVolumeCountPredicate(predicates.GCEPDVolumeFilterType, csiNodeLister, scLister, pvLister, pvcLister),
|
||||
}, nil
|
||||
}
|
||||
|
@ -52,16 +52,10 @@ 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) {
|
||||
informerFactory := handle.SharedInformerFactory()
|
||||
pvInfo := &predicates.CachedPersistentVolumeInfo{
|
||||
PersistentVolumeLister: informerFactory.Core().V1().PersistentVolumes().Lister(),
|
||||
}
|
||||
pvcInfo := &predicates.CachedPersistentVolumeClaimInfo{
|
||||
PersistentVolumeClaimLister: informerFactory.Core().V1().PersistentVolumeClaims().Lister(),
|
||||
}
|
||||
classInfo := &predicates.CachedStorageClassInfo{
|
||||
StorageClassLister: informerFactory.Storage().V1().StorageClasses().Lister(),
|
||||
}
|
||||
pvLister := informerFactory.Core().V1().PersistentVolumes().Lister()
|
||||
pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister()
|
||||
scLister := informerFactory.Storage().V1().StorageClasses().Lister()
|
||||
return &VolumeZone{
|
||||
predicate: predicates.NewVolumeZonePredicate(pvInfo, pvcInfo, classInfo),
|
||||
predicate: predicates.NewVolumeZonePredicate(pvLister, pvcLister, scLister),
|
||||
}, nil
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ go_library(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/apps/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/storage/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/storage/v1beta1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -27,6 +27,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
appslisters "k8s.io/client-go/listers/apps/v1"
|
||||
corelisters "k8s.io/client-go/listers/core/v1"
|
||||
storagelisters "k8s.io/client-go/listers/storage/v1"
|
||||
v1beta1storagelisters "k8s.io/client-go/listers/storage/v1beta1"
|
||||
schedulerlisters "k8s.io/kubernetes/pkg/scheduler/listers"
|
||||
)
|
||||
|
||||
@ -205,7 +207,7 @@ type PersistentVolumeClaimLister []*v1.PersistentVolumeClaim
|
||||
|
||||
var _ corelisters.PersistentVolumeClaimLister = PersistentVolumeClaimLister{}
|
||||
|
||||
// List returns not implemented error.
|
||||
// List lists all PersistentVolumeClaims in the indexer.
|
||||
func (f PersistentVolumeClaimLister) List(selector labels.Selector) (ret []*v1.PersistentVolumeClaim, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
@ -240,6 +242,8 @@ func (f persistentVolumeClaimNamespaceLister) List(selector labels.Selector) (re
|
||||
// PersistentVolumeClaimInfo declares a []v1.PersistentVolumeClaim type for testing.
|
||||
type PersistentVolumeClaimInfo []v1.PersistentVolumeClaim
|
||||
|
||||
var _ corelisters.PersistentVolumeClaimLister = PersistentVolumeClaimInfo{}
|
||||
|
||||
// GetPersistentVolumeClaimInfo gets PVC matching the namespace and PVC ID.
|
||||
func (pvcs PersistentVolumeClaimInfo) GetPersistentVolumeClaimInfo(namespace string, pvcID string) (*v1.PersistentVolumeClaim, error) {
|
||||
for _, pvc := range pvcs {
|
||||
@ -250,6 +254,23 @@ func (pvcs PersistentVolumeClaimInfo) GetPersistentVolumeClaimInfo(namespace str
|
||||
return nil, fmt.Errorf("Unable to find persistent volume claim: %s/%s", namespace, pvcID)
|
||||
}
|
||||
|
||||
// List gets PVC matching the namespace and PVC ID.
|
||||
func (pvcs PersistentVolumeClaimInfo) List(selector labels.Selector) (ret []*v1.PersistentVolumeClaim, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
// PersistentVolumeClaims returns a fake PersistentVolumeClaimLister object.
|
||||
func (pvcs PersistentVolumeClaimInfo) PersistentVolumeClaims(namespace string) corelisters.PersistentVolumeClaimNamespaceLister {
|
||||
ps := make([]*v1.PersistentVolumeClaim, len(pvcs))
|
||||
for i := range pvcs {
|
||||
ps[i] = &pvcs[i]
|
||||
}
|
||||
return &persistentVolumeClaimNamespaceLister{
|
||||
pvcs: ps,
|
||||
namespace: namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// NodeLister declares a *v1.Node type for testing.
|
||||
type NodeLister []*v1.Node
|
||||
|
||||
@ -263,6 +284,8 @@ func (nodes NodeLister) GetNodeInfo(nodeName string) (*v1.Node, error) {
|
||||
return nil, fmt.Errorf("Unable to find node: %s", nodeName)
|
||||
}
|
||||
|
||||
var _ v1beta1storagelisters.CSINodeLister = CSINodeInfo{}
|
||||
|
||||
// CSINodeInfo declares a storagev1beta1.CSINode type for testing.
|
||||
type CSINodeInfo storagev1beta1.CSINode
|
||||
|
||||
@ -272,9 +295,22 @@ func (n CSINodeInfo) GetCSINodeInfo(name string) (*storagev1beta1.CSINode, error
|
||||
return &csiNode, nil
|
||||
}
|
||||
|
||||
// Get returns a fake CSINode object.
|
||||
func (n CSINodeInfo) Get(name string) (*storagev1beta1.CSINode, error) {
|
||||
csiNode := storagev1beta1.CSINode(n)
|
||||
return &csiNode, nil
|
||||
}
|
||||
|
||||
// List lists all CSINodes in the indexer.
|
||||
func (n CSINodeInfo) List(selector labels.Selector) (ret []*storagev1beta1.CSINode, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
// PersistentVolumeInfo declares a []v1.PersistentVolume type for testing.
|
||||
type PersistentVolumeInfo []v1.PersistentVolume
|
||||
|
||||
var _ corelisters.PersistentVolumeLister = PersistentVolumeInfo{}
|
||||
|
||||
// GetPersistentVolumeInfo returns a fake PV object in the fake PVs by PV ID.
|
||||
func (pvs PersistentVolumeInfo) GetPersistentVolumeInfo(pvID string) (*v1.PersistentVolume, error) {
|
||||
for _, pv := range pvs {
|
||||
@ -285,9 +321,26 @@ func (pvs PersistentVolumeInfo) GetPersistentVolumeInfo(pvID string) (*v1.Persis
|
||||
return nil, fmt.Errorf("Unable to find persistent volume: %s", pvID)
|
||||
}
|
||||
|
||||
// Get returns a fake PV object in the fake PVs by PV ID.
|
||||
func (pvs PersistentVolumeInfo) Get(pvID string) (*v1.PersistentVolume, error) {
|
||||
for _, pv := range pvs {
|
||||
if pv.Name == pvID {
|
||||
return &pv, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("Unable to find persistent volume: %s", pvID)
|
||||
}
|
||||
|
||||
// List lists all PersistentVolumes in the indexer.
|
||||
func (pvs PersistentVolumeInfo) List(selector labels.Selector) ([]*v1.PersistentVolume, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
// StorageClassInfo declares a []storagev1.StorageClass type for testing.
|
||||
type StorageClassInfo []storagev1.StorageClass
|
||||
|
||||
var _ storagelisters.StorageClassLister = StorageClassInfo{}
|
||||
|
||||
// GetStorageClassInfo returns a fake storage class object in the fake storage classes by name.
|
||||
func (classes StorageClassInfo) GetStorageClassInfo(name string) (*storagev1.StorageClass, error) {
|
||||
for _, sc := range classes {
|
||||
@ -297,3 +350,18 @@ func (classes StorageClassInfo) GetStorageClassInfo(name string) (*storagev1.Sto
|
||||
}
|
||||
return nil, fmt.Errorf("Unable to find storage class: %s", name)
|
||||
}
|
||||
|
||||
// Get returns a fake storage class object in the fake storage classes by name.
|
||||
func (classes StorageClassInfo) Get(name string) (*storagev1.StorageClass, error) {
|
||||
for _, sc := range classes {
|
||||
if sc.Name == name {
|
||||
return &sc, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("Unable to find storage class: %s", name)
|
||||
}
|
||||
|
||||
// List lists all StorageClass in the indexer.
|
||||
func (classes StorageClassInfo) List(selector labels.Selector) ([]*storagev1.StorageClass, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user