File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ type Config struct {
13
13
VaultToken string // vault token
14
14
VaultRoleID string // vault approle role-id
15
15
VaultSecretID string // vault approle secret-id
16
+ InCluster bool // kubernetes in-cluster
17
+ Context string // kubernetes context
18
+ Namespace string // kubernetes namespace
19
+ KubeConfig string // kubernetes config
16
20
}
17
21
18
22
// Validate configuration object.
@@ -35,6 +39,19 @@ func (c *Config) Validate() error {
35
39
if c .OutputDir != "" && ! isDir (c .OutputDir ) {
36
40
return fmt .Errorf ("output-dir '%s' is not found" , c .OutputDir )
37
41
}
42
+ return nil
43
+ }
38
44
45
+ // ValidateKubernetes configuration related to Kubernetes.
46
+ func (c * Config ) ValidateKubernetes () error {
47
+ if c .InCluster && c .Context != "" {
48
+ return fmt .Errorf ("configuration 'context' cannot be used in combination with 'in-cluster'" )
49
+ }
50
+ if c .Namespace == "" {
51
+ return fmt .Errorf ("namespace is not informed" )
52
+ }
53
+ if c .KubeConfig != "" && ! fileExists (c .KubeConfig ) {
54
+ return fmt .Errorf ("can't find kube-config file at '%s'" , c .KubeConfig )
55
+ }
39
56
return nil
40
57
}
Original file line number Diff line number Diff line change 8
8
9
9
func TestConfigValidate (t * testing.T ) {
10
10
config := & Config {}
11
+
11
12
err := config .Validate ()
12
13
assert .NotNil (t , err )
13
14
@@ -18,3 +19,23 @@ func TestConfigValidate(t *testing.T) {
18
19
err = config .Validate ()
19
20
assert .Nil (t , err )
20
21
}
22
+
23
+ func TestConfigValidateKubernetes (t * testing.T ) {
24
+ config := & Config {}
25
+
26
+ err := config .ValidateKubernetes ()
27
+ assert .NotNil (t , err )
28
+
29
+ config .InCluster = true
30
+ config .Context = "context"
31
+
32
+ err = config .ValidateKubernetes ()
33
+ assert .NotNil (t , err )
34
+
35
+ config .InCluster = false
36
+ config .Namespace = "namespace"
37
+ config .KubeConfig = "../../test/manifest.yaml"
38
+
39
+ err = config .ValidateKubernetes ()
40
+ assert .Nil (t , err )
41
+ }
You can’t perform that action at this time.
0 commit comments