@@ -13,14 +13,12 @@ import (
13
13
"net/url"
14
14
"path/filepath"
15
15
16
- batchv1 "k8s.io/api/batch/v1"
16
+ "github.com/openshift/cert-manager-operator/api/operator/v1alpha1"
17
+ "github.com/openshift/cert-manager-operator/test/library"
17
18
corev1 "k8s.io/api/core/v1"
18
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19
20
"k8s.io/client-go/dynamic"
20
21
"k8s.io/client-go/kubernetes"
21
- "k8s.io/utils/ptr"
22
-
23
- "github.com/openshift/cert-manager-operator/test/library"
24
22
25
23
. "github.com/onsi/ginkgo/v2"
26
24
. "github.com/onsi/gomega"
@@ -142,106 +140,16 @@ var _ = Describe("Istio-CSR", Ordered, Label("TechPreview", "Feature:IstioCSR"),
142
140
Expect (err ).Should (BeNil ())
143
141
144
142
By ("creating an grpcurl job" )
145
- job := & batchv1.Job {
146
- ObjectMeta : metav1.ObjectMeta {
147
- Name : "grpcurl-job" ,
148
- },
149
- Spec : batchv1.JobSpec {
150
- Completions : ptr .To (int32 (1 )),
151
- BackoffLimit : ptr .To (backOffLimit ),
152
- Template : corev1.PodTemplateSpec {
153
- ObjectMeta : metav1.ObjectMeta {
154
- Name : grpcAppName ,
155
- Labels : map [string ]string {
156
- "app" : grpcAppName ,
157
- },
158
- },
159
- Spec : corev1.PodSpec {
160
- ServiceAccountName : serviceAccountName ,
161
- AutomountServiceAccountToken : ptr .To (false ),
162
- RestartPolicy : corev1 .RestartPolicyOnFailure ,
163
- Containers : []corev1.Container {
164
- {
165
- Name : grpcAppName ,
166
- Image : "registry.redhat.io/rhel9/go-toolset" ,
167
- Command : []string {
168
- "/bin/sh" ,
169
- "-c" ,
170
- },
171
- Env : []corev1.EnvVar {
172
- {
173
- Name : "GOCACHE" ,
174
- Value : "/tmp/go-cache" ,
175
- },
176
- {
177
- Name : "GOPATH" ,
178
- Value : "/tmp/go" ,
179
- },
180
- },
181
- Args : []string {
182
- "go install github.com/fullstorydev/grpcurl/cmd/[email protected] >/dev/null 2>&1 && " +
183
- "TOKEN=$(cat /var/run/secrets/istio-ca/token) && " +
184
- "/tmp/go/bin/grpcurl " +
185
- "-import-path /proto " +
186
- "-proto /proto/ca.proto " +
187
- "-H \" Authorization: Bearer $TOKEN\" " +
188
- fmt .Sprintf ("-d '{\" csr\" : \" %s\" , \" validity_duration\" : 3600}' " , csr ) +
189
- "-cacert /etc/root-secret/ca.crt " +
190
- "-key /etc/root-secret/tls.key " +
191
- "-cert /etc/root-secret/tls.crt " +
192
- fmt .Sprintf ("%s istio.v1.auth.IstioCertificateService/CreateCertificate" , istioCSRGRPCEndpoint ),
193
- },
194
- VolumeMounts : []corev1.VolumeMount {
195
- {Name : "root-secret" , MountPath : "/etc/root-secret" },
196
- {Name : "proto" , MountPath : "/proto" },
197
- {Name : "sa-token" , MountPath : "/var/run/secrets/istio-ca" },
198
- },
199
- },
200
- },
201
- Volumes : []corev1.Volume {
202
- {
203
- Name : "sa-token" ,
204
- VolumeSource : corev1.VolumeSource {
205
- Projected : & corev1.ProjectedVolumeSource {
206
- DefaultMode : ptr .To (int32 (420 )),
207
- Sources : []corev1.VolumeProjection {
208
- {
209
- ServiceAccountToken : & corev1.ServiceAccountTokenProjection {
210
- Audience : "istio-ca" ,
211
- ExpirationSeconds : ptr .To (int64 (3600 )),
212
- Path : "token" ,
213
- },
214
- },
215
- },
216
- },
217
- },
218
- },
219
- {
220
- Name : "root-secret" ,
221
- VolumeSource : corev1.VolumeSource {
222
- Secret : & corev1.SecretVolumeSource {
223
- SecretName : "istiod-tls" ,
224
- },
225
- },
226
- },
227
- {
228
- Name : "proto" ,
229
- VolumeSource : corev1.VolumeSource {
230
- ConfigMap : & corev1.ConfigMapVolumeSource {
231
- LocalObjectReference : corev1.LocalObjectReference {
232
- Name : "proto-cm" ,
233
- },
234
- },
235
- },
236
- },
237
- },
238
- },
143
+ loader .CreateFromFile (AssetFunc (testassets .ReadFile ).WithTemplateValues (
144
+ IstioCSRGRPCurlJobConfig {
145
+ CertificateSigningRequest : csr ,
146
+ IstioCSRStatus : v1alpha1.IstioCSRStatus {
147
+ IstioCSRGRPCEndpoint : istioCSRGRPCEndpoint ,
148
+ ServiceAccount : serviceAccountName ,
239
149
},
240
150
},
241
- }
242
- _ , err = clientset .BatchV1 ().Jobs (ns .Name ).Create (context .TODO (), job , metav1.CreateOptions {})
243
- Expect (err ).Should (BeNil ())
244
- defer clientset .BatchV1 ().Jobs (ns .Name ).Delete (ctx , job .Name , metav1.DeleteOptions {})
151
+ ), filepath .Join ("testdata" , "istio" , "grpcurl_job.yaml" ), ns .Name )
152
+ defer loader .DeleteFromFile (testassets .ReadFile , filepath .Join ("testdata" , "istio" , "grpcurl_job.yaml" ), ns .Name )
245
153
246
154
By ("waiting for the job to be completed" )
247
155
err = pollTillJobCompleted (ctx , clientset , ns .Name , "grpcurl-job" )
0 commit comments