(ctx context.Context, selectors ...Selector)
| 130 | } |
| 131 | |
| 132 | func (f *filter) SelectContainers(ctx context.Context, selectors ...Selector) ([]*SelectedPodContainer, error) { |
| 133 | retList := []*SelectedPodContainer{} |
| 134 | for _, s := range selectors { |
| 135 | namespace := f.client.Namespace() |
| 136 | if s.Namespace != "" { |
| 137 | namespace = s.Namespace |
| 138 | } |
| 139 | |
| 140 | if s.LabelSelector != "" || (len(s.ImageSelector) == 0 && s.Pod == "") { |
| 141 | containersByLabelSelector, err := byLabelSelector(ctx, f.client, namespace, s.LabelSelector, s.ContainerName, s.FilterContainer, s.SkipInitContainers) |
| 142 | if err != nil { |
| 143 | return nil, errors.Wrap(err, "pods by label selector") |
| 144 | } |
| 145 | |
| 146 | retList = append(retList, containersByLabelSelector...) |
| 147 | } |
| 148 | |
| 149 | containersByImage, err := byImageName(ctx, f.client, namespace, s.ImageSelector, s.ContainerName, s.FilterContainer, s.SkipInitContainers) |
| 150 | if err != nil { |
| 151 | return nil, errors.Wrap(err, "pods by image name") |
| 152 | } |
| 153 | |
| 154 | containersByName, err := byPodName(ctx, f.client, namespace, s.Pod, s.ContainerName, s.FilterContainer, s.SkipInitContainers) |
| 155 | if err != nil { |
| 156 | return nil, errors.Wrap(err, "pods by label selector") |
| 157 | } |
| 158 | |
| 159 | retList = append(retList, containersByImage...) |
| 160 | retList = append(retList, containersByName...) |
| 161 | } |
| 162 | |
| 163 | retList = deduplicate(retList) |
| 164 | if f.sortContainers != nil { |
| 165 | sort.Slice(retList, func(i, j int) bool { |
| 166 | return f.sortContainers(retList, i, j) |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | return retList, nil |
| 171 | } |
| 172 | |
| 173 | func deduplicate(stack []*SelectedPodContainer) []*SelectedPodContainer { |
| 174 | retStack := []*SelectedPodContainer{} |
nothing calls this directly
no test coverage detected