Skip to content

Commit 8adc2b2

Browse files
committed
Refactoring config & prepare kubectl deployment
1 parent 8a3a989 commit 8adc2b2

30 files changed

Lines changed: 173 additions & 128 deletions

File tree

cmd/add.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
"github.com/covexo/devspace/pkg/util/tar"
1515
"github.com/covexo/devspace/pkg/util/yamlutil"
1616

17-
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
18-
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
1917
"github.com/covexo/devspace/pkg/devspace/config/configutil"
2018
"github.com/covexo/devspace/pkg/devspace/config/v1"
19+
helmClient "github.com/covexo/devspace/pkg/devspace/deploy/helm"
20+
"github.com/covexo/devspace/pkg/devspace/kubectl"
2121
"github.com/covexo/devspace/pkg/util/log"
2222
"github.com/russross/blackfriday"
2323
"github.com/skratchdot/open-golang/open"

cmd/down.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cmd
22

33
import (
4-
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
5-
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
64
"github.com/covexo/devspace/pkg/devspace/config/configutil"
5+
helmClient "github.com/covexo/devspace/pkg/devspace/deploy/helm"
6+
"github.com/covexo/devspace/pkg/devspace/kubectl"
77
"github.com/covexo/devspace/pkg/util/log"
88

99
"github.com/spf13/cobra"

cmd/enter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cmd
22

33
import (
4-
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
5-
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
64
"github.com/covexo/devspace/pkg/devspace/config/configutil"
5+
helmClient "github.com/covexo/devspace/pkg/devspace/deploy/helm"
6+
"github.com/covexo/devspace/pkg/devspace/kubectl"
77
"github.com/covexo/devspace/pkg/util/log"
88
"github.com/spf13/cobra"
99
k8sv1 "k8s.io/api/core/v1"

cmd/init.go

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import (
66
"os/exec"
77
"path/filepath"
88
"regexp"
9-
"strconv"
109
"strings"
1110

1211
"github.com/covexo/devspace/pkg/util/kubeconfig"
1312

1413
"k8s.io/client-go/tools/clientcmd"
1514

16-
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
1715
"github.com/covexo/devspace/pkg/devspace/cloud"
16+
"github.com/covexo/devspace/pkg/devspace/kubectl"
1817

1918
"github.com/covexo/devspace/pkg/devspace/builder/docker"
2019

@@ -185,12 +184,17 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
185184
}
186185

187186
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+
188193
cmd.configureKubernetes()
189194
cmd.configureDevSpace()
190195

191196
cmd.defaultImage.Name = cmd.config.DevSpace.Release.Name
192197

193-
cmd.configureTiller()
194198
cmd.configureRegistry()
195199

196200
err := configutil.SaveConfig()
@@ -244,25 +248,27 @@ func (cmd *InitCmd) configureDevSpace() {
244248
}*/
245249
}
246250

247-
cmd.config.DevSpace.Release.Name = stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
251+
/* cmd.config.DevSpace.Release.Name = stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
248252
Question: "What is the name of your application?",
249253
DefaultValue: *cmd.config.DevSpace.Release.Name,
250254
ValidationRegexPattern: v1.Kubernetes.RegexPatterns.Name,
251-
})
255+
}) */
252256

253-
ports := strings.Split(*stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
254-
Question: "Which port(s) does your application listen on? (separated by spaces)",
255-
DefaultValue: "",
256-
ValidationRegexPattern: "^([1-9][0-9]{0,4})?(\\s[1-9][0-9]{0,4})*?$",
257-
}), " ")
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+
}), " ")
258263
259-
for _, port := range ports {
260-
portInt, _ := strconv.Atoi(port)
264+
for _, port := range ports {
265+
portInt, _ := strconv.Atoi(port)
266+
267+
if portInt > 0 {
268+
cmd.addPortForwarding(portInt)
269+
}
270+
}*/
261271

262-
if portInt > 0 {
263-
cmd.addPortForwarding(portInt)
264-
}
265-
}
266272
cmd.addDefaultSyncConfig()
267273

