Skip to content

Commit f643de1

Browse files
committed
replaces grpcurl job struct with loader file
1 parent b7dc226 commit f643de1

File tree

3 files changed

+79
-102
lines changed

3 files changed

+79
-102
lines changed

test/e2e/config_template.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package e2e
55

66
import (
77
"bytes"
8+
"github.com/openshift/cert-manager-operator/api/operator/v1alpha1"
89
"text/template"
910
)
1011

@@ -19,6 +20,12 @@ type CertificateConfig struct {
1920
DNSName string
2021
}
2122

23+
// IstioCSRConfig customizes the fields in a job spec
24+
type IstioCSRGRPCurlJobConfig struct {
25+
CertificateSigningRequest string
26+
IstioCSRStatus v1alpha1.IstioCSRStatus
27+
}
28+
2229
// replaceWithTemplate puts field values from a template struct
2330
func replaceWithTemplate(sourceFileContents string, templatedValues any) ([]byte, error) {
2431
tmpl, err := template.New("template").Parse(sourceFileContents)

test/e2e/istio_csr_test.go

Lines changed: 10 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ import (
1313
"net/url"
1414
"path/filepath"
1515

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"
1718
corev1 "k8s.io/api/core/v1"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920
"k8s.io/client-go/dynamic"
2021
"k8s.io/client-go/kubernetes"
21-
"k8s.io/utils/ptr"
22-
23-
"github.com/openshift/cert-manager-operator/test/library"
2422

2523
. "github.com/onsi/ginkgo/v2"
2624
. "github.com/onsi/gomega"
@@ -142,106 +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-
},
143+
loader.CreateFromFile(AssetFunc(testassets.ReadFile).WithTemplateValues(
144+
IstioCSRGRPCurlJobConfig{
145+
CertificateSigningRequest: csr,
146+
IstioCSRStatus: v1alpha1.IstioCSRStatus{
147+
IstioCSRGRPCEndpoint: istioCSRGRPCEndpoint,
148+
ServiceAccount: serviceAccountName,
239149
},
240150
},
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)
245153

246154
By("waiting for the job to be completed")
247155
err = pollTillJobCompleted(ctx, clientset, ns.Name, "grpcurl-job")
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: grpcurl-istio-csr
5+
spec:
6+
backoffLimit: 10
7+
completions: 1
8+
template:
9+
metadata:
10+
labels:
11+
app: grpcurl-istio-csr
12+
name: grpcurl-istio-csr
13+
spec:
14+
automountServiceAccountToken: false
15+
containers:
16+
- args:
17+
- |
18+
go install github.com/fullstorydev/grpcurl/cmd/[email protected] >/dev/null 2>&1 && \
19+
TOKEN=$(cat /var/run/secrets/istio-ca/token) && \
20+
/tmp/go/bin/grpcurl \
21+
-import-path /proto \
22+
-proto /proto/ca.proto \
23+
-H "Authorization: Bearer $TOKEN" \
24+
-d '{"csr": "{{.CertificateSigningRequest}}", "validity_duration": 3600}' \
25+
-cacert /etc/root-secret/ca.crt \
26+
-key /etc/root-secret/tls.key \
27+
-cert /etc/root-secret/tls.crt \
28+
{{.IstioCSRStatus.IstioCSRGRPCEndpoint}} istio.v1.auth.IstioCertificateService/CreateCertificate
29+
command:
30+
- /bin/sh
31+
- -c
32+
env:
33+
- name: GOCACHE
34+
value: /tmp/go-cache
35+
- name: GOPATH
36+
value: /tmp/go
37+
image: registry.redhat.io/rhel9/go-toolset
38+
name: grpcurl
39+
volumeMounts:
40+
- mountPath: /etc/root-secret
41+
name: root-secret
42+
- mountPath: /proto
43+
name: proto
44+
- mountPath: /var/run/secrets/istio-ca
45+
name: sa-token
46+
restartPolicy: OnFailure
47+
serviceAccountName: '{{.IstioCSRStatus.ServiceAccount}}'
48+
volumes:
49+
- name: sa-token
50+
projected:
51+
defaultMode: 420
52+
sources:
53+
- serviceAccountToken:
54+
audience: istio-ca
55+
expirationSeconds: 3600
56+
path: token
57+
- name: root-secret
58+
secret:
59+
secretName: istiod-tls
60+
- configMap:
61+
name: proto-cm
62+
name: proto

0 commit comments

Comments
 (0)