forked from gruntwork-io/helm-kubernetes-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s_service_template_render_helpers_for_test.go
167 lines (138 loc) · 6.64 KB
/
k8s_service_template_render_helpers_for_test.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//go:build all || tpl
// +build all tpl
// NOTE: We use build flags to differentiate between template tests and integration tests so that you can conveniently
// run just the template tests. See the test README for more information.
package test
import (
"path/filepath"
"testing"
"github.com/gruntwork-io/terratest/modules/helm"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
extv1beta1 "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
certapi "github.com/GoogleCloudPlatform/gke-managed-certs/pkg/apis/networking.gke.io/v1beta1"
)
func renderK8SServiceDeploymentWithSetValues(t *testing.T, setValues map[string]string) appsv1.Deployment {
helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)
// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
options := &helm.Options{
ValuesFiles: []string{filepath.Join("..", "charts", "k8s-service", "linter_values.yaml")},
SetValues: setValues,
}
// Render just the deployment resource
out := helm.RenderTemplate(t, options, helmChartPath, "deployment", []string{"templates/deployment.yaml"})
// Parse the deployment and return it
var deployment appsv1.Deployment
helm.UnmarshalK8SYaml(t, out, &deployment)
return deployment
}
func renderK8SServiceCanaryDeploymentWithSetValues(t *testing.T, setValues map[string]string) appsv1.Deployment {
helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)
// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
options := &helm.Options{
ValuesFiles: []string{filepath.Join("..", "charts", "k8s-service", "linter_values.yaml")},
SetValues: setValues,
}
// Render just the canary deployment resource
out := helm.RenderTemplate(t, options, helmChartPath, "canarydeployment", []string{"templates/canarydeployment.yaml"})
// Parse the canary deployment and return it
var canarydeployment appsv1.Deployment
helm.UnmarshalK8SYaml(t, out, &canarydeployment)
return canarydeployment
}
func renderK8SServiceIngressWithSetValues(t *testing.T, setValues map[string]string) networkingv1.Ingress {
helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)
// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
options := &helm.Options{
ValuesFiles: []string{filepath.Join("..", "charts", "k8s-service", "linter_values.yaml")},
SetValues: setValues,
}
// Render just the ingress resource
out := helm.RenderTemplate(t, options, helmChartPath, "ingress", []string{"templates/ingress.yaml"})
// Parse the ingress and return it
var ingress networkingv1.Ingress
helm.UnmarshalK8SYaml(t, out, &ingress)
return ingress
}
func renderK8SServiceIngressWithValuesFile(t *testing.T, valuesFilePath string) networkingv1.Ingress {
helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)
// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
options := &helm.Options{
ValuesFiles: []string{
filepath.Join("..", "charts", "k8s-service", "linter_values.yaml"),
valuesFilePath,
},
}
// Render just the ingress resource
out := helm.RenderTemplate(t, options, helmChartPath, "ingress", []string{"templates/ingress.yaml"})
// Parse the ingress and return it
var ingress networkingv1.Ingress
helm.UnmarshalK8SYaml(t, out, &ingress)
return ingress
}
func renderK8SServiceExtV1Beta1IngressWithSetValues(t *testing.T, setValues map[string]string) extv1beta1.Ingress {
helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)
// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
options := &helm.Options{
ValuesFiles: []string{filepath.Join("..", "charts", "k8s-service", "linter_values.yaml")},
SetValues: setValues,
}
// Render just the ingress resource
out := helm.RenderTemplate(t, options, helmChartPath, "ingress", []string{"templates/ingress.yaml"})
// Parse the ingress and return it
var ingress extv1beta1.Ingress
helm.UnmarshalK8SYaml(t, out, &ingress)
return ingress
}
func renderK8SServiceManagedCertificateWithSetValues(t *testing.T, setValues map[string]string) certapi.ManagedCertificate {
helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)
// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
options := &helm.Options{
ValuesFiles: []string{filepath.Join("..", "charts", "k8s-service", "linter_values.yaml")},
SetValues: setValues,
}
// Render just the google managed certificate resource
out := helm.RenderTemplate(t, options, helmChartPath, "gmc", []string{"templates/gmc.yaml"})
// Parse the google managed certificate and return it
var cert certapi.ManagedCertificate
helm.UnmarshalK8SYaml(t, out, &cert)
return cert
}
func renderK8SServiceAccountWithSetValues(t *testing.T, setValues map[string]string) corev1.ServiceAccount {
helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)
// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
options := &helm.Options{
ValuesFiles: []string{filepath.Join("..", "charts", "k8s-service", "linter_values.yaml")},
SetValues: setValues,
}
// Render just the service account resource
out := helm.RenderTemplate(t, options, helmChartPath, "serviceaccount", []string{"templates/serviceaccount.yaml"})
// Parse the service account and return it
var serviceaccount corev1.ServiceAccount
helm.UnmarshalK8SYaml(t, out, &serviceaccount)
return serviceaccount
}
func renderK8SServiceWithSetValues(t *testing.T, setValues map[string]string) corev1.Service {
helmChartPath, err := filepath.Abs(filepath.Join("..", "charts", "k8s-service"))
require.NoError(t, err)
// We make sure to pass in the linter_values.yaml values file, which we assume has all the required values defined.
options := &helm.Options{
ValuesFiles: []string{filepath.Join("..", "charts", "k8s-service", "linter_values.yaml")},
SetValues: setValues,
}
// Render just the service resource
out := helm.RenderTemplate(t, options, helmChartPath, "service", []string{"templates/service.yaml"})
// Parse the service and return it
var service corev1.Service
helm.UnmarshalK8SYaml(t, out, &service)
return service
}