268274
if cmd.config.DevSpace.Release.Namespace == nil || len(*cmd.config.DevSpace.Release.Namespace) == 0 {
@@ -272,13 +278,6 @@ func (cmd *InitCmd) configureDevSpace() {
272278
ValidationRegexPattern: v1.Kubernetes.RegexPatterns.Name,
273279
})
274280
}
275-
276-
/* TODO
277-
cmd.appConfig.External.Domain = stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
278-
Question: "Which domain do you want to run your application on?",
279-
DefaultValue: cmd.appConfig.External.Domain,
280-
ValidationRegexPattern: "^([a-z0-9]([a-z0-9-]{0,120}[a-z0-9])?\\.)+[a-z0-9]{2,}$",
281-
})*/
282281
}
283282

284283
func (cmd *InitCmd) addPortForwarding(port int) {
@@ -337,21 +336,6 @@ func (cmd *InitCmd) addDefaultSyncConfig() {
337336
cmd.config.DevSpace.Sync = &syncConfig
338337
}
339338

340-
func (cmd *InitCmd) configureTiller() {
341-
tillerConfig := cmd.config.Services.Tiller
342-
tillerRelease := tillerConfig.Release
343-
344-
if tillerRelease.Namespace == nil || len(*tillerRelease.Namespace) == 0 {
345-
tillerRelease.Namespace = cmd.config.DevSpace.Release.Namespace
346-
347-
tillerRelease.Namespace = stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
348-
Question: "Which Kubernetes namespace should your tiller server run in?",
349-
DefaultValue: *tillerRelease.Namespace,
350-
ValidationRegexPattern: v1.Kubernetes.RegexPatterns.Name,
351-
})
352-
}
353-
}
354-
355339
func (cmd *InitCmd) useCloudProvider() bool {
356340
providerConfig, err := cloud.ParseCloudConfig()
357341
if err != nil {
@@ -389,10 +373,9 @@ func (cmd *InitCmd) useCloudProvider() bool {
389373
}) == "yes"
390374

391375
cmd.config.Cluster.CloudProvider = &cloudProviderSelected
392-
cmd.config.Cluster.UseKubeConfig = &addToContext
393376

394377
log.StartWait("Logging into cloud provider " + providerConfig[cloudProviderSelected].Host + cloud.LoginEndpoint + "...")
395-
err := cloud.Update(providerConfig, cmd.config, true)
378+
err := cloud.Update(providerConfig, cmd.config, addToContext, true)
396379
log.StopWait()
397380
if err != nil {
398381
log.Fatalf("Couldn't authenticate to devspace cloud: %v", err)
@@ -415,10 +398,9 @@ func (cmd *InitCmd) useCloudProvider() bool {
415398
}) == "yes"
416399

417400
cmd.config.Cluster.CloudProvider = configutil.String(cloud.DevSpaceCloudProviderName)
418-
cmd.config.Cluster.UseKubeConfig = &addToContext
419401

420402
log.StartWait("Logging into cloud provider " + providerConfig[cloud.DevSpaceCloudProviderName].Host + cloud.LoginEndpoint + "...")
421-
err := cloud.Update(providerConfig, cmd.config, true)
403+
err := cloud.Update(providerConfig, cmd.config, addToContext, true)
422404
log.StopWait()
423405
if err != nil {
424406
log.Fatalf("Couldn't authenticate to devspace cloud: %v", err)
@@ -451,7 +433,6 @@ func (cmd *InitCmd) configureKubernetes() {
451433
useKubeConfig = (*skipAnswer == "yes")
452434
}
453435

454-
clusterConfig.UseKubeConfig = configutil.Bool(useKubeConfig)
455436
if !useKubeConfig {
456437
if clusterConfig.APIServer == nil {
457438
clusterConfig.APIServer = configutil.String("https://192.168.99.100:8443")
@@ -527,6 +508,7 @@ func (cmd *InitCmd) configureRegistry() {
527508
}
528509
}
529510
}
511+
530512
internalRegistryConfig := cmd.config.Services.InternalRegistry
531513
createInternalRegistry := stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
532514
Question: "Should we create a private registry within your Kubernetes cluster for you? (yes | no)",
@@ -654,12 +636,11 @@ func (cmd *InitCmd) configureRegistry() {
654636
if internalRegistryConfig.Release.Name == nil {
655637
internalRegistryConfig.Release.Name = configutil.String("devspace-registry")
656638
}
657-
658639
if internalRegistryConfig.Release.Namespace == nil {
659640
internalRegistryConfig.Release.Namespace = cmd.config.DevSpace.Release.Namespace
660641
}
661-
overwriteRegistryMap := *cmd.overwriteConfig.Registries
662642

643+
overwriteRegistryMap := *cmd.overwriteConfig.Registries
663644
overwriteRegistryConfig, overwriteRegistryConfigFound := overwriteRegistryMap["internal"]
664645

665646
if !overwriteRegistryConfigFound {
@@ -668,8 +649,8 @@ func (cmd *InitCmd) configureRegistry() {
668649
}
669650
overwriteRegistryMap["internal"] = overwriteRegistryConfig
670651
}
671-
registryAuth := overwriteRegistryConfig.Auth
672652

653+
registryAuth := overwriteRegistryConfig.Auth
673654
if registryAuth.Username == nil {
674655
randomUserSuffix, err := randutil.GenerateRandomString(5)
675656

@@ -687,8 +668,8 @@ func (cmd *InitCmd) configureRegistry() {
687668
}
688669
registryAuth.Password = &randomPassword
689670
}
690-
var registryReleaseValues map[interface{}]interface{}
691671

672+
var registryReleaseValues map[interface{}]interface{}
692673
if internalRegistryConfig.Release.Values != nil {
693674
registryReleaseValues = *internalRegistryConfig.Release.Values
694675
} else {
@@ -723,21 +704,22 @@ func (cmd *InitCmd) configureRegistry() {
723704
log.Warn("Your Kubernetes cluster will not be able to pull images from a registry without a registry domain!\n")
724705
}
725706
}
726-
secrets, registryHasSecrets := registryReleaseValues["secrets"]
727707

708+
secrets, registryHasSecrets := registryReleaseValues["secrets"]
728709
if !registryHasSecrets {
729710
secrets = map[interface{}]interface{}{}
730711
registryReleaseValues["secrets"] = secrets
731712
}
732-
secretMap, secretsIsMap := secrets.(map[interface{}]interface{})
733713

714+
secretMap, secretsIsMap := secrets.(map[interface{}]interface{})
734715
if secretsIsMap {
735716
_, registryHasSecretHtpasswd := secretMap["htpasswd"]
736717

737718
if !registryHasSecretHtpasswd {
738719
secretMap["htpasswd"] = ""
739720
}
740721
}
722+
741723
internalRegistryConfig.Release.Values = &registryReleaseValues
742724
}
743725
}

cmd/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/covexo/devspace/pkg/util/envutil"
88
"github.com/covexo/devspace/pkg/util/log"
99

10-
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
10+
helmClient "github.com/covexo/devspace/pkg/devspace/deploy/helm"
1111

1212
"github.com/covexo/devspace/pkg/devspace/config/v1"
1313

cmd/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"strconv"
77
"strings"
88

9-
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
10-
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
119
"github.com/covexo/devspace/pkg/devspace/config/configutil"
1210
"github.com/covexo/devspace/pkg/devspace/config/v1"
11+
helmClient "github.com/covexo/devspace/pkg/devspace/deploy/helm"
12+
"github.com/covexo/devspace/pkg/devspace/kubectl"
1313
"github.com/covexo/devspace/pkg/util/log"
1414
"github.com/covexo/devspace/pkg/util/yamlutil"
1515
"github.com/spf13/cobra"

cmd/reset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"os"
55
"path"
66

7-
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
8-
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
7+
helmClient "github.com/covexo/devspace/pkg/devspace/deploy/helm"
8+
"github.com/covexo/devspace/pkg/devspace/kubectl"
99
"github.com/covexo/devspace/pkg/util/log"
1010
"github.com/covexo/devspace/pkg/util/stdinutil"
1111

cmd/status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"errors"
55
"fmt"
66

7-
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
8-
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
97
"github.com/covexo/devspace/pkg/devspace/config/configutil"
8+
helmClient "github.com/covexo/devspace/pkg/devspace/deploy/helm"
9+
"github.com/covexo/devspace/pkg/devspace/kubectl"
1010
"github.com/covexo/devspace/pkg/util/log"
1111
"github.com/daviddengcn/go-colortext"
1212
"github.com/spf13/cobra"

0 commit comments

Comments
 (0)