in internal/workload/podspec_updates.go [221:262]
func (u *Updater) CheckWorkloadContainers(wl *PodWorkload, matches []*cloudsqlapi.AuthProxyWorkload) error {
// Find the names of all AuthProxyWorkload resources that should have a
// container on this pod, but there is no container.
var missing []string
for _, p := range matches {
wantName := ContainerName(p)
var found bool
podSpec := wl.PodSpec()
allContainers := append(podSpec.Containers, podSpec.InitContainers...)
for _, c := range allContainers {
if c.Name == wantName {
found = true
}
}
if !found {
missing = append(missing, p.Name)
break
}
}
// If no containers are missing, then there is no error, return nil.
if len(missing) == 0 {
return nil
}
missingSidecars := strings.Join(missing, ", ")
// Some proxy containers are missing. Are the remaining pod containers failing?
for _, cs := range wl.Pod.Status.ContainerStatuses {
if cs.State.Terminated != nil && cs.State.Terminated.Reason == "Error" {
return fmt.Errorf("pod is in an error state and missing sidecar containers %v", missingSidecars)
}
if cs.State.Waiting != nil && cs.State.Waiting.Reason == "CrashLoopBackOff" {
return fmt.Errorf("pod is in a CrashLoopBackOff state and missing sidecar containers %v", missingSidecars)
}
}
// Pod's other containers are not in an error state. Operator should not
// interrupt running containers.
return nil
}