File: default.go

package info (click to toggle)
golang-github-containerd-nydus-snapshotter 0.13.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,824 kB
  • sloc: sh: 470; makefile: 129
file content (69 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (c) 2023. Nydus Developers. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package config

import (
	"os/exec"

	"github.com/containerd/nydus-snapshotter/internal/constant"
)

func (c *SnapshotterConfig) FillUpWithDefaults() error {
	c.Version = 1
	c.Root = constant.DefaultRootDir
	c.Address = constant.DefaultAddress

	// essential configuration
	if c.DaemonMode == "" {
		c.DaemonMode = constant.DefaultDaemonMode
	}

	// system controller configuration
	c.SystemControllerConfig.Address = constant.DefaultSystemControllerAddress

	// logging configuration
	logConfig := &c.LoggingConfig
	if logConfig.LogLevel == "" {
		logConfig.LogLevel = constant.DefaultLogLevel
	}
	logConfig.RotateLogMaxSize = constant.DefaultRotateLogMaxSize
	logConfig.RotateLogMaxBackups = constant.DefaultRotateLogMaxBackups
	logConfig.RotateLogMaxAge = constant.DefaultRotateLogMaxAge
	logConfig.RotateLogLocalTime = constant.DefaultRotateLogLocalTime
	logConfig.RotateLogCompress = constant.DefaultRotateLogCompress

	// daemon configuration
	daemonConfig := &c.DaemonConfig
	if daemonConfig.NydusdConfigPath == "" {
		daemonConfig.NydusdConfigPath = constant.DefaultNydusDaemonConfigPath
	}
	daemonConfig.RecoverPolicy = RecoverPolicyRestart.String()
	daemonConfig.FsDriver = constant.DefaultFsDriver
	daemonConfig.LogRotationSize = constant.DefaultDaemonRotateLogMaxSize

	// cache configuration
	cacheConfig := &c.CacheManagerConfig
	if cacheConfig.GCPeriod == "" {
		cacheConfig.GCPeriod = constant.DefaultGCPeriod
	}

	return c.SetupNydusBinaryPaths()
}

func (c *SnapshotterConfig) SetupNydusBinaryPaths() error {
	// resolve nydusd path
	if path, err := exec.LookPath(constant.NydusdBinaryName); err == nil {
		c.DaemonConfig.NydusdPath = path
	}

	// resolve nydus-image path
	if path, err := exec.LookPath(constant.NydusImageBinaryName); err == nil {
		c.DaemonConfig.NydusImagePath = path
	}

	return nil
}