@@ -682,18 +682,21 @@ type SidecarsStatus struct {
682682}
683683
684684// GetSidecarsStatus returns the SidecarsStatus for the given pod 
685+ // We assume the worst: if we are unable to determine the status of all containers we make defensive assumptions that 
686+ // there are sidecars, they are not ready, and that there are non-sidecars waiting. This is to prevent starting non- 
687+ // -sidecars accidentally. 
685688func  GetSidecarsStatus (pod  * v1.Pod ) SidecarsStatus  {
686689	var  containerStatusesCopy  []v1.ContainerStatus 
687690	if  pod  ==  nil  {
688- 		klog .Infof ("Pod was nil, returning empty  sidecar status" )
689- 		return  SidecarsStatus {}
691+ 		klog .Infof ("Pod was nil, returning sidecar status that prevents progress " )
692+ 		return  SidecarsStatus {SidecarsPresent :  true ,  SidecarsReady :  false ,  ContainersWaiting :  true }
690693	}
691694	if  pod .Spec .Containers  ==  nil  {
692- 		klog .Infof ("Pod Containers was nil, returning empty  sidecar status"  )
693- 		return  SidecarsStatus {}
695+ 		klog .Infof ("Pod %s:  Containers was nil, returning sidecar status that prevents progress"  ,  format . Pod ( pod ) )
696+ 		return  SidecarsStatus {SidecarsPresent :  true ,  SidecarsReady :  false ,  ContainersWaiting :  true }
694697	}
695698	if  pod .Status .ContainerStatuses  ==  nil  {
696- 		klog .Infof ("Pod Container status  was nil, doing best effort using spec" )
699+ 		klog .Infof ("Pod %s: ContainerStatuses  was nil, doing best effort using spec" ,  format . Pod ( pod ) )
697700	} else  {
698701		// Make a copy of ContainerStatuses to avoid having the carpet pulled from under our feet 
699702		containerStatusesCopy  =  make ([]v1.ContainerStatus , len (pod .Status .ContainerStatuses ))
@@ -726,9 +729,14 @@ func GetSidecarsStatus(pod *v1.Pod) SidecarsStatus {
726729				break 
727730			}
728731		}
729- 		if  ! foundStatus  &&  isSidecar  {
730- 			klog .Infof ("Pod %s: %s (sidecar): status not found, assuming not ready" , format .Pod (pod ), container .Name )
731- 			sidecarsStatus .SidecarsReady  =  false 
732+ 		if  ! foundStatus  {
733+ 			if  isSidecar  {
734+ 				klog .Infof ("Pod %s: %s (sidecar): status not found, assuming not ready" , format .Pod (pod ), container .Name )
735+ 				sidecarsStatus .SidecarsReady  =  false 
736+ 			} else  {
737+ 				klog .Infof ("Pod: %s: %s (non-sidecar): status not found, assuming waiting" , format .Pod (pod ), container .Name )
738+ 				sidecarsStatus .ContainersWaiting  =  true 
739+ 			}
732740		}
733741	}
734742	return  sidecarsStatus 
0 commit comments