Skip to content

Commit 8608f18

Browse files
committed
Feat: Add minimal config
1 parent a2cb62d commit 8608f18

1 file changed

Lines changed: 162 additions & 0 deletions

File tree

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package config
2+
3+
import "fmt"
4+
5+
// applyMinimalDefaults fills any missing (zero-value) fields from defaultConfig()
6+
// after the config file + ENV have been unmarshaled.
7+
func applyMinimalDefaults(cfg *Config) {
8+
def := defaultConfig()
9+
10+
// === Strings ===
11+
if cfg.GRPCAddr == "" {
12+
cfg.GRPCAddr = def.GRPCAddr
13+
}
14+
if cfg.TLSCertPath == "" {
15+
cfg.TLSCertPath = def.TLSCertPath
16+
}
17+
if cfg.TLSKeyPath == "" {
18+
cfg.TLSKeyPath = def.TLSKeyPath
19+
}
20+
if cfg.TLSCAPath == "" {
21+
cfg.TLSCAPath = def.TLSCAPath
22+
}
23+
if cfg.VaultManagerAddr == "" {
24+
cfg.VaultManagerAddr = def.VaultManagerAddr
25+
}
26+
if cfg.VaultAddr == "" {
27+
cfg.VaultAddr = def.VaultAddr
28+
}
29+
if cfg.VaultAuthMethod == "" {
30+
cfg.VaultAuthMethod = def.VaultAuthMethod
31+
}
32+
if cfg.VaultToken == "" {
33+
cfg.VaultToken = def.VaultToken
34+
}
35+
if cfg.VaultAppRoleID == "" {
36+
cfg.VaultAppRoleID = def.VaultAppRoleID
37+
}
38+
if cfg.VaultAppSecretID == "" {
39+
cfg.VaultAppSecretID = def.VaultAppSecretID
40+
}
41+
if cfg.VaultPKIMount == "" {
42+
cfg.VaultPKIMount = def.VaultPKIMount
43+
}
44+
if cfg.VaultPKIRole == "" {
45+
cfg.VaultPKIRole = def.VaultPKIRole
46+
}
47+
if cfg.VaultServiceName == "" {
48+
cfg.VaultServiceName = def.VaultServiceName
49+
}
50+
if cfg.VaultServiceDomain == "" {
51+
cfg.VaultServiceDomain = def.VaultServiceDomain
52+
}
53+
if cfg.StateStorePath == "" {
54+
cfg.StateStorePath = def.StateStorePath
55+
}
56+
if cfg.DockerEndpoint == "" {
57+
cfg.DockerEndpoint = def.DockerEndpoint
58+
fmt.Printf("DEBUG: DockerEndpoint was empty → set default\n")
59+
} else {
60+
fmt.Printf("DEBUG: Keeping DockerEndpoint from config file: %s\n", cfg.DockerEndpoint)
61+
}
62+
if cfg.ComposeBinary == "" {
63+
cfg.ComposeBinary = def.ComposeBinary
64+
}
65+
if cfg.LibvirtURI == "" {
66+
cfg.LibvirtURI = def.LibvirtURI
67+
}
68+
if cfg.StorageLocalRoot == "" {
69+
cfg.StorageLocalRoot = def.StorageLocalRoot
70+
}
71+
if cfg.StorageNFSStageDir == "" {
72+
cfg.StorageNFSStageDir = def.StorageNFSStageDir
73+
}
74+
if cfg.StorageNFSServer == "" {
75+
cfg.StorageNFSServer = def.StorageNFSServer
76+
}
77+
if cfg.StorageNFSExport == "" {
78+
cfg.StorageNFSExport = def.StorageNFSExport
79+
}
80+
if cfg.StorageNFSOptions == "" {
81+
cfg.StorageNFSOptions = def.StorageNFSOptions
82+
}
83+
if cfg.StorageCephStageDir == "" {
84+
cfg.StorageCephStageDir = def.StorageCephStageDir
85+
}
86+
if cfg.StorageCephCluster == "" {
87+
cfg.StorageCephCluster = def.StorageCephCluster
88+
}
89+
if cfg.StorageCephPool == "" {
90+
cfg.StorageCephPool = def.StorageCephPool
91+
}
92+
if cfg.StorageCephUser == "" {
93+
cfg.StorageCephUser = def.StorageCephUser
94+
}
95+
if cfg.StorageCephKeyring == "" {
96+
cfg.StorageCephKeyring = def.StorageCephKeyring
97+
}
98+
if cfg.LogLevel == "" {
99+
cfg.LogLevel = def.LogLevel
100+
}
101+
if cfg.NodeID == "" {
102+
cfg.NodeID = def.NodeID
103+
}
104+
if cfg.NodeRegion == "" {
105+
cfg.NodeRegion = def.NodeRegion
106+
}
107+
if cfg.NodeEnv == "" {
108+
cfg.NodeEnv = def.NodeEnv
109+
}
110+
if cfg.SchedulerAddr == "" {
111+
cfg.SchedulerAddr = def.SchedulerAddr
112+
}
113+
if cfg.AgentGRPCEndpoint == "" {
114+
cfg.AgentGRPCEndpoint = def.AgentGRPCEndpoint
115+
}
116+
if cfg.OTELExporterEndpoint == "" {
117+
cfg.OTELExporterEndpoint = def.OTELExporterEndpoint
118+
}
119+
120+
// === Integers ===
121+
if cfg.GRPCPort == 0 {
122+
cfg.GRPCPort = def.GRPCPort
123+
}
124+
if cfg.MetricsPort == 0 {
125+
cfg.MetricsPort = def.MetricsPort
126+
}
127+
128+
// === Booleans ===
129+
if !cfg.TLSEnabled {
130+
cfg.TLSEnabled = def.TLSEnabled
131+
}
132+
if !cfg.VaultEnabled {
133+
cfg.VaultEnabled = def.VaultEnabled
134+
}
135+
if !cfg.DockerEnabled {
136+
cfg.DockerEnabled = def.DockerEnabled
137+
}
138+
if !cfg.ComposeEnabled {
139+
cfg.ComposeEnabled = def.ComposeEnabled
140+
}
141+
if !cfg.VMEnabled {
142+
cfg.VMEnabled = def.VMEnabled
143+
}
144+
if !cfg.ReconcileEnabled {
145+
cfg.ReconcileEnabled = def.ReconcileEnabled
146+
}
147+
if !cfg.SchedulerInsecure {
148+
cfg.SchedulerInsecure = def.SchedulerInsecure
149+
}
150+
151+
// === Durations ===
152+
if cfg.VaultCertTTL == 0 {
153+
cfg.VaultCertTTL = def.VaultCertTTL
154+
}
155+
if cfg.VaultRetryInterval == 0 {
156+
cfg.VaultRetryInterval = def.VaultRetryInterval
157+
}
158+
if cfg.ReconcileInterval == 0 {
159+
cfg.ReconcileInterval = def.ReconcileInterval
160+
}
161+
162+
}

0 commit comments

Comments
 (0)