| 293 | } |
| 294 | |
| 295 | func mergePodAdditions(toMerge []v1alpha1.PodAdditions) (*v1alpha1.PodAdditions, error) { |
| 296 | podAdditions := &v1alpha1.PodAdditions{} |
| 297 | |
| 298 | // "Set"s to store k8s object names and detect duplicates |
| 299 | containerNames := map[string]bool{} |
| 300 | initContainerNames := map[string]bool{} |
| 301 | volumeNames := map[string]bool{} |
| 302 | volumeMountNames := map[string]bool{} |
| 303 | pullSecretNames := map[string]bool{} |
| 304 | for _, additions := range toMerge { |
| 305 | for annotKey, annotVal := range additions.Annotations { |
| 306 | if podAdditions.Annotations == nil { |
| 307 | podAdditions.Annotations = map[string]string{} |
| 308 | } |
| 309 | podAdditions.Annotations[annotKey] = annotVal |
| 310 | } |
| 311 | for labelKey, labelVal := range additions.Labels { |
| 312 | if podAdditions.Labels == nil { |
| 313 | podAdditions.Labels = map[string]string{} |
| 314 | } |
| 315 | podAdditions.Labels[labelKey] = labelVal |
| 316 | } |
| 317 | for _, container := range additions.Containers { |
| 318 | if containerNames[container.Name] { |
| 319 | return nil, fmt.Errorf("duplicate containers in the workspace definition: %s", container.Name) |
| 320 | } |
| 321 | containerNames[container.Name] = true |
| 322 | podAdditions.Containers = append(podAdditions.Containers, container) |
| 323 | } |
| 324 | |
| 325 | for _, container := range additions.InitContainers { |
| 326 | if initContainerNames[container.Name] { |
| 327 | return nil, fmt.Errorf("duplicate init containers in the workspace definition: %s", container.Name) |
| 328 | } |
| 329 | initContainerNames[container.Name] = true |
| 330 | podAdditions.InitContainers = append(podAdditions.InitContainers, container) |
| 331 | } |
| 332 | |
| 333 | for _, volume := range additions.Volumes { |
| 334 | if volumeNames[volume.Name] { |
| 335 | return nil, fmt.Errorf("duplicate volumes in the workspace definition: %s", volume.Name) |
| 336 | } |
| 337 | volumeNames[volume.Name] = true |
| 338 | podAdditions.Volumes = append(podAdditions.Volumes, volume) |
| 339 | } |
| 340 | |
| 341 | for _, volumeMount := range additions.VolumeMounts { |
| 342 | if volumeMountNames[volumeMount.Name] { |
| 343 | return nil, fmt.Errorf("duplicated volumeMounts in workspace definition: %s", volumeMount.Name) |
| 344 | } |
| 345 | volumeMountNames[volumeMount.Name] = true |
| 346 | podAdditions.VolumeMounts = append(podAdditions.VolumeMounts, volumeMount) |
| 347 | } |
| 348 | |
| 349 | for _, pullSecret := range additions.PullSecrets { |
| 350 | if pullSecretNames[pullSecret.Name] { |
| 351 | continue |
| 352 | } |