@@ -13,12 +13,10 @@ import (
1313 "net/url"
1414 "path/filepath"
1515
16- batchv1 "k8s.io/api/batch/v1"
1716 corev1 "k8s.io/api/core/v1"
1817 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1918 "k8s.io/client-go/dynamic"
2019 "k8s.io/client-go/kubernetes"
21- "k8s.io/utils/ptr"
2220
2321 "github.com/openshift/cert-manager-operator/test/library"
2422
@@ -74,7 +72,7 @@ var _ = Describe("Istio-CSR", Ordered, Label("TechPreview", "Feature:IstioCSR"),
7472 Context ("grpc call istio.v1.auth.IstioCertificateService/CreateCertificate to istio-csr agent" , func () {
7573 It ("should return cert-chain as response" , func () {
7674 serviceAccountName := "cert-manager-istio-csr"
77- grpcAppName := "grpcurl"
75+ grpcAppName := "grpcurl-istio-csr "
7876
7977 By ("creating cluster issuer" )
8078 loader .CreateFromFile (testassets .ReadFile , filepath .Join ("testdata" , "self_signed" , "cluster_issuer.yaml" ), ns .Name )
@@ -115,7 +113,7 @@ var _ = Describe("Istio-CSR", Ordered, Label("TechPreview", "Feature:IstioCSR"),
115113 err = pollTillDeploymentAvailable (ctx , clientset , ns .Name , "cert-manager-istio-csr" )
116114 Expect (err ).Should (BeNil ())
117115
118- istioCSRGRPCEndpoint , err := pollTillIstioCSRAvailable (ctx , dynamicClient , ns .Name , "default" )
116+ istioCSRStatus , err := pollTillIstioCSRAvailable (ctx , dynamicClient , ns .Name , "default" )
119117 Expect (err ).Should (BeNil ())
120118
121119 By ("poll till the service account is available" )
@@ -142,109 +140,16 @@ var _ = Describe("Istio-CSR", Ordered, Label("TechPreview", "Feature:IstioCSR"),
142140 Expect (err ).Should (BeNil ())
143141
144142 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- },
239- },
143+ loader .CreateFromFile (AssetFunc (testassets .ReadFile ).WithTemplateValues (
144+ IstioCSRGRPCurlJobConfig {
145+ CertificateSigningRequest : csr ,
146+ IstioCSRStatus : istioCSRStatus ,
240147 },
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 {})
148+ ), filepath .Join ("testdata" , "istio" , "grpcurl_job.yaml" ), ns .Name )
149+ defer loader .DeleteFromFile (testassets .ReadFile , filepath .Join ("testdata" , "istio" , "grpcurl_job.yaml" ), ns .Name )
245150
246151 By ("waiting for the job to be completed" )
247- err = pollTillJobCompleted (ctx , clientset , ns .Name , "grpcurl-job" )
152+ err = pollTillJobCompleted (ctx , clientset , ns .Name , grpcAppName )
248153 Expect (err ).Should (BeNil ())
249154
250155 By ("fetching logs of the grpcurl job" )
0 commit comments