(ctx devspacecontext.Context, devPodConfig *latest.DevPod, opts Options, parent *tomb.Tomb)
| 219 | } |
| 220 | |
| 221 | func (d *devPod) start(ctx devspacecontext.Context, devPodConfig *latest.DevPod, opts Options, parent *tomb.Tomb) error { |
| 222 | // check first if we need to replace the pod |
| 223 | if !opts.DisablePodReplace && needPodReplace(devPodConfig) { |
| 224 | err := podreplace.NewPodReplacer().ReplacePod(ctx, devPodConfig) |
| 225 | if err != nil { |
| 226 | return errors.Wrap(err, "replace pod") |
| 227 | } |
| 228 | } else { |
| 229 | devPodCache, ok := ctx.Config().RemoteCache().GetDevPod(devPodConfig.Name) |
| 230 | if ok && devPodCache.Deployment != "" { |
| 231 | _, err := podreplace.NewPodReplacer().RevertReplacePod(ctx, &devPodCache, &deploy.PurgeOptions{ForcePurge: true}) |
| 232 | if err != nil { |
| 233 | return errors.Wrap(err, "replace pod") |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | var imageSelector []string |
| 239 | if devPodConfig.ImageSelector != "" { |
| 240 | imageSelectorObject, err := runtimevar.NewRuntimeResolver(ctx.WorkingDir(), true).FillRuntimeVariablesAsImageSelector(ctx.Context(), devPodConfig.ImageSelector, ctx.Config(), ctx.Dependencies()) |
| 241 | if err != nil { |
| 242 | return err |
| 243 | } |
| 244 | |
| 245 | imageSelector = []string{imageSelectorObject.Image} |
| 246 | } |
| 247 | |
| 248 | // wait for pod to be ready |
| 249 | ctx.Log().Infof("Waiting for pod to become ready...") |
| 250 | options := targetselector.NewEmptyOptions(). |
| 251 | ApplyConfigParameter("", devPodConfig.LabelSelector, imageSelector, devPodConfig.Namespace, ""). |
| 252 | WithWaitingStrategy(targetselector.NewUntilNewestRunningWaitingStrategy(time.Millisecond * 500)). |
| 253 | WithSkipInitContainers(true) |
| 254 | var err error |
| 255 | selectedPod, err := targetselector.NewTargetSelector(options).SelectSingleContainer(ctx.Context(), ctx.KubeClient(), ctx.Log()) |
| 256 | if err != nil { |
| 257 | return errors.Wrap(err, "waiting for pod to become ready") |
| 258 | } |
| 259 | |
| 260 | // check if the correct pod is matched |
| 261 | loader.EachDevContainer(devPodConfig, func(devContainer *latest.DevContainer) bool { |
| 262 | if devContainer.Container == "" { |
| 263 | return true |
| 264 | } |
| 265 | |
| 266 | // check if the container exists in the pod |
| 267 | for _, container := range selectedPod.Pod.Spec.Containers { |
| 268 | if container.Name == devContainer.Container { |
| 269 | return true |
| 270 | } |
| 271 | } |
| 272 | for _, container := range selectedPod.Pod.Spec.InitContainers { |
| 273 | if container.Name == devContainer.Container { |
| 274 | return true |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | 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) |
no test coverage detected