Skip to content

Commit 1c6d92c

Browse files
committed
Fix init issues
1 parent 99b8285 commit 1c6d92c

3 files changed

Lines changed: 81 additions & 111 deletions

File tree

cmd/init.go

Lines changed: 63 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -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

204203
func (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

244213
func (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

431405
func (cmd *InitCmd) configureRegistry() {

pkg/devspace/deploy/helm/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewClient(kubectlClient *kubernetes.Clientset, upgradeTiller bool) (*HelmCl
5757
tunnelWaitTime := 2 * 60 * time.Second
5858
tunnelCheckInterval := 5 * time.Second
5959

60-
log.StartWait("Waiting for tiller to become ready")
60+
log.StartWait("Waiting for " + tillerNamespace + "/tiller-deploy to become ready")
6161
defer log.StopWait()
6262

6363
// Next we wait till we can establish a tunnel to the running pod
@@ -88,7 +88,6 @@ func NewClient(kubectlClient *kubernetes.Clientset, upgradeTiller bool) (*HelmCl
8888

8989
for helmWaitTime > 0 {
9090
_, tillerError = client.ListReleases(k8shelm.ReleaseListLimit(1))
91-
9291
if tillerError == nil || helmWaitTime < 0 {
9392
break
9493
}

pkg/devspace/deploy/helm/rbac.go

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,26 @@ func createTillerRBAC(kubectlClient *kubernetes.Clientset, dsConfig *v1.Config)
3838
}
3939
}
4040

41-
tillerConfig := dsConfig.Services.Tiller
42-
if tillerConfig != nil {
43-
// Tiller does need full access to all namespaces is should deploy to and therefore we create the roles & rolebindings
44-
appNamespaces := []*string{
45-
dsConfig.DevSpace.Release.Namespace,
46-
}
41+
// Tiller does need full access to all namespaces is should deploy to and therefore we create the roles & rolebindings
42+
appNamespaces := []*string{
43+
dsConfig.DevSpace.Release.Namespace,
44+
}
4745

48-
// Check if there is an internal registry
49-
if dsConfig.Services.InternalRegistry != nil && dsConfig.Services.InternalRegistry.Release != nil && dsConfig.Services.InternalRegistry.Release.Namespace != nil {
50-
// Tiller needs access to the internal registry namespace
51-
appNamespaces = append(appNamespaces, dsConfig.Services.InternalRegistry.Release.Namespace)
52-
}
46+
// Check if there is an internal registry
47+
if dsConfig.Services.InternalRegistry != nil && dsConfig.Services.InternalRegistry.Release != nil && dsConfig.Services.InternalRegistry.Release.Namespace != nil {
48+
// Tiller needs access to the internal registry namespace
49+
appNamespaces = append(appNamespaces, dsConfig.Services.InternalRegistry.Release.Namespace)
50+
}
5351

54-
if tillerConfig.AppNamespaces != nil {
55-
appNamespaces = append(appNamespaces, *tillerConfig.AppNamespaces...)
56-
}
52+
if dsConfig.Services.Tiller != nil && dsConfig.Services.Tiller.AppNamespaces != nil {
53+
appNamespaces = append(appNamespaces, *dsConfig.Services.Tiller.AppNamespaces...)
54+
}
5755

58-
// Persist the app namespaces to the config
59-
for _, appNamespace := range appNamespaces {
60-
err = addDeployAccessToTiller(kubectlClient, tillerNamespace, *appNamespace)
61-
if err != nil {
62-
return err
63-
}
56+
// Persist the app namespaces to the config
57+
for _, appNamespace := range appNamespaces {
58+
err = addDeployAccessToTiller(kubectlClient, tillerNamespace, *appNamespace)
59+
if err != nil {
60+
return err
6461
}
6562
}
6663

0 commit comments

Comments
 (0)