(ctx context.Context, client kubectl.Client, namespace string, imageSelector []string, containerName string, skipContainer FilterContainer, skipInit bool)
| 310 | } |
| 311 | |
| 312 | func byImageName(ctx context.Context, client kubectl.Client, namespace string, imageSelector []string, containerName string, skipContainer FilterContainer, skipInit bool) ([]*SelectedPodContainer, error) { |
| 313 | retPods := []*SelectedPodContainer{} |
| 314 | if len(imageSelector) > 0 { |
| 315 | podList, err := client.KubeClient().CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{}) |
| 316 | if err != nil { |
| 317 | return nil, errors.Wrap(err, "list pods") |
| 318 | } |
| 319 | |
| 320 | for _, pod := range podList.Items { |
| 321 | if !skipInit { |
| 322 | for _, container := range pod.Spec.InitContainers { |
| 323 | for _, imageName := range imageSelector { |
| 324 | if skipContainer != nil && skipContainer(&pod, &container) { |
| 325 | continue |
| 326 | } |
| 327 | if containerName != "" && container.Name != containerName { |
| 328 | continue |
| 329 | } |
| 330 | |
| 331 | if imageselector.CompareImageNames(imageName, container.Image) { |
| 332 | retPod := pod |
| 333 | retContainer := container |
| 334 | retPods = append(retPods, &SelectedPodContainer{ |
| 335 | Pod: &retPod, |
| 336 | Container: &retContainer, |
| 337 | }) |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | for _, container := range pod.Spec.Containers { |
| 343 | for _, imageName := range imageSelector { |
| 344 | if skipContainer != nil && skipContainer(&pod, &container) { |
| 345 | continue |
| 346 | } |
| 347 | if containerName != "" && container.Name != containerName { |
| 348 | continue |
| 349 | } |
| 350 | |
| 351 | // check if it is a replaced pod and if yes, check if the imageName and container name matches |
| 352 | containers := map[string]bool{} |
| 353 | if pod.Annotations != nil && pod.Annotations[MatchedContainerAnnotation] != "" { |
| 354 | splitted := strings.Split(pod.Annotations[MatchedContainerAnnotation], ";") |
| 355 | for _, s := range splitted { |
| 356 | containers[s] = true |
| 357 | } |
| 358 | } |
| 359 | if pod.Labels != nil && pod.Labels[ReplacedLabel] == "true" && containers[container.Name] { |
| 360 | if pod.Annotations != nil && pod.Annotations[ImageSelectorAnnotation] != "" && pod.Annotations[ImageSelectorAnnotation] == imageName { |
| 361 | retPod := pod |
| 362 | retContainer := container |
| 363 | retPods = append(retPods, &SelectedPodContainer{ |
| 364 | Pod: &retPod, |
| 365 | Container: &retContainer, |
| 366 | }) |
| 367 | } |
| 368 | continue |
| 369 | } |
no test coverage detected