CreateContainer creates a new container in the given PodSandbox Docker cannot store the log to an arbitrary location (yet), so we create an symlink at LogPath, linking to the actual path of the log.
( _ context.Context, r *v1.CreateContainerRequest, )
| 31 | // Docker cannot store the log to an arbitrary location (yet), so we create an |
| 32 | // symlink at LogPath, linking to the actual path of the log. |
| 33 | func (ds *dockerService) CreateContainer( |
| 34 | _ context.Context, |
| 35 | r *v1.CreateContainerRequest, |
| 36 | ) (*v1.CreateContainerResponse, error) { |
| 37 | podSandboxID := r.PodSandboxId |
| 38 | config := r.GetConfig() |
| 39 | sandboxConfig := r.GetSandboxConfig() |
| 40 | |
| 41 | if config == nil { |
| 42 | return nil, fmt.Errorf("container config is nil") |
| 43 | } |
| 44 | if sandboxConfig == nil { |
| 45 | return nil, fmt.Errorf("sandbox config is nil for container %q", config.Metadata.Name) |
| 46 | } |
| 47 | |
| 48 | labels := makeLabels(config.GetLabels(), config.GetAnnotations()) |
| 49 | // Apply a the container type label. |
| 50 | labels[containerTypeLabelKey] = containerTypeLabelContainer |
| 51 | // Write the container log path in the labels. |
| 52 | labels[containerLogPathLabelKey] = filepath.Join(sandboxConfig.LogDirectory, config.LogPath) |
| 53 | // Write the sandbox ID in the labels. |
| 54 | labels[sandboxIDLabelKey] = podSandboxID |
| 55 | |
| 56 | apiVersion, err := ds.getDockerAPIVersion() |
| 57 | if err != nil { |
| 58 | return nil, fmt.Errorf("unable to get the docker API version: %v", err) |
| 59 | } |
| 60 | |
| 61 | image := "" |
| 62 | if iSpec := config.GetImage(); iSpec != nil { |
| 63 | image = iSpec.Image |
| 64 | } |
| 65 | containerName := makeContainerName(sandboxConfig, config) |
| 66 | terminationMessagePath, _ := config.Annotations["io.kubernetes.container.terminationMessagePath"] |
| 67 | createConfig := libdocker.ContainerCreateConfig{ |
| 68 | Name: containerName, |
| 69 | Config: &container.Config{ |
| 70 | Entrypoint: strslice.StrSlice(config.Command), |
| 71 | Cmd: strslice.StrSlice(config.Args), |
| 72 | Env: libdocker.GenerateEnvList(config.GetEnvs()), |
| 73 | Image: image, |
| 74 | WorkingDir: config.WorkingDir, |
| 75 | Labels: labels, |
| 76 | // Interactive containers: |
| 77 | OpenStdin: config.Stdin, |
| 78 | StdinOnce: config.StdinOnce, |
| 79 | Tty: config.Tty, |
| 80 | // Disable Docker's health check until we officially support it |
| 81 | // (https://github.com/kubernetes/kubernetes/issues/25829). |
| 82 | Healthcheck: &container.HealthConfig{ |
| 83 | Test: []string{"NONE"}, |
| 84 | }, |
| 85 | }, |
| 86 | HostConfig: &container.HostConfig{ |
| 87 | Binds: libdocker.GenerateMountBindings(config.GetMounts(), terminationMessagePath), |
| 88 | RestartPolicy: container.RestartPolicy{ |
| 89 | Name: "no", |
| 90 | }, |
nothing calls this directly
no test coverage detected