This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 388
/
config.go
89 lines (71 loc) · 2.3 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package framework
import (
"fmt"
"io/ioutil"
"path/filepath"
"gopkg.in/yaml.v2"
)
// TestConfig holds configuration for the test suite
type TestConfig struct {
Kubeconfig string
KubeContext string
KubeNamespace string
EnableMultiCluster bool
SecondaryKubeconfig string
SecondaryKubeContext string
SecondaryKubeNamespace string
EnableEnterprise bool
EnterpriseLicenseSecretName string
EnterpriseLicenseSecretKey string
EnableOpenshift bool
ConsulImage string
ConsulK8SImage string
NoCleanupOnFailure bool
DebugDirectory string
}
// HelmValuesFromConfig returns a map of Helm values
// that includes any non-empty values from the TestConfig
func (t *TestConfig) HelmValuesFromConfig() (map[string]string, error) {
helmValues := map[string]string{}
// Set the enterprise image first if enterprise tests are enabled.
// It can be overwritten by the -consul-image flag later.
if t.EnableEnterprise {
entImage, err := t.entImage()
if err != nil {
return nil, err
}
setIfNotEmpty(helmValues, "global.image", entImage)
}
if t.EnterpriseLicenseSecretName != "" && t.EnterpriseLicenseSecretKey != "" {
setIfNotEmpty(helmValues, "server.enterpriseLicense.secretName", t.EnterpriseLicenseSecretName)
setIfNotEmpty(helmValues, "server.enterpriseLicense.secretKey", t.EnterpriseLicenseSecretKey)
}
// todo add tests
if t.EnableOpenshift {
setIfNotEmpty(helmValues, "global.openshift.enabled", "true")
}
setIfNotEmpty(helmValues, "global.image", t.ConsulImage)
setIfNotEmpty(helmValues, "global.imageK8S", t.ConsulK8SImage)
return helmValues, nil
}
// entImage parses out consul version from Chart.yaml
// and sets global.image to the consul enterprise image with that version.
func (t *TestConfig) entImage() (string, error) {
// Unmarshal Chart.yaml to get appVersion (i.e. Consul version)
chart, err := ioutil.ReadFile(filepath.Join(helmChartPath, "Chart.yaml"))
if err != nil {
return "", err
}
var chartMap map[string]interface{}
err = yaml.Unmarshal(chart, &chartMap)
if err != nil {
return "", err
}
return fmt.Sprintf("hashicorp/consul-enterprise:%s-ent", chartMap["appVersion"]), nil
}
// setIfNotEmpty sets key to val in map m if value is not empty
func setIfNotEmpty(m map[string]string, key, val string) {
if val != "" {
m[key] = val
}
}