From bff3e85625d804013e74f8b1489c61a237a73320 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 11 Aug 2022 13:00:01 +0200 Subject: [PATCH] libcontainerd/supervisor: store location of config-file Adding a remote.configFile to store the location instead of re-constructing its location each time. Also fixing a minor inconsistency in the error formats. Signed-off-by: Sebastiaan van Stijn --- libcontainerd/supervisor/remote_daemon.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libcontainerd/supervisor/remote_daemon.go b/libcontainerd/supervisor/remote_daemon.go index f5e35677d1..83f0d6de7c 100644 --- a/libcontainerd/supervisor/remote_daemon.go +++ b/libcontainerd/supervisor/remote_daemon.go @@ -32,6 +32,10 @@ const ( type remote struct { config.Config + // configFile is the location where the generated containerd configuration + // file is saved. + configFile string + daemonPid int pidFile string logger *logrus.Entry @@ -64,6 +68,7 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da Root: filepath.Join(rootDir, "daemon"), State: filepath.Join(stateDir, "daemon"), }, + configFile: filepath.Join(stateDir, configFile), daemonPid: -1, pidFile: filepath.Join(stateDir, pidFile), logger: logrus.WithField("module", "libcontainerd"), @@ -144,17 +149,16 @@ func (r *remote) getContainerdPid() (int, error) { } func (r *remote) getContainerdConfig() (string, error) { - path := filepath.Join(r.stateDir, configFile) - f, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) + f, err := os.OpenFile(r.configFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) if err != nil { - return "", errors.Wrapf(err, "failed to open containerd config file at %s", path) + return "", errors.Wrapf(err, "failed to open containerd config file (%s)", r.configFile) } defer f.Close() if err := toml.NewEncoder(f).Encode(r); err != nil { - return "", errors.Wrapf(err, "failed to write containerd config file (%s)", path) + return "", errors.Wrapf(err, "failed to write containerd config file (%s)", r.configFile) } - return path, nil + return r.configFile, nil } func (r *remote) startContainerd() error {