Skip to content

Commit b96a0a7

Browse files
committed
Initial Implementation of kubectl deploy
1 parent e43d191 commit b96a0a7

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,50 @@
11
package kubectl
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/covexo/devspace/pkg/util/yamlutil"
7+
8+
"k8s.io/client-go/kubernetes"
9+
)
10+
11+
// Deploy deploys all specified manifests via kubectl apply and adds to the specified image names the corresponding tags
12+
func Deploy(client *kubernetes.Clientset, namespace string, images []string, tags map[string]string, manifests []string) error {
13+
for _, pattern := range manifests {
14+
files, err := filepath.Glob(pattern)
15+
if err != nil {
16+
return err
17+
}
18+
19+
for _, file := range files {
20+
err = applyFile(client, file, namespace, images, tags)
21+
if err != nil {
22+
return err
23+
}
24+
}
25+
}
26+
27+
return nil
28+
}
29+
30+
func applyFile(client *kubernetes.Clientset, file string, namespace string, images []string, tags map[string]string) error {
31+
y := make(map[interface{}]interface{})
32+
yamlutil.ReadYamlFromFile(file, y)
33+
34+
match := func(key, value string) bool {
35+
return false
36+
}
37+
38+
replace := func(value string) string {
39+
return ""
40+
}
41+
42+
Walk(y, match, replace)
43+
44+
//changedManifest, err := yaml.Marshal(y)
45+
//if err != nil {
46+
// return err
47+
//}
48+
49+
return nil
50+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package kubectl
2+
3+
// ReplaceFn defines the replace function
4+
type ReplaceFn func(value string) string
5+
6+
// MatchFn defines the match function
7+
type MatchFn func(key, value string) bool
8+
9+
// Walk walks over an interface and replaces keys that match the match function with the replace function
10+
func Walk(d interface{}, match MatchFn, replace ReplaceFn) {
11+
switch t := d.(type) {
12+
case map[interface{}]interface{}:
13+
for k, v := range t {
14+
key := k.(string)
15+
value, ok := v.(string)
16+
if ok == false {
17+
Walk(v, match, replace)
18+
continue
19+
}
20+
21+
if match(key, value) {
22+
t[k] = replace(value)
23+
}
24+
}
25+
case []interface{}:
26+
for _, val := range t {
27+
Walk(val, match, replace)
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)