(ctx devspacecontext.Context, devPod *latest.DevPod, devContainer *latest.DevContainer, podTemplate *corev1.PodTemplateSpec)
| 283 | } |
| 284 | |
| 285 | func replaceCommand(ctx devspacecontext.Context, devPod *latest.DevPod, devContainer *latest.DevContainer, podTemplate *corev1.PodTemplateSpec) error { |
| 286 | // replace with DevSpace helper |
| 287 | injectRestartHelper := devContainer.RestartHelper != nil && devContainer.RestartHelper.Inject != nil && *devContainer.RestartHelper.Inject |
| 288 | if devContainer.RestartHelper == nil || devContainer.RestartHelper.Inject == nil || *devContainer.RestartHelper.Inject { |
| 289 | for _, s := range devContainer.Sync { |
| 290 | if s.StartContainer || (s.OnUpload != nil && s.OnUpload.RestartContainer) { |
| 291 | injectRestartHelper = true |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | if len(devContainer.Command) == 0 && injectRestartHelper { |
| 296 | return fmt.Errorf("dev.%s.sync[*].onUpload.restartContainer or dev.%s.restartHelper.inject is true, please specify the entrypoint that should get restarted in dev.%s.command", devPod.Name, devPod.Name, devPod.Name) |
| 297 | } |
| 298 | if !injectRestartHelper && len(devContainer.Command) == 0 && devContainer.Args == nil { |
| 299 | return nil |
| 300 | } |
| 301 | |
| 302 | index, container, err := getPodTemplateContainer(ctx, devPod, devContainer, podTemplate) |
| 303 | if err != nil { |
| 304 | return err |
| 305 | } |
| 306 | |
| 307 | // make sure probes are not set for this container |
| 308 | container.ReadinessProbe = nil |
| 309 | container.LivenessProbe = nil |
| 310 | container.StartupProbe = nil |
| 311 | |
| 312 | // should we inject devspace restart helper? |
| 313 | if injectRestartHelper { |
| 314 | containerHash := strings.ToLower(hash.String(container.Name))[0:10] |
| 315 | annotationName := restartHelperAnnotation + containerHash |
| 316 | if podTemplate.Annotations == nil { |
| 317 | podTemplate.Annotations = map[string]string{} |
| 318 | } |
| 319 | |
| 320 | restartHelperPath := "" |
| 321 | if devContainer.RestartHelper != nil { |
| 322 | restartHelperPath = devContainer.RestartHelper.Path |
| 323 | } |
| 324 | |
| 325 | restartHelperString, err := restart.LoadRestartHelper(restartHelperPath) |
| 326 | if err != nil { |
| 327 | return errors.Wrap(err, "load restart helper") |
| 328 | } |
| 329 | podTemplate.Annotations[annotationName] = restartHelperString |
| 330 | |
| 331 | volumeName := "devspace-restart-" + containerHash |
| 332 | podTemplate.Spec.Volumes = append(podTemplate.Spec.Volumes, corev1.Volume{ |
| 333 | Name: volumeName, |
| 334 | VolumeSource: corev1.VolumeSource{ |
| 335 | DownwardAPI: &corev1.DownwardAPIVolumeSource{ |
| 336 | DefaultMode: &mode, |
| 337 | Items: []corev1.DownwardAPIVolumeFile{ |
| 338 | { |
| 339 | Path: restart.ScriptName, |
| 340 | FieldRef: &corev1.ObjectFieldSelector{ |
| 341 | APIVersion: "v1", |
| 342 | FieldPath: "metadata.annotations['" + annotationName + "']", |
no test coverage detected