@@ -45,8 +45,9 @@ type SatelliteOptions struct {
4545 SPIFFEExpectedServerID string
4646 BYORegistry bool
4747 RegistryURL string
48- RegistryUsername string
48+ RegistryUsername string
4949 RegistryPassword string
50+ ConfigDir string
5051}
5152
5253func main () {
@@ -64,6 +65,7 @@ func main() {
6465 flag .StringVar (& opts .RegistryURL , "registry-url" , "" , "External registry URL" )
6566 flag .StringVar (& opts .RegistryUsername , "registry-username" , "" , "External registry username" )
6667 flag .StringVar (& opts .RegistryPassword , "registry-password" , "" , "External registry password" )
68+ flag .StringVar (& opts .ConfigDir , "config-dir" , "" , "Configuration directory path (default: ~/.config/satellite)" )
6769
6870 flag .Parse ()
6971
@@ -97,6 +99,25 @@ func main() {
9799 if opts .RegistryPassword == "" {
98100 opts .RegistryPassword = os .Getenv ("REGISTRY_PASSWORD" )
99101 }
102+ if opts .ConfigDir == "" {
103+ opts .ConfigDir = os .Getenv ("CONFIG_DIR" )
104+ }
105+
106+ // Resolve config directory path
107+ if opts .ConfigDir == "" {
108+ var err error
109+ opts .ConfigDir , err = config .DefaultConfigDir ()
110+ if err != nil {
111+ fmt .Printf ("Error resolving default config directory: %v\n " , err )
112+ os .Exit (1 )
113+ }
114+ }
115+
116+ pathConfig , err := config .ResolvePathConfig (opts .ConfigDir )
117+ if err != nil {
118+ fmt .Printf ("Error resolving config paths: %v\n " , err )
119+ os .Exit (1 )
120+ }
100121
101122 // Token is not required if SPIFFE is enabled
102123 if ! opts .SPIFFEEnabled && (opts .Token == "" || opts .GroundControlURL == "" ) {
@@ -112,21 +133,21 @@ func main() {
112133 os .Exit (1 )
113134 }
114135
115- err : = run (opts )
136+ err = run (opts , pathConfig )
116137 if err != nil {
117138 fmt .Printf ("fatal: %v\n " , err )
118139 os .Exit (1 )
119140 }
120141}
121142
122- func run (opts SatelliteOptions ) error {
143+ func run (opts SatelliteOptions , pathConfig * config. PathConfig ) error {
123144 ctx , cancel := utils .SetupContext (context .Background ())
124145 defer cancel ()
125146 wg , ctx := errgroup .WithContext (ctx )
126147
127- cm , warnings , err := config .InitConfigManager (opts .Token , opts .GroundControlURL , config . DefaultConfigPath , config . DefaultPrevConfigPath , opts .JSONLogging , opts .UseUnsecure )
148+ cm , warnings , err := config .InitConfigManager (opts .Token , opts .GroundControlURL , pathConfig . ConfigFile , pathConfig . PrevConfigFile , opts .JSONLogging , opts .UseUnsecure )
128149 if err != nil {
129- fmt .Printf ("Error initiating the config manager: %v" , err )
150+ fmt .Printf ("Error initiating the config manager: %v\n " , err )
130151 return err
131152 }
132153
@@ -149,6 +170,13 @@ func run(opts SatelliteOptions) error {
149170 )
150171 }
151172
173+ // Update Zot config with storage path
174+ zotConfigJSON , err := config .BuildZotConfigWithStoragePath (pathConfig .ZotStorageDir )
175+ if err != nil {
176+ return fmt .Errorf ("build Zot config: %w" , err )
177+ }
178+ cm .With (config .SetZotConfigRaw (json .RawMessage (zotConfigJSON )))
179+
152180 // Resolve local registry endpoint for CRI mirror config
153181 localRegistryEndpoint , err := resolveLocalRegistryEndpoint (cm )
154182 if err != nil {
@@ -170,17 +198,18 @@ func run(opts SatelliteOptions) error {
170198 ctx ,
171199 cm ,
172200 log ,
201+ pathConfig .ZotTempConfig ,
173202 nil , // Will be set after scheduler creation
174203 )
175204
176205 eventChan := make (chan struct {})
177206
178207 // Handle registry setup
179- wg .Go (func () error { return handleRegistrySetup (ctx , log , cm ) })
208+ wg .Go (func () error { return handleRegistrySetup (ctx , log , cm , pathConfig ) })
180209
181210 // Watch for changes in the config file
182211 wg .Go (func () error {
183- return watcher .WatchChanges (ctx , log .With ().Str ("component" , "file watcher" ).Logger (), config . DefaultConfigPath , eventChan )
212+ return watcher .WatchChanges (ctx , log .With ().Str ("component" , "file watcher" ).Logger (), pathConfig . ConfigFile , eventChan )
184213 })
185214
186215 // Watch for changes in the config file
@@ -233,11 +262,11 @@ func resolveLocalRegistryEndpoint(cm *config.ConfigManager) (string, error) {
233262 if cm .GetOwnRegistry () {
234263 return utils .FormatRegistryURL (cm .GetLocalRegistryURL ()), nil
235264 }
236- var data map [string ]interface {}
265+ var data map [string ]any
237266 if err := json .Unmarshal (cm .GetRawZotConfig (), & data ); err != nil {
238267 return "" , fmt .Errorf ("unmarshalling zot config: %w" , err )
239268 }
240- httpData , ok := data ["http" ].(map [string ]interface {} )
269+ httpData , ok := data ["http" ].(map [string ]any )
241270 if ! ok {
242271 return "" , fmt .Errorf ("missing 'http' section in zot config" )
243272 }
@@ -249,7 +278,7 @@ func resolveLocalRegistryEndpoint(cm *config.ConfigManager) (string, error) {
249278 return addr + ":" + port , nil
250279}
251280
252- func handleRegistrySetup (ctx context.Context , log * zerolog.Logger , cm * config.ConfigManager ) error {
281+ func handleRegistrySetup (ctx context.Context , log * zerolog.Logger , cm * config.ConfigManager , pathConfig * config. PathConfig ) error {
253282 log .Debug ().Msg ("Setting up local registry" )
254283
255284 if cm .GetOwnRegistry () {
@@ -264,7 +293,7 @@ func handleRegistrySetup(ctx context.Context, log *zerolog.Logger, cm *config.Co
264293
265294 log .Info ().Msg ("Launching default registry" )
266295
267- zm := registry .NewZotManager (log .With ().Str ("component" , "zot manager" ).Logger (), cm .GetRawZotConfig ())
296+ zm := registry .NewZotManager (log .With ().Str ("component" , "zot manager" ).Logger (), cm .GetRawZotConfig (), pathConfig . ZotTempConfig )
268297
269298 if err := zm .HandleRegistrySetup (ctx ); err != nil {
270299 return fmt .Errorf ("default registry setup failed: %w" , err )
0 commit comments