@@ -11,7 +11,7 @@ import (
1111
1212 "github.com/gruntwork-io/terratest/modules/helm"
1313 "github.com/stretchr/testify/assert"
14- "gopkg.in/yaml.v2 "
14+ "gopkg.in/yaml.v3 "
1515 appsv1 "k8s.io/api/apps/v1"
1616 corev1 "k8s.io/api/core/v1"
1717 rbacv1 "k8s.io/api/rbac/v1"
@@ -41,6 +41,7 @@ const (
4141var (
4242 // Generic variables.
4343 helmChartVersion = "0.0.0"
44+ helmChartValues = & chartValues {}
4445
4546 // Deployment variables.
4647 defaultDeploymentName = fmt .Sprintf ("%s-%s" , helmReleaseName , helmChartName )
5859 "app.kubernetes.io/name" : helmChartName ,
5960 "control-plane" : fmt .Sprintf ("%s-controller-manager" , helmReleaseName ),
6061 }
61- defaultDeploymentTemplateSpecLabels = map [string ]string {
62- "control-plane" : fmt .Sprintf ("%s-controller-manager" , helmReleaseName ),
63- }
6462 defaultDeploymentTerminationGracePeriodSeconds = int64 (10 )
65- defaultDeploymentTemplateVolumeName = "manager-config"
66- defaultDeploymentTemplateVolumeConfigMapName = fmt .Sprintf ("%s-manager-config" , helmReleaseName )
6763
6864 // RBAC variables.
6965 defaultRBACRoleName = fmt .Sprintf ("%s-leader-election-role" , helmReleaseName )
@@ -93,29 +89,63 @@ func init() {
9389 os .Exit (1 )
9490 }
9591
92+ if helmChartValues , err = getChartValues (); err != nil {
93+ log .Fatal (err )
94+ os .Exit (1 )
95+ }
96+
9697 defaultDeploymentLabels ["helm.sh/chart" ] = fmt .Sprintf ("%s-%s" , helmChartName , helmChartVersion )
9798 defaultDeploymentLabels ["app.kubernetes.io/version" ] = helmChartVersion
9899
99100 defaultServiceAccountLabels ["helm.sh/chart" ] = fmt .Sprintf ("%s-%s" , helmChartName , helmChartVersion )
100101 defaultServiceAccountLabels ["app.kubernetes.io/version" ] = helmChartVersion
101102}
102103
103- type Chart struct {
104+ // Chart.yaml
105+ type chart struct {
104106 Version string `yaml:"version"`
105107}
106108
109+ // values.yaml
110+ type chartValues struct {
111+ KubeRbacProxy kubeRbacProxy `yaml:"kubeRbacProxy"`
112+ }
113+
114+ type kubeRbacProxy struct {
115+ Image image `yaml:"image"`
116+ }
117+
118+ type image struct {
119+ Tag string `yaml:"tag"`
120+ Repository string `yaml:"repository"`
121+ }
122+
107123func getChartVersion () (string , error ) {
108124 file , err := os .ReadFile (fmt .Sprintf ("%s/Chart.yaml" , helmChartPath ))
109125 if err != nil {
110126 log .Fatalf ("Error reading Chart.yaml: %v" , err )
111127 }
112128
113- var chart Chart
114- if err := yaml .Unmarshal (file , & chart ); err != nil {
115- return "" , fmt .Errorf ("Error unmarshalling YAML: %v" , err )
129+ var c chart
130+ if err := yaml .Unmarshal (file , & c ); err != nil {
131+ return "" , fmt .Errorf ("error unmarshalling YAML: %v" , err )
132+ }
133+
134+ return c .Version , nil
135+ }
136+
137+ func getChartValues () (* chartValues , error ) {
138+ file , err := os .ReadFile (fmt .Sprintf ("%s/values.yaml" , helmChartPath ))
139+ if err != nil {
140+ log .Fatalf ("Error reading values.yaml: %v" , err )
141+ }
142+
143+ var cv chartValues
144+ if err := yaml .Unmarshal (file , & cv ); err != nil {
145+ return nil , fmt .Errorf ("error unmarshalling YAML: %v" , err )
116146 }
117147
118- return chart . Version , nil
148+ return & cv , nil
119149}
120150
121151func renderDeploymentManifest (t * testing.T , options * helm.Options ) appsv1.Deployment {
0 commit comments