@@ -32,8 +32,6 @@ type InitCmd struct {
3232 flags * InitCmdFlags
3333 workdir string
3434 chartGenerator * generator.ChartGenerator
35- config * v1.Config
36- overwriteConfig * v1.Config
3735 defaultImage * v1.ImageConfig
3836 defaultRegistry * v1.RegistryConfig
3937}
@@ -106,21 +104,26 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
106104 log .StartFileLogging ()
107105
108106 workdir , err := os .Getwd ()
109-
110107 if err != nil {
111108 log .Fatalf ("Unable to determine current workdir: %s" , err .Error ())
112109 }
113110
114111 cmd .workdir = workdir
115- configExists , _ := configutil .ConfigExists ()
116112
117- if configExists {
118- cmd .config = configutil .GetConfig (false )
113+ var config * v1.Config
114+
115+ configExists , _ := configutil .ConfigExists ()
116+ if configExists && cmd .flags .reconfigure == false {
117+ config = configutil .GetConfig ()
119118 } else {
120- cmd .config = configutil .GetConfigInstance ()
119+ // Delete config & overwrite config
120+ os .Remove (filepath .Join (workdir , configutil .ConfigPath ))
121+ os .Remove (filepath .Join (workdir , configutil .OverwriteConfigPath ))
122+
123+ config , _ = configutil .InitConfig ()
121124 }
122125
123- configutil .Merge (cmd . config , & v1.Config {
126+ configutil .Merge (config , & v1.Config {
124127 Version : configutil .String ("v1" ),
125128 DevSpace : & v1.DevSpaceConfig {
126129 Release : & v1.Release {
@@ -150,12 +153,11 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
150153 },
151154 },
152155 })
153- cmd .overwriteConfig = configutil .GetOverwriteConfig (false )
154156
155- imageMap := * cmd . config .Images
157+ imageMap := * config .Images
156158 cmd .defaultImage , _ = imageMap ["default" ]
157159
158- registryMap := * cmd . config .Registries
160+ registryMap := * config .Registries
159161 cmd .defaultRegistry , _ = registryMap ["default" ]
160162
161163 cmd .initChartGenerator ()
@@ -184,26 +186,16 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
184186 }
185187
186188 if cmd .flags .reconfigure || ! configExists {
187- if configExists {
188- // Delete config & overwrite config
189- os .Remove (filepath .Join (workdir , configutil .ConfigPath ))
190- os .Remove (filepath .Join (workdir , configutil .OverwriteConfigPath ))
191- }
192-
193189 cmd .configureKubernetes ()
194190 cmd .configureDevSpace ()
195191
196- cmd .defaultImage .Name = cmd .config .DevSpace .Release .Name
197-
192+ cmd .defaultImage .Name = config .DevSpace .Release .Name
198193 cmd .configureRegistry ()
199194
200195 err := configutil .SaveConfig ()
201-
202196 if err != nil {
203197 log .With (err ).Fatalf ("Config error: %s" , err .Error ())
204198 }
205-
206- _ = configutil .GetConfig (true )
207199 }
208200}
209201
@@ -225,71 +217,30 @@ func (cmd *InitCmd) initChartGenerator() {
225217}
226218
227219func (cmd * InitCmd ) configureDevSpace () {
228- _ , chartDirNotFound := os .Stat (cmd .workdir + "/chart" )
229- if chartDirNotFound == nil {
230- /*TODO
231- existingChartYaml := map[interface{}]interface{}{}
232- existingChartValuesYaml := map[interface{}]interface{}{}
233-
234- yamlutil.ReadYamlFromFile(cmd.workdir+"/chart/Chart.yaml", existingChartYaml)
235- yamlutil.ReadYamlFromFile(cmd.workdir+"/chart/values.yaml", existingChartValuesYaml)
236-
237- cmd.config.Release.Name = existingChartYaml["name"].(string)
238-
239- applicationValues, applicationValuesCorrect := existingChartValuesYaml["container"].(map[interface{}]interface{})
240- externalValues, externalValuesCorrect := existingChartValuesYaml["external"].(map[interface{}]interface{})
241-
242- if externalValuesCorrect {
243- value, isCorrect := externalValues["domain"].(string)
244-
245- if isCorrect {
246- cmd.appConfig.External.Domain = value
247- }
248- }*/
249- }
250-
251- /* cmd.config.DevSpace.Release.Name = stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
252- Question: "What is the name of your application?",
253- DefaultValue: *cmd.config.DevSpace.Release.Name,
254- ValidationRegexPattern: v1.Kubernetes.RegexPatterns.Name,
255- }) */
256-
257- /*
258- ports := strings.Split(*stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
259- Question: "Which port(s) does your application listen on? (separated by spaces)",
260- DefaultValue: "",
261- ValidationRegexPattern: "^([1-9][0-9]{0,4})?(\\s[1-9][0-9]{0,4})*?$",
262- }), " ")
263-
264- for _, port := range ports {
265- portInt, _ := strconv.Atoi(port)
266-
267- if portInt > 0 {
268- cmd.addPortForwarding(portInt)
269- }
270- }*/
271-
220+ config := configutil .GetConfig ()
272221 cmd .addDefaultSyncConfig ()
273222
274- if cmd . config .DevSpace .Release .Namespace == nil || len (* cmd . config .DevSpace .Release .Namespace ) == 0 {
275- cmd . config .DevSpace .Release .Namespace = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
223+ if config .DevSpace .Release .Namespace == nil || len (* config .DevSpace .Release .Namespace ) == 0 {
224+ config .DevSpace .Release .Namespace = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
276225 Question : "Which Kubernetes namespace should your application run in?" ,
277- DefaultValue : * cmd . config .DevSpace .Release .Namespace ,
226+ DefaultValue : * config .DevSpace .Release .Namespace ,
278227 ValidationRegexPattern : v1 .Kubernetes .RegexPatterns .Name ,
279228 })
280229 }
281230}
282231
283232func (cmd * InitCmd ) addPortForwarding (port int ) {
284- for _ , portForwarding := range * cmd .config .DevSpace .PortForwarding {
233+ config := configutil .GetConfig ()
234+
235+ for _ , portForwarding := range * config .DevSpace .PortForwarding {
285236 for _ , portMapping := range * portForwarding .PortMappings {
286237 if * portMapping .RemotePort == port {
287238 return
288239 }
289240 }
290241 }
291242
292- portForwarding := append (* cmd . config .DevSpace .PortForwarding , & v1.PortForwardingConfig {
243+ portForwarding := append (* config .DevSpace .PortForwarding , & v1.PortForwardingConfig {
293244 PortMappings : & []* v1.PortMapping {
294245 {
295246 LocalPort : & port ,
@@ -298,14 +249,17 @@ func (cmd *InitCmd) addPortForwarding(port int) {
298249 },
299250 ResourceType : configutil .String ("pod" ),
300251 LabelSelector : & map [string ]* string {
301- "release" : cmd . config .DevSpace .Release .Name ,
252+ "release" : config .DevSpace .Release .Name ,
302253 },
303254 })
304- cmd .config .DevSpace .PortForwarding = & portForwarding
255+
256+ config .DevSpace .PortForwarding = & portForwarding
305257}
306258
307259func (cmd * InitCmd ) addDefaultSyncConfig () {
308- for _ , syncPath := range * cmd .config .DevSpace .Sync {
260+ config := configutil .GetConfig ()
261+
262+ for _ , syncPath := range * config .DevSpace .Sync {
309263 if * syncPath .LocalSubPath == "./" || * syncPath .ContainerPath == "/app" {
310264 return
311265 }
@@ -324,19 +278,21 @@ func (cmd *InitCmd) addDefaultSyncConfig() {
324278 }
325279 }
326280
327- syncConfig := append (* cmd . config .DevSpace .Sync , & v1.SyncConfig {
281+ syncConfig := append (* config .DevSpace .Sync , & v1.SyncConfig {
328282 ContainerPath : configutil .String ("/app" ),
329283 LocalSubPath : configutil .String ("./" ),
330284 ResourceType : configutil .String ("pod" ),
331285 LabelSelector : & map [string ]* string {
332- "release" : cmd . config .DevSpace .Release .Name ,
286+ "release" : config .DevSpace .Release .Name ,
333287 },
334288 UploadExcludePaths : & uploadExcludePaths ,
335289 })
336- cmd .config .DevSpace .Sync = & syncConfig
290+
291+ config .DevSpace .Sync = & syncConfig
337292}
338293
339294func (cmd * InitCmd ) useCloudProvider () bool {
295+ config := configutil .GetConfig ()
340296 providerConfig , err := cloud .ParseCloudConfig ()
341297 if err != nil {
342298 log .Fatalf ("Error loading cloud config: %v" , err )
@@ -372,10 +328,10 @@ func (cmd *InitCmd) useCloudProvider() bool {
372328 ValidationRegexPattern : "^(yes)|(no)$" ,
373329 }) == "yes"
374330
375- cmd . config .Cluster .CloudProvider = & cloudProviderSelected
331+ config .Cluster .CloudProvider = & cloudProviderSelected
376332
377333 log .StartWait ("Logging into cloud provider " + providerConfig [cloudProviderSelected ].Host + cloud .LoginEndpoint + "..." )
378- err := cloud .Update (providerConfig , cmd . config , addToContext , true )
334+ err := cloud .Update (providerConfig , config , addToContext , true )
379335 log .StopWait ()
380336 if err != nil {
381337 log .Fatalf ("Couldn't authenticate to devspace cloud: %v" , err )
@@ -397,10 +353,10 @@ func (cmd *InitCmd) useCloudProvider() bool {
397353 ValidationRegexPattern : "^(yes)|(no)$" ,
398354 }) == "yes"
399355
400- cmd . config .Cluster .CloudProvider = configutil .String (cloud .DevSpaceCloudProviderName )
356+ config .Cluster .CloudProvider = configutil .String (cloud .DevSpaceCloudProviderName )
401357
402358 log .StartWait ("Logging into cloud provider " + providerConfig [cloud .DevSpaceCloudProviderName ].Host + cloud .LoginEndpoint + "..." )
403- err := cloud .Update (providerConfig , cmd . config , addToContext , true )
359+ err := cloud .Update (providerConfig , config , addToContext , true )
404360 log .StopWait ()
405361 if err != nil {
406362 log .Fatalf ("Couldn't authenticate to devspace cloud: %v" , err )
@@ -414,7 +370,8 @@ func (cmd *InitCmd) useCloudProvider() bool {
414370}
415371
416372func (cmd * InitCmd ) configureKubernetes () {
417- clusterConfig := cmd .config .Cluster
373+ config := configutil .GetConfig ()
374+ clusterConfig := config .Cluster
418375 useKubeConfig := false
419376
420377 // Check if devspace cloud should be used
@@ -487,6 +444,9 @@ func (cmd *InitCmd) configureKubernetes() {
487444}
488445
489446func (cmd * InitCmd ) configureRegistry () {
447+ config := configutil .GetConfig ()
448+ overwriteConfig := configutil .GetOverwriteConfig ()
449+
490450 dockerUsername := ""
491451 createInternalRegistryDefaultAnswer := "yes"
492452
@@ -509,7 +469,7 @@ func (cmd *InitCmd) configureRegistry() {
509469 }
510470 }
511471
512- internalRegistryConfig := cmd . config .Services .InternalRegistry
472+ internalRegistryConfig := config .Services .InternalRegistry
513473 createInternalRegistry := stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
514474 Question : "Should we create a private registry within your Kubernetes cluster for you? (yes | no)" ,
515475 DefaultValue : createInternalRegistryDefaultAnswer ,
@@ -543,6 +503,7 @@ func (cmd *InitCmd) configureRegistry() {
543503 }
544504 }
545505 }
506+
546507 googleRegistryRegex := regexp .MustCompile ("^(.+\\ .)?gcr.io$" )
547508 isGoogleRegistry := googleRegistryRegex .Match ([]byte (* registryURL ))
548509 isDockerHub := * registryURL == "hub.docker.com"
@@ -551,7 +512,7 @@ func (cmd *InitCmd) configureRegistry() {
551512 if cmd .defaultImage .Build .Engine .Docker != nil {
552513 log .Fatal ("Make sure you login to the registry with: docker login" + loginWarningServer )
553514 } else {
554- registryMapOverwrite := * cmd . overwriteConfig .Registries
515+ registryMapOverwrite := * overwriteConfig .Registries
555516 defaultRegistryOverwrite , defaultRegistryOverwriteDefined := registryMapOverwrite ["default" ]
556517
557518 if ! defaultRegistryOverwriteDefined {
@@ -619,7 +580,7 @@ func (cmd *InitCmd) configureRegistry() {
619580 }
620581 }
621582 } else {
622- imageMap := * cmd . config .Images
583+ imageMap := * config .Images
623584 defaultImageConf , defaultImageExists := imageMap ["default" ]
624585
625586 if defaultImageExists {
@@ -630,17 +591,17 @@ func (cmd *InitCmd) configureRegistry() {
630591 internalRegistryConfig = & v1.InternalRegistry {
631592 Release : & v1.Release {},
632593 }
633- cmd . config .Services .InternalRegistry = internalRegistryConfig
594+ config .Services .InternalRegistry = internalRegistryConfig
634595 }
635596
636597 if internalRegistryConfig .Release .Name == nil {
637598 internalRegistryConfig .Release .Name = configutil .String ("devspace-registry" )
638599 }
639600 if internalRegistryConfig .Release .Namespace == nil {
640- internalRegistryConfig .Release .Namespace = cmd . config .DevSpace .Release .Namespace
601+ internalRegistryConfig .Release .Namespace = config .DevSpace .Release .Namespace
641602 }
642603
643- overwriteRegistryMap := * cmd . overwriteConfig .Registries
604+ overwriteRegistryMap := * overwriteConfig .Registries
644605 overwriteRegistryConfig , overwriteRegistryConfigFound := overwriteRegistryMap ["internal" ]
645606
646607 if ! overwriteRegistryConfigFound {
@@ -761,7 +722,6 @@ func (cmd *InitCmd) determineLanguage() {
761722
762723func (cmd * InitCmd ) createChart () {
763724 err := cmd .chartGenerator .CreateChart ()
764-
765725 if err != nil {
766726 log .Fatalf ("Error while creating Helm chart and Dockerfile: %s" , err .Error ())
767727 }
0 commit comments