Implement HavePodsWithRequiredAntiAffinityList for all snapshots

This is required after updating dependencies because of changes in
scheduler code.
This commit is contained in:
Jakub Tużnik 2020-09-17 14:39:53 +02:00
parent a64c8d6799
commit 33ea9a349b
3 changed files with 43 additions and 2 deletions

View File

@ -53,6 +53,17 @@ func (data *internalBasicSnapshotData) listNodeInfosThatHavePodsWithAffinityList
return havePodsWithAffinityList, nil
}
func (data *internalBasicSnapshotData) listNodeInfosThatHavePodsWithRequiredAntiAffinityList() ([]*schedulerframework.NodeInfo, error) {
havePodsWithRequiredAntiAffinityList := make([]*schedulerframework.NodeInfo, 0, len(data.nodeInfoMap))
for _, v := range data.nodeInfoMap {
if len(v.PodsWithRequiredAntiAffinity) > 0 {
havePodsWithRequiredAntiAffinityList = append(havePodsWithRequiredAntiAffinityList, v)
}
}
return havePodsWithRequiredAntiAffinityList, nil
}
func (data *internalBasicSnapshotData) getNodeInfo(nodeName string) (*schedulerframework.NodeInfo, error) {
if v, ok := data.nodeInfoMap[nodeName]; ok {
return v, nil
@ -235,6 +246,11 @@ func (snapshot *basicClusterSnapshotNodeLister) HavePodsWithAffinityList() ([]*s
return (*BasicClusterSnapshot)(snapshot).getInternalData().listNodeInfosThatHavePodsWithAffinityList()
}
// HavePodsWithRequiredAntiAffinityList returns the list of NodeInfos of nodes with pods with required anti-affinity terms.
func (snapshot *basicClusterSnapshotNodeLister) HavePodsWithRequiredAntiAffinityList() ([]*schedulerframework.NodeInfo, error) {
return (*BasicClusterSnapshot)(snapshot).getInternalData().listNodeInfosThatHavePodsWithRequiredAntiAffinityList()
}
// Returns the NodeInfo of the given node name.
func (snapshot *basicClusterSnapshotNodeLister) Get(nodeName string) (*schedulerframework.NodeInfo, error) {
return (*BasicClusterSnapshot)(snapshot).getInternalData().getNodeInfo(nodeName)

View File

@ -62,6 +62,11 @@ func (lister *unsetNodeInfoLister) HavePodsWithAffinityList() ([]*schedulerframe
return nil, fmt.Errorf("lister not set in delegate")
}
// HavePodsWithRequiredAntiAffinityList always returns an error.
func (lister *unsetNodeInfoLister) HavePodsWithRequiredAntiAffinityList() ([]*schedulerframework.NodeInfo, error) {
return nil, fmt.Errorf("lister not set in delegate")
}
// Get always returns an error
func (lister *unsetNodeInfoLister) Get(nodeName string) (*schedulerframework.NodeInfo, error) {
return nil, fmt.Errorf("lister not set in delegate")

View File

@ -54,6 +54,7 @@ type internalDeltaSnapshotData struct {
nodeInfoList []*schedulerframework.NodeInfo
havePodsWithAffinity []*schedulerframework.NodeInfo
havePodsWithRequiredAntiAffinity []*schedulerframework.NodeInfo
}
func newInternalDeltaSnapshotData() *internalDeltaSnapshotData {
@ -178,6 +179,7 @@ func (data *internalDeltaSnapshotData) clearCaches() {
func (data *internalDeltaSnapshotData) clearPodCaches() {
data.havePodsWithAffinity = nil
data.havePodsWithRequiredAntiAffinity = nil
}
func (data *internalDeltaSnapshotData) removeNode(nodeName string) error {
@ -326,6 +328,24 @@ func (snapshot *deltaSnapshotNodeLister) HavePodsWithAffinityList() ([]*schedule
return data.havePodsWithAffinity, nil
}
// HavePodsWithRequiredAntiAffinityList returns the list of NodeInfos of nodes with pods with required anti-affinity terms.
func (snapshot *deltaSnapshotNodeLister) HavePodsWithRequiredAntiAffinityList() ([]*schedulerframework.NodeInfo, error) {
data := snapshot.data
if data.havePodsWithRequiredAntiAffinity != nil {
return data.havePodsWithRequiredAntiAffinity, nil
}
nodeInfoList := snapshot.data.getNodeInfoList()
havePodsWithRequiredAntiAffinityList := make([]*schedulerframework.NodeInfo, 0, len(nodeInfoList))
for _, node := range nodeInfoList {
if len(node.PodsWithRequiredAntiAffinity) > 0 {
havePodsWithRequiredAntiAffinityList = append(havePodsWithRequiredAntiAffinityList, node)
}
}
data.havePodsWithRequiredAntiAffinity = havePodsWithRequiredAntiAffinityList
return data.havePodsWithRequiredAntiAffinity, nil
}
// Get returns node info by node name.
func (snapshot *deltaSnapshotNodeLister) Get(nodeName string) (*schedulerframework.NodeInfo, error) {
return (*DeltaClusterSnapshot)(snapshot).getNodeInfo(nodeName)