File tree Expand file tree Collapse file tree 4 files changed +44
-9
lines changed Expand file tree Collapse file tree 4 files changed +44
-9
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ porter mixin install kubernetes --version $VERSION --url https://github.com/getp
39
39
``` yaml
40
40
- kubernetes :
41
41
clientVersion : v1.15.5
42
+ namespaces :
43
+ - my-namespace-1
44
+ - my-namespace-2
42
45
` ` `
43
46
44
47
### Mixin Actions Syntax
@@ -52,7 +55,6 @@ install:
52
55
manifests :
53
56
- /cnab/app/manifests/hello
54
57
wait : true
55
-
56
58
` ` `
57
59
58
60
#### Upgrade Action
@@ -64,7 +66,6 @@ upgrade:
64
66
manifests :
65
67
- /cnab/app/manifests/hello
66
68
wait : true
67
-
68
69
` ` `
69
70
70
71
#### Uninstall Action
@@ -76,7 +77,6 @@ uninstall:
76
77
manifests :
77
78
- /cnab/app/manifests/hello
78
79
wait : true
79
-
80
80
` ` `
81
81
82
82
#### Outputs
@@ -85,9 +85,9 @@ The mixin supports extracting resource metadata from Kubernetes as outputs.
85
85
86
86
` ` ` yaml
87
87
outputs :
88
- - name : NAME
89
- resourceType : RESOURCE_TYPE
90
- resourceName : RESOURCE_TYPE_NAME
91
- namespace : NAMESPACE
92
- jsonPath : JSON_PATH_DEFINITION
88
+ - name : NAME
89
+ resourceType : RESOURCE_TYPE
90
+ resourceName : RESOURCE_TYPE_NAME
91
+ namespace : NAMESPACE
92
+ jsonPath : JSON_PATH_DEFINITION
93
93
` ` `
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package kubernetes
3
3
import (
4
4
"bytes"
5
5
"fmt"
6
+ "strings"
6
7
"text/template"
7
8
8
9
"get.porter.sh/porter/pkg/exec/builder"
@@ -24,7 +25,8 @@ chmod a+x /usr/local/bin/kubectl
24
25
)
25
26
26
27
type MixinConfig struct {
27
- ClientVersion string `yaml:"clientVersion,omitempty"`
28
+ ClientVersion string `yaml:"clientVersion,omitempty"`
29
+ Namespaces []string `yaml:"namespaces,omitempty"`
28
30
}
29
31
30
32
// BuildInput represents stdin passed to the mixin for the build command.
@@ -74,6 +76,16 @@ func (m *Mixin) Build() error {
74
76
return err
75
77
}
76
78
79
+ // Go through Namespaces if defined
80
+ if len (input .Config .Namespaces ) > 0 {
81
+ namespacesCommand , err := getNamespacesCommand (input .Config .Namespaces )
82
+ if err != nil && m .Debug {
83
+ fmt .Fprintf (m .Err , "DEBUG: addition of namespace failed: %s\n " , err .Error ())
84
+ } else {
85
+ fmt .Fprintf (m .Out , strings .Join (namespacesCommand , " " ))
86
+ }
87
+ }
88
+
77
89
return nil
78
90
}
79
91
Original file line number Diff line number Diff line change @@ -45,4 +45,21 @@ func TestMixin_Build(t *testing.T) {
45
45
gotOutput := m .TestContext .GetOutput ()
46
46
assert .Equal (t , wantOutput , gotOutput )
47
47
})
48
+
49
+ t .Run ("build with custom Kubernetes version" , func (t * testing.T ) {
50
+ b , err := ioutil .ReadFile ("testdata/build-input-with-namespaces.yaml" )
51
+ require .NoError (t , err )
52
+
53
+ m := NewTestMixin (t )
54
+ m .Debug = false
55
+ m .In = bytes .NewReader (b )
56
+ err = m .Build ()
57
+ require .NoError (t , err )
58
+
59
+ wantOutput := fmt .Sprintf (buildOutputTemplate , "v1.15.5" ) +
60
+ "\n RUN kubectl create namespace my-namespace-1 || true; kubectl create namespace my-namespace-2 || true; " +
61
+ "kubectl create namespace my-namespace-3 || true; kubectl create namespace my-namespace-4 || true;"
62
+ gotOutput := m .TestContext .GetOutput ()
63
+ assert .Equal (t , wantOutput , gotOutput )
64
+ })
48
65
}
Original file line number Diff line number Diff line change
1
+ config :
2
+ namespaces :
3
+ - my-namespace-1
4
+ - my-namespace-2
5
+ - my-namespace-3
6
+ - my-namespace-4
You can’t perform that action at this time.
0 commit comments