MCPcopy
hub / github.com/firecracker-microvm/firecracker-containerd / LoadConfig

Function LoadConfig

config/config.go:73–115  ·  view source on GitHub ↗

LoadConfig loads configuration from JSON file at 'path'

(path string)

Source from the content-addressed store, hash-verified

71
72// LoadConfig loads configuration from JSON file at 'path'
73func LoadConfig(path string) (*Config, error) {
74 if path == "" {
75 path = os.Getenv(ConfigPathEnvName)
76 }
77
78 if path == "" {
79 path = defaultConfigPath
80 }
81
82 data, err := os.ReadFile(path)
83 if err != nil {
84 return nil, fmt.Errorf("failed to read config from %q: %w", path, err)
85 }
86
87 cfg := &Config{
88 KernelArgs: defaultKernelArgs,
89 KernelImagePath: defaultKernelPath,
90 RootDrive: defaultRootfsPath,
91 ShimBaseDir: defaultShimBaseDir,
92 JailerConfig: JailerConfig{
93 RuncConfigPath: runcConfigPath,
94 },
95 }
96
97 flag, err := internal.SupportCPUTemplate()
98 if err != nil {
99 return nil, err
100 }
101 if flag {
102 cfg.CPUTemplate = string(defaultCPUTemplate)
103 }
104
105 if err := json.Unmarshal(data, cfg); err != nil {
106 return nil, fmt.Errorf("failed to unmarshal config from %q: %w", path, err)
107 }
108
109 cfg.DebugHelper, err = debug.New(cfg.LogLevels...)
110 if err != nil {
111 return nil, err
112 }
113
114 return cfg, nil
115}

Callers 8

newLocalFunction · 0.92
NewServiceFunction · 0.92
testMultipleVMsFunction · 0.92
TestLoadConfigDefaultsFunction · 0.85
TestLoadConfigOverridesFunction · 0.85

Calls 2

SupportCPUTemplateFunction · 0.92
NewFunction · 0.92