MCPcopy Create free account
hub / github.com/devspace-sh/devspace / SelectContainers

Method SelectContainers

pkg/devspace/kubectl/selector/selector.go:132–171  ·  view source on GitHub ↗
(ctx context.Context, selectors ...Selector)

Source from the content-addressed store, hash-verified

130}
131
132func (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
173func deduplicate(stack []*SelectedPodContainer) []*SelectedPodContainer {
174 retStack := []*SelectedPodContainer{}

Callers

nothing calls this directly

Calls 5

byLabelSelectorFunction · 0.85
byImageNameFunction · 0.85
byPodNameFunction · 0.85
deduplicateFunction · 0.85
NamespaceMethod · 0.65

Tested by

no test coverage detected