Skip to content

Commit 231daff

Browse files
committed
Fix issue kubectl deployment method
1 parent 328b4e1 commit 231daff

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

pkg/devspace/deploy/kubectl/kubectl.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ func New(kubectl *kubernetes.Clientset, deployConfig *v1.DeploymentConfig, log l
4040
context = *config.Cluster.KubeContext
4141
}
4242

43-
namespace := ""
44-
if deployConfig.Namespace != nil {
43+
namespace, err := configutil.GetDefaultNamespace(config)
44+
if err != nil {
45+
return nil, err
46+
}
47+
if deployConfig.Namespace != nil && *deployConfig.Namespace != "" {
4548
namespace = *deployConfig.Namespace
4649
}
4750

@@ -73,6 +76,7 @@ func (d *DeployConfig) Status() ([][]string, error) {
7376

7477
// Delete deletes all matched manifests from kubernetes
7578
func (d *DeployConfig) Delete() error {
79+
d.Log.StartWait("Loading manifests")
7680
manifests, err := loadManifests(d.Manifests, d.Log)
7781
if err != nil {
7882
return err
@@ -92,11 +96,14 @@ func (d *DeployConfig) Delete() error {
9296
cmd.Stdout = d.Log
9397
cmd.Stderr = d.Log
9498

99+
d.Log.StartWait("Deleting manifests with kubectl")
100+
defer d.Log.StopWait()
95101
return cmd.Run()
96102
}
97103

98104
// Deploy deploys all specified manifests via kubectl apply and adds to the specified image names the corresponding tags
99105
func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy bool) error {
106+
d.Log.StartWait("Loading manifests")
100107
manifests, err := loadManifests(d.Manifests, d.Log)
101108
if err != nil {
102109
return err
@@ -120,19 +127,20 @@ func (d *DeployConfig) Deploy(generatedConfig *generated.Config, forceDeploy boo
120127
cmd.Stdout = d.Log
121128
cmd.Stderr = d.Log
122129

130+
d.Log.StartWait("Applying manifests with kubectl")
131+
defer d.Log.StopWait()
123132
return cmd.Run()
124133
}
125134

126135
func (d *DeployConfig) getCmdArgs(method string, additionalArgs ...string) []string {
127136
args := []string{}
128137

129-
if d.Namespace != "" {
130-
args = append(args, "-n", d.Namespace)
131-
}
132-
133138
if d.Context != "" {
134139
args = append(args, "--context", d.Context)
135140
}
141+
if d.Namespace != "" {
142+
args = append(args, "-n", d.Namespace)
143+
}
136144

137145
args = append(args, method)
138146

@@ -160,5 +168,5 @@ func replaceManifest(manifest Manifest, tags map[string]string) {
160168
return value + ":" + tags[value]
161169
}
162170

163-
Walk(manifest, match, replace)
171+
Walk(map[interface{}]interface{}(manifest), match, replace)
164172
}

pkg/devspace/deploy/kubectl/manifests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func getManifestsFromFile(filepath string) ([]Manifest, error) {
7575
manifest = strings.TrimLeft(manifest, "\r\n")
7676
manifest = strings.TrimRight(manifest, "\r\n")
7777

78-
manifestData := Manifest{}
78+
manifestData := make(map[interface{}]interface{})
7979

80-
err = yaml.Unmarshal([]byte(manifest), manifestData)
80+
err = yaml.Unmarshal([]byte(manifest), &manifestData)
8181
if err != nil {
8282
return nil, err
8383
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package kubectl
22

3+
import "github.com/covexo/devspace/pkg/util/log"
4+
35
// ReplaceFn defines the replace function
46
type ReplaceFn func(value string) string
57

@@ -9,22 +11,25 @@ type MatchFn func(key, value string) bool
911
// Walk walks over an interface and replaces keys that match the match function with the replace function
1012
func Walk(d interface{}, match MatchFn, replace ReplaceFn) {
1113
switch t := d.(type) {
14+
case []interface{}:
15+
for _, val := range t {
16+
Walk(val, match, replace)
17+
}
1218
case map[interface{}]interface{}:
1319
for k, v := range t {
1420
key := k.(string)
1521
value, ok := v.(string)
1622
if ok == false {
23+
log.Infof("Key %s is no string", key)
24+
1725
Walk(v, match, replace)
1826
continue
1927
}
2028

29+
log.Infof("Key %s is string", key)
2130
if match(key, value) {
2231
t[k] = replace(value)
2332
}
2433
}
25-
case []interface{}:
26-
for _, val := range t {
27-
Walk(val, match, replace)
28-
}
2934
}
3035
}

0 commit comments

Comments
 (0)