in internal/workload/podspec_updates.go [521:579]
func (s *updateState) update(wl *PodWorkload, matches []*cloudsqlapi.AuthProxyWorkload) error {
s.initState(matches)
podSpec := wl.PodSpec()
allContainers := append(podSpec.Containers, podSpec.InitContainers...)
for _, container := range allContainers {
if !strings.HasPrefix(container.Name, ContainerPrefix) {
for _, port := range container.Ports {
s.addWorkloadPort(port.ContainerPort)
}
}
}
// Copy the existing pod annotation map
ann := map[string]string{}
for k, v := range wl.PodTemplateAnnotations() {
ann[k] = v
}
// add all new containers and update existing containers
for i := range matches {
inst := matches[i]
newContainer := corev1.Container{}
s.updateContainer(inst, &newContainer)
if s.updater.useSidecar {
podSpec.InitContainers = append([]corev1.Container{newContainer}, podSpec.InitContainers...)
} else {
podSpec.Containers = append(podSpec.Containers, newContainer)
}
// Add pod annotation for each instance
k, v := s.updater.PodAnnotation(inst)
ann[k] = v
}
// Add the envvar containing the proxy quit urls to the workloads
s.addQuitEnvVar()
if len(ann) != 0 {
wl.SetPodTemplateAnnotations(ann)
}
s.processContainers(&podSpec.Containers)
s.processContainers(&podSpec.InitContainers)
s.applyVolumes(&podSpec)
// only return ConfigError if there were reported
// errors during processing.
if len(s.err.details) > 0 {
return &s.err
}
wl.SetPodSpec(podSpec)
return nil
}