@@ -172,7 +172,6 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
172172
173173 if cmd .flags .reconfigure || ! configExists {
174174 cmd .configureKubernetes ()
175- cmd .configureDevSpace ()
176175
177176 cmd .defaultImage .Name = config .DevSpace .Release .Name
178177 cmd .configureRegistry ()
@@ -203,42 +202,12 @@ func (cmd *InitCmd) initChartGenerator() {
203202
204203func (cmd * InitCmd ) configureDevSpace () {
205204 config := configutil .GetConfig ()
206- cmd .addDefaultSyncConfig ()
207205
208- if config .DevSpace .Release .Namespace == nil || len (* config .DevSpace .Release .Namespace ) == 0 {
209- config .DevSpace .Release .Namespace = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
210- Question : "Which Kubernetes namespace should your application run in?" ,
211- DefaultValue : * config .DevSpace .Release .Namespace ,
212- ValidationRegexPattern : v1 .Kubernetes .RegexPatterns .Name ,
213- })
214- }
215- }
216-
217- func (cmd * InitCmd ) addPortForwarding (port int ) {
218- config := configutil .GetConfig ()
219-
220- for _ , portForwarding := range * config .DevSpace .PortForwarding {
221- for _ , portMapping := range * portForwarding .PortMappings {
222- if * portMapping .RemotePort == port {
223- return
224- }
225- }
226- }
227-
228- portForwarding := append (* config .DevSpace .PortForwarding , & v1.PortForwardingConfig {
229- PortMappings : & []* v1.PortMapping {
230- {
231- LocalPort : & port ,
232- RemotePort : & port ,
233- },
234- },
235- ResourceType : configutil .String ("pod" ),
236- LabelSelector : & map [string ]* string {
237- "release" : config .DevSpace .Release .Name ,
238- },
206+ config .DevSpace .Release .Namespace = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
207+ Question : "Which Kubernetes namespace should your application run in?" ,
208+ DefaultValue : * config .DevSpace .Release .Namespace ,
209+ ValidationRegexPattern : v1 .Kubernetes .RegexPatterns .Name ,
239210 })
240-
241- config .DevSpace .PortForwarding = & portForwarding
242211}
243212
244213func (cmd * InitCmd ) addDefaultSyncConfig () {
@@ -360,72 +329,77 @@ func (cmd *InitCmd) configureKubernetes() {
360329 useKubeConfig := false
361330
362331 // Check if devspace cloud should be used
363- if cmd .useCloudProvider () {
364- return
365- }
332+ if cmd .useCloudProvider () == false {
333+ _ , err := os .Stat (clientcmd .RecommendedHomeFile )
334+ if err == nil {
335+ skipAnswer := stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
336+ Question : "Do you want to use your existing $HOME/.kube/config for Kubernetes access? (yes | no)" ,
337+ DefaultValue : "yes" ,
338+ ValidationRegexPattern : "^(yes)|(no)$" ,
339+ })
366340
367- _ , err := os .Stat (clientcmd .RecommendedHomeFile )
368- if err == nil {
369- skipAnswer := stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
370- Question : "Do you want to use your existing $HOME/.kube/config for Kubernetes access? (yes | no)" ,
371- DefaultValue : "yes" ,
372- ValidationRegexPattern : "^(yes)|(no)$" ,
373- })
341+ useKubeConfig = (* skipAnswer == "yes" )
342+ }
374343
375- useKubeConfig = (* skipAnswer == "yes" )
376- }
344+ if ! useKubeConfig {
345+ if clusterConfig .APIServer == nil {
346+ clusterConfig .APIServer = configutil .String ("https://192.168.99.100:8443" )
347+ }
377348
378- if ! useKubeConfig {
379- if clusterConfig .APIServer == nil {
380- clusterConfig .APIServer = configutil .String ("https://192.168.99.100:8443" )
381- }
382- clusterConfig .APIServer = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
383- Question : "What is your Kubernetes API Server URL? (e.g. https://127.0.0.1:8443)" ,
384- DefaultValue : * clusterConfig .APIServer ,
385- ValidationRegexPattern : "^https?://[a-z0-9-.]{0,99}:[0-9]{1,5}$" ,
386- })
349+ clusterConfig .APIServer = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
350+ Question : "What is your Kubernetes API Server URL? (e.g. https://127.0.0.1:8443)" ,
351+ DefaultValue : * clusterConfig .APIServer ,
352+ ValidationRegexPattern : "^https?://[a-z0-9-.]{0,99}:[0-9]{1,5}$" ,
353+ })
387354
388- if clusterConfig .CaCert == nil {
389- clusterConfig .CaCert = configutil .String ("" )
390- }
391- clusterConfig .CaCert = stdinutil .AskChangeQuestion (& stdinutil.GetFromStdinParams {
392- Question : "What is the CA Certificate of your API Server? (PEM)" ,
393- DefaultValue : * clusterConfig .CaCert ,
394- InputTerminationString : "-----END CERTIFICATE-----" ,
395- })
355+ if clusterConfig .CaCert == nil {
356+ clusterConfig .CaCert = configutil .String ("" )
357+ }
358+ clusterConfig .CaCert = stdinutil .AskChangeQuestion (& stdinutil.GetFromStdinParams {
359+ Question : "What is the CA Certificate of your API Server? (PEM)" ,
360+ DefaultValue : * clusterConfig .CaCert ,
361+ InputTerminationString : "-----END CERTIFICATE-----" ,
362+ })
396363
397- if clusterConfig .User == nil {
398- clusterConfig .User = & v1.ClusterUser {
399- ClientCert : configutil .String ("" ),
400- ClientKey : configutil .String ("" ),
364+ if clusterConfig .User == nil {
365+ clusterConfig .User = & v1.ClusterUser {
366+ ClientCert : configutil .String ("" ),
367+ ClientKey : configutil .String ("" ),
368+ }
369+ } else {
370+ if clusterConfig .User .ClientCert == nil {
371+ clusterConfig .User .ClientCert = configutil .String ("" )
372+ }
373+
374+ if clusterConfig .User .ClientKey == nil {
375+ clusterConfig .User .ClientKey = configutil .String ("" )
376+ }
401377 }
378+
379+ clusterConfig .User .ClientCert = stdinutil .AskChangeQuestion (& stdinutil.GetFromStdinParams {
380+ Question : "What is your Kubernetes client certificate? (PEM)" ,
381+ DefaultValue : * clusterConfig .User .ClientCert ,
382+ InputTerminationString : "-----END CERTIFICATE-----" ,
383+ })
384+
385+ clusterConfig .User .ClientKey = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
386+ Question : "What is your Kubernetes client key? (RSA, PEM)" ,
387+ DefaultValue : * clusterConfig .User .ClientKey ,
388+ InputTerminationString : "-----END RSA PRIVATE KEY-----" ,
389+ })
402390 } else {
403- if clusterConfig .User .ClientCert == nil {
404- clusterConfig .User .ClientCert = configutil .String ("" )
391+ currentContext , err := kubeconfig .GetCurrentContext ()
392+ if err != nil {
393+ log .Fatalf ("Couldn't determine current kubernetes context: %v" , err )
405394 }
406395
407- if clusterConfig .User .ClientKey == nil {
408- clusterConfig .User .ClientKey = configutil .String ("" )
409- }
410- }
411- clusterConfig .User .ClientCert = stdinutil .AskChangeQuestion (& stdinutil.GetFromStdinParams {
412- Question : "What is your Kubernetes client certificate? (PEM)" ,
413- DefaultValue : * clusterConfig .User .ClientCert ,
414- InputTerminationString : "-----END CERTIFICATE-----" ,
415- })
416- clusterConfig .User .ClientKey = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
417- Question : "What is your Kubernetes client key? (RSA, PEM)" ,
418- DefaultValue : * clusterConfig .User .ClientKey ,
419- InputTerminationString : "-----END RSA PRIVATE KEY-----" ,
420- })
421- } else {
422- currentContext , err := kubeconfig .GetCurrentContext ()
423- if err != nil {
424- log .Fatalf ("Couldn't determine current kubernetes context: %v" , err )
396+ clusterConfig .KubeContext = & currentContext
425397 }
426398
427- clusterConfig . KubeContext = & currentContext
399+ cmd . configureDevSpace ()
428400 }
401+
402+ cmd .addDefaultSyncConfig ()
429403}
430404
431405func (cmd * InitCmd ) configureRegistry () {
0 commit comments