mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Update CPUmanager containerMap to allow removal by containerRef
This commit is contained in:
		@@ -39,11 +39,19 @@ func (cm ContainerMap) Add(podUID, containerName, containerID string) {
 | 
			
		||||
	}{podUID, containerName}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Remove removes a mapping of (containerID)->(*v1.Pod, *.v1.Container) from the ContainerMap
 | 
			
		||||
func (cm ContainerMap) Remove(containerID string) {
 | 
			
		||||
// RemoveByContainerID removes a mapping of (containerID)->(podUID, containerName) from the ContainerMap
 | 
			
		||||
func (cm ContainerMap) RemoveByContainerID(containerID string) {
 | 
			
		||||
	delete(cm, containerID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RemoveByContainerRef removes a mapping of (containerID)->(podUID, containerName) from the ContainerMap
 | 
			
		||||
func (cm ContainerMap) RemoveByContainerRef(podUID, containerName string) {
 | 
			
		||||
	containerID, err := cm.GetContainerID(podUID, containerName)
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		cm.RemoveByContainerID(containerID)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetContainerID retrieves a ContainerID from the ContainerMap
 | 
			
		||||
func (cm ContainerMap) GetContainerID(podUID, containerName string) (string, error) {
 | 
			
		||||
	for key, val := range cm {
 | 
			
		||||
 
 | 
			
		||||
@@ -63,11 +63,19 @@ func TestContainerMap(t *testing.T) {
 | 
			
		||||
		// Remove all entries from the containerMap, checking proper removal of
 | 
			
		||||
		// each along the way.
 | 
			
		||||
		for i := range tc.containerNames {
 | 
			
		||||
			cm.Remove(tc.containerIDs[i])
 | 
			
		||||
			cm.RemoveByContainerID(tc.containerIDs[i])
 | 
			
		||||
			containerID, err := cm.GetContainerID(tc.podUID, tc.containerNames[i])
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				t.Errorf("unexpected retrieval of containerID after removal: %v", containerID)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			cm.Add(tc.podUID, tc.containerNames[i], tc.containerIDs[i])
 | 
			
		||||
 | 
			
		||||
			cm.RemoveByContainerRef(tc.podUID, tc.containerNames[i])
 | 
			
		||||
			podUID, containerName, err := cm.GetContainerRef(tc.containerIDs[i])
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				t.Errorf("unexpected retrieval of container reference after removal: (%v, %v)", podUID, containerName)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Verify containerMap now empty.
 | 
			
		||||
 
 | 
			
		||||
@@ -243,7 +243,7 @@ func (p *staticPolicy) RemoveContainer(s state.State, containerID string) (rerr
 | 
			
		||||
	// remove containerID from the containerMap.
 | 
			
		||||
	defer func() {
 | 
			
		||||
		if rerr == nil {
 | 
			
		||||
			p.containerMap.Remove(containerID)
 | 
			
		||||
			p.containerMap.RemoveByContainerID(containerID)
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user