Skip to content

Commit

Permalink
Fix CA breaking after vendor update to v1.25.0-alpha.0 by supporting …
Browse files Browse the repository at this point in the history
…StorageInfoLister
  • Loading branch information
jayantjain93 committed Jul 7, 2022
1 parent 9dc72fe commit f508ee1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
11 changes: 11 additions & 0 deletions cluster-autoscaler/simulator/basic_cluster_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,18 @@ func (snapshot *BasicClusterSnapshot) Clear() {
// implementation of SharedLister interface

type basicClusterSnapshotNodeLister BasicClusterSnapshot
type basicClusterSnapshotStorageLister BasicClusterSnapshot

// NodeInfos exposes snapshot as NodeInfoLister.
func (snapshot *BasicClusterSnapshot) NodeInfos() schedulerframework.NodeInfoLister {
return (*basicClusterSnapshotNodeLister)(snapshot)
}

// StorageInfos exposes snapshot as StorageInfoLister.
func (snapshot *BasicClusterSnapshot) StorageInfos() schedulerframework.StorageInfoLister {
return (*basicClusterSnapshotStorageLister)(snapshot)
}

// List returns the list of nodes in the snapshot.
func (snapshot *basicClusterSnapshotNodeLister) List() ([]*schedulerframework.NodeInfo, error) {
return (*BasicClusterSnapshot)(snapshot).getInternalData().listNodeInfos()
Expand All @@ -252,3 +258,8 @@ func (snapshot *basicClusterSnapshotNodeLister) HavePodsWithRequiredAntiAffinity
func (snapshot *basicClusterSnapshotNodeLister) Get(nodeName string) (*schedulerframework.NodeInfo, error) {
return (*BasicClusterSnapshot)(snapshot).getInternalData().getNodeInfo(nodeName)
}

// Returns the IsPVCUsedByPods in a given key.
func (snapshot *basicClusterSnapshotStorageLister) IsPVCUsedByPods(key string) bool {
return false
}
16 changes: 15 additions & 1 deletion cluster-autoscaler/simulator/delegating_shared_lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (lister *DelegatingSchedulerSharedLister) NodeInfos() schedulerframework.No
return lister.delegate.NodeInfos()
}

func (lister *DelegatingSchedulerSharedLister) StorageInfos() schedulerframework.StorageInfoLister {
return lister.delegate.StorageInfos()
}

// UpdateDelegate updates the delegate
func (lister *DelegatingSchedulerSharedLister) UpdateDelegate(delegate schedulerframework.SharedLister) {
lister.delegate = delegate
Expand All @@ -52,6 +56,7 @@ func (lister *DelegatingSchedulerSharedLister) ResetDelegate() {

type unsetSharedLister struct{}
type unsetNodeInfoLister unsetSharedLister
type unsetStorageInfoLister unsetSharedLister

// List always returns an error
func (lister *unsetNodeInfoLister) List() ([]*schedulerframework.NodeInfo, error) {
Expand All @@ -73,9 +78,18 @@ func (lister *unsetNodeInfoLister) Get(nodeName string) (*schedulerframework.Nod
return nil, fmt.Errorf("lister not set in delegate")
}

// Pods returns a fake NodeInfoLister which always returns an error
func (lister *unsetStorageInfoLister) IsPVCUsedByPods(key string) bool {
return false
}

// NodeInfos: Pods returns a fake NodeInfoLister which always returns an error
func (lister *unsetSharedLister) NodeInfos() schedulerframework.NodeInfoLister {
return (*unsetNodeInfoLister)(lister)
}

// StorageInfos: Pods returns a fake StorageInfoLister which always returns an error
func (lister *unsetSharedLister) StorageInfos() schedulerframework.StorageInfoLister {
return (*unsetStorageInfoLister)(lister)
}

var unsetSharedListerSingleton *unsetSharedLister
14 changes: 13 additions & 1 deletion cluster-autoscaler/simulator/delta_cluster_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
// DeltaClusterSnapshot is an implementation of ClusterSnapshot optimized for typical Cluster Autoscaler usage - (fork, add stuff, revert), repeated many times per loop.
//
// Complexity of some notable operations:
//
// fork - O(1)
// revert - O(1)
// commit - O(n)
Expand All @@ -34,16 +35,17 @@ import (
// list node infos - O(n), cached
//
// Watch out for:
//
// node deletions, pod additions & deletions - invalidates cache of current snapshot
// (when forked affects delta, but not base.)
// pod affinity - causes scheduler framework to list pods with non-empty selector,
// so basic caching doesn't help.
//
type DeltaClusterSnapshot struct {
data *internalDeltaSnapshotData
}

type deltaSnapshotNodeLister DeltaClusterSnapshot
type deltaSnapshotStorageLister DeltaClusterSnapshot

type internalDeltaSnapshotData struct {
baseData *internalDeltaSnapshotData
Expand Down Expand Up @@ -349,6 +351,11 @@ func (snapshot *deltaSnapshotNodeLister) Get(nodeName string) (*schedulerframewo
return (*DeltaClusterSnapshot)(snapshot).getNodeInfo(nodeName)
}

// IsPVCUsedByPods returns if PVC is used by pods
func (snapshot *deltaSnapshotStorageLister) IsPVCUsedByPods(key string) bool {
return false
}

func (snapshot *DeltaClusterSnapshot) getNodeInfo(nodeName string) (*schedulerframework.NodeInfo, error) {
data := snapshot.data
node, found := data.getNodeInfo(nodeName)
Expand All @@ -363,6 +370,11 @@ func (snapshot *DeltaClusterSnapshot) NodeInfos() schedulerframework.NodeInfoLis
return (*deltaSnapshotNodeLister)(snapshot)
}

// StorageInfos returns storage lister
func (snapshot *DeltaClusterSnapshot) StorageInfos() schedulerframework.StorageInfoLister {
return (*deltaSnapshotStorageLister)(snapshot)
}

// NewDeltaClusterSnapshot creates instances of DeltaClusterSnapshot.
func NewDeltaClusterSnapshot() *DeltaClusterSnapshot {
snapshot := &DeltaClusterSnapshot{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func NewSchedulerBasedPredicateChecker(kubeClient kube_client.Interface, stop <-
framework, err := schedulerframeworkruntime.NewFramework(
scheduler_plugins.NewInTreeRegistry(),
&config.Profiles[0],
stop,
schedulerframeworkruntime.WithInformerFactory(informerFactory),
schedulerframeworkruntime.WithSnapshotSharedLister(sharedLister),
)
Expand Down

0 comments on commit f508ee1

Please sign in to comment.