Skip to content

Commit d0f8c87

Browse files
author
Otávio Fernandes
committed
Kubernetes related configuration.
1 parent 062718a commit d0f8c87

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pkg/vault-handler/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ type Config struct {
1313
VaultToken string // vault token
1414
VaultRoleID string // vault approle role-id
1515
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
1620
}
1721

1822
// Validate configuration object.
@@ -35,6 +39,19 @@ func (c *Config) Validate() error {
3539
if c.OutputDir != "" && !isDir(c.OutputDir) {
3640
return fmt.Errorf("output-dir '%s' is not found", c.OutputDir)
3741
}
42+
return nil
43+
}
3844

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+
}
3956
return nil
4057
}

pkg/vault-handler/config_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
func TestConfigValidate(t *testing.T) {
1010
config := &Config{}
11+
1112
err := config.Validate()
1213
assert.NotNil(t, err)
1314

@@ -18,3 +19,23 @@ func TestConfigValidate(t *testing.T) {
1819
err = config.Validate()
1920
assert.Nil(t, err)
2021
}
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+
}

0 commit comments

Comments
 (0)