MCPcopy Create free account
hub / github.com/Mirantis/cri-dockerd / createContainerLogSymlink

Method createContainerLogSymlink

core/logs.go:162–203  ·  view source on GitHub ↗

createContainerLogSymlink creates the symlink for docker container log.

(containerID string)

Source from the content-addressed store, hash-verified

160
161// createContainerLogSymlink creates the symlink for docker container log.
162func (ds *dockerService) createContainerLogSymlink(containerID string) error {
163 path, realPath, err := ds.getContainerLogPath(containerID)
164 if err != nil {
165 return fmt.Errorf("failed to get container %q log path: %v", containerID, err)
166 }
167
168 if path == "" {
169 logrus.Debugf("Container log path for Container ID %s isn't specified, will not create symlink", containerID)
170 return nil
171 }
172
173 if realPath != "" {
174 // Only create the symlink when container log path is specified and log file exists.
175 // Delete possibly existing file first
176 if err = ds.os.Remove(path); err == nil {
177 logrus.Debugf("Deleted previously existing symlink file: %s", path)
178 }
179 if err = ds.os.Symlink(realPath, path); err != nil {
180 return fmt.Errorf(
181 "failed to create symbolic link %q to the container log file %q for container %q: %v",
182 path,
183 realPath,
184 containerID,
185 err,
186 )
187 }
188 } else {
189 supported, err := ds.IsCRISupportedLogDriver()
190 if err != nil {
191 logrus.Errorf("Failed to check supported logging driver for CRI: %v", err)
192 return nil
193 }
194
195 if supported {
196 logrus.Info("Cannot create symbolic link because container log file doesn't exist!")
197 } else {
198 logrus.Debug("Unsupported logging driver by CRI")
199 }
200 }
201
202 return nil
203}
204
205// removeContainerLogSymlink removes the symlink for docker container log.
206func (ds *dockerService) removeContainerLogSymlink(containerID string) error {

Callers 1

StartContainerMethod · 0.95

Calls 5

getContainerLogPathMethod · 0.95
RemoveMethod · 0.65
SymlinkMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected