Skip to content

Commit 9cd3723

Browse files
authored
Merge pull request #2299 from FabianKramm/main
refactor: improve dev pod selection
2 parents f56dc02 + 49f3a52 commit 9cd3723

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

pkg/devspace/devpod/devpod.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,32 @@ func (d *devPod) start(ctx devspacecontext.Context, devPodConfig *latest.DevPod,
255255
if err != nil {
256256
return errors.Wrap(err, "waiting for pod to become ready")
257257
}
258-
ctx.Log().Infof("Selected %s (%s)", ansi.Color(fmt.Sprintf("%s:%s", selectedPod.Pod.Name, selectedPod.Container.Name), "yellow+b"), ansi.Color("pod:container", "white+b"))
258+
259+
// check if the correct pod is matched
260+
loader.EachDevContainer(devPodConfig, func(devContainer *latest.DevContainer) bool {
261+
if devContainer.Container == "" {
262+
return true
263+
}
264+
265+
// check if the container exists in the pod
266+
for _, container := range selectedPod.Pod.Spec.Containers {
267+
if container.Name == devContainer.Container {
268+
return true
269+
}
270+
}
271+
for _, container := range selectedPod.Pod.Spec.InitContainers {
272+
if container.Name == devContainer.Container {
273+
return true
274+
}
275+
}
276+
277+
err = fmt.Errorf("selected pod '%s/%s' doesn't include container '%s', please make sure you don't have overlapping label selectors within the namespace and the pod you select contains container '%s'", selectedPod.Pod.Namespace, selectedPod.Pod.Name, devContainer.Container, devContainer.Container)
278+
return false
279+
})
280+
if err != nil {
281+
return errors.Wrap(err, "select pod")
282+
}
283+
ctx.Log().Infof("Selected pod %s", ansi.Color(selectedPod.Pod.Name, "yellow+b"))
259284

260285
// set selected pod
261286
d.m.Lock()

0 commit comments

Comments
 (0)