@@ -112,7 +112,7 @@ func GetConfig() *latest.Config {
112112 return config
113113}
114114
115- func loadBaseConfigFromPath (basePath string , loadConfig string , cache * generated.CacheConfig ) (* latest.Config , * configs.ConfigDefinition , error ) {
115+ func loadBaseConfigFromPath (basePath string , loadConfig string , loadOverwrites bool , generatedConfig * generated.Config , log log. Logger ) (* latest.Config , * configs.ConfigDefinition , error ) {
116116 var (
117117 config = latest .New ().(* latest.Config )
118118 configRaw = latest .New ().(* latest.Config )
@@ -159,7 +159,7 @@ func loadBaseConfigFromPath(basePath string, loadConfig string, cache *generated
159159 return nil , nil , fmt .Errorf ("Error loading vars: %v" , err )
160160 }
161161
162- err = askQuestions (cache , vars )
162+ err = askQuestions (generatedConfig . GetActive () , vars )
163163 if err != nil {
164164 return nil , nil , fmt .Errorf ("Error filling vars: %v" , err )
165165 }
@@ -185,7 +185,7 @@ func loadBaseConfigFromPath(basePath string, loadConfig string, cache *generated
185185 }
186186
187187 // Ask questions
188- err = askQuestions (cache , vars )
188+ err = askQuestions (generatedConfig . GetActive () , vars )
189189 if err != nil {
190190 return nil , nil , fmt .Errorf ("Error filling vars: %v" , err )
191191 }
@@ -198,28 +198,58 @@ func loadBaseConfigFromPath(basePath string, loadConfig string, cache *generated
198198 }
199199
200200 Merge (& config , deepCopy (configRaw ))
201- return config , configDefinition , nil
202- }
203-
204- // GetConfigFromPath loads the config from a given base path
205- func GetConfigFromPath (basePath string , loadConfig string , cache * generated.CacheConfig ) (* latest.Config , error ) {
206- config , configDefinition , err := loadBaseConfigFromPath (basePath , loadConfig , cache )
207- if err != nil {
208- return nil , err
209- }
210201
211202 // Check if we should load overrides
212- if configDefinition != nil {
213- if configDefinition .Overrides != nil {
214- for index , configWrapper := range * configDefinition .Overrides {
215- overwriteConfig , err := loadConfigFromWrapper (basePath , configWrapper )
216- if err != nil {
217- return nil , fmt .Errorf ("Error loading override config at index %d: %v" , index , err )
203+ if loadOverwrites {
204+ if configDefinition != nil {
205+ if configDefinition .Overrides != nil {
206+ for index , configWrapper := range * configDefinition .Overrides {
207+ overwriteConfig , err := loadConfigFromWrapper ("." , configWrapper )
208+ if err != nil {
209+ return nil , nil , fmt .Errorf ("Error loading override config at index %d: %v" , index , err )
210+ }
211+
212+ Merge (& config , overwriteConfig )
213+ }
214+
215+ log .Infof ("Loaded config %s from %s with %d overrides" , LoadedConfig , DefaultConfigsPath , len (* configDefinition .Overrides ))
216+ } else {
217+ log .Infof ("Loaded config %s from %s" , LoadedConfig , DefaultConfigsPath )
218+ }
219+ } else {
220+ log .Infof ("Loaded config from %s" , DefaultConfigPath )
221+ }
222+
223+ // Exchange kube context if necessary, but only if we don't load the base config
224+ // we do this to avoid saving the kube context on commands like
225+ // devspace add deployment && devspace add image etc.
226+ if generatedConfig .CloudSpace != nil {
227+ if config .Cluster == nil || (config .Cluster .KubeContext == nil && config .Cluster .APIServer == nil ) {
228+ if generatedConfig .CloudSpace .KubeContext == "" {
229+ return nil , nil , fmt .Errorf ("No space configured\n \n Please run: \n - `%s` to create a new space\n - `%s` to use an existing space\n - `%s` to list existing spaces" , ansi .Color ("devspace create space [NAME]" , "white+b" ), ansi .Color ("devspace use space [NAME]" , "white+b" ), ansi .Color ("devspace list spaces" , "white+b" ))
218230 }
219231
220- Merge (& config , overwriteConfig )
232+ config .Cluster = & latest.Cluster {
233+ KubeContext : & generatedConfig .CloudSpace .KubeContext ,
234+ }
221235 }
222236 }
237+ } else {
238+ if configDefinition != nil {
239+ log .Infof ("Loaded config %s from %s" , LoadedConfig , DefaultConfigsPath )
240+ } else {
241+ log .Infof ("Loaded config %s" , DefaultConfigPath )
242+ }
243+ }
244+
245+ return config , configDefinition , nil
246+ }
247+
248+ // GetConfigFromPath loads the config from a given base path
249+ func GetConfigFromPath (basePath string , loadConfig string , loadOverrides bool , generatedConfig * generated.Config ) (* latest.Config , error ) {
250+ config , _ , err := loadBaseConfigFromPath (basePath , loadConfig , loadOverrides , generatedConfig , log .Discard )
251+ if err != nil {
252+ return nil , err
223253 }
224254
225255 err = validate (config )
@@ -248,7 +278,7 @@ func GetConfigWithoutDefaults(loadOverwrites bool) *latest.Config {
248278 LoadedConfig = generatedConfig .ActiveConfig
249279
250280 // Load base config
251- config , configDefinition , err = loadBaseConfigFromPath ("." , LoadedConfig , generatedConfig . GetActive ())
281+ config , configDefinition , err = loadBaseConfigFromPath ("." , LoadedConfig , loadOverwrites , generatedConfig , log . GetInstance ())
252282 if err != nil {
253283 log .Fatal (err )
254284 }
@@ -258,49 +288,6 @@ func GetConfigWithoutDefaults(loadOverwrites bool) *latest.Config {
258288 LoadedConfig = ""
259289 }
260290
261- // Check if we should load overrides
262- if loadOverwrites {
263- if configDefinition != nil {
264- if configDefinition .Overrides != nil {
265- for index , configWrapper := range * configDefinition .Overrides {
266- overwriteConfig , err := loadConfigFromWrapper ("." , configWrapper )
267- if err != nil {
268- log .Fatalf ("Error loading override config at index %d: %v" , index , err )
269- }
270-
271- Merge (& config , overwriteConfig )
272- }
273-
274- log .Infof ("Loaded config %s from %s with %d overrides" , LoadedConfig , DefaultConfigsPath , len (* configDefinition .Overrides ))
275- } else {
276- log .Infof ("Loaded config %s from %s" , LoadedConfig , DefaultConfigsPath )
277- }
278- } else {
279- log .Infof ("Loaded config from %s" , DefaultConfigPath )
280- }
281-
282- // Exchange kube context if necessary, but only if we don't load the base config
283- // we do this to avoid saving the kube context on commands like
284- // devspace add deployment && devspace add image etc.
285- if generatedConfig .CloudSpace != nil {
286- if config .Cluster == nil || (config .Cluster .KubeContext == nil && config .Cluster .APIServer == nil ) {
287- if generatedConfig .CloudSpace .KubeContext == "" {
288- log .Fatalf ("No space configured\n \n Please run: \n - `%s` to create a new space\n - `%s` to use an existing space\n - `%s` to list existing spaces" , ansi .Color ("devspace create space [NAME]" , "white+b" ), ansi .Color ("devspace use space [NAME]" , "white+b" ), ansi .Color ("devspace list spaces" , "white+b" ))
289- }
290-
291- config .Cluster = & latest.Cluster {
292- KubeContext : & generatedConfig .CloudSpace .KubeContext ,
293- }
294- }
295- }
296- } else {
297- if configDefinition != nil {
298- log .Infof ("Loaded config %s from %s" , LoadedConfig , DefaultConfigsPath )
299- } else {
300- log .Infof ("Loaded config %s" , DefaultConfigPath )
301- }
302- }
303-
304291 // Save generated config
305292 err = generated .SaveConfig (generatedConfig )
306293 if err != nil {
0 commit comments