@@ -29,6 +29,7 @@ import (
29
29
mathrand "math/rand/v2"
30
30
"os"
31
31
"regexp"
32
+ "strings"
32
33
"time"
33
34
34
35
certificatesv1alpha1 "k8s.io/api/certificates/v1alpha1"
@@ -56,14 +57,13 @@ const (
56
57
noSignerKey = "no-signer"
57
58
)
58
59
59
- // TODO: running the tests in parallel should be possible
60
- var _ = SIGDescribe (feature .ClusterTrustBundle , feature .ClusterTrustBundleProjection , framework .WithSerial (), func () {
60
+ var _ = SIGDescribe (feature .ClusterTrustBundle , feature .ClusterTrustBundleProjection , func () {
61
61
f := framework .NewDefaultFramework ("projected-clustertrustbundle" )
62
62
f .NamespacePodSecurityLevel = admissionapi .LevelBaseline
63
63
64
64
initCTBs , pemMapping := initCTBData ()
65
65
66
- ginkgo .JustBeforeEach (func (ctx context.Context ) {
66
+ ginkgo .BeforeEach (func (ctx context.Context ) {
67
67
cleanup := mustInitCTBs (ctx , f , initCTBs )
68
68
ginkgo .DeferCleanup (cleanup )
69
69
})
@@ -78,7 +78,7 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
78
78
}{
79
79
{
80
80
name : "name of an existing CTB" ,
81
- ctbName : "test.test.signer-one.4" ,
81
+ ctbName : "test.test.signer-one.4" + f . UniqueName ,
82
82
expectedOutput : expectedRegexFromPEMs (initCTBs [4 ].Spec .TrustBundle ),
83
83
},
84
84
{
@@ -145,10 +145,11 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
145
145
},
146
146
} {
147
147
ginkgo .It (tt .name , func (ctx context.Context ) {
148
+ signerName := tt .signerName + f .UniqueName
148
149
pod := podForCTBProjection (v1.VolumeProjection {
149
150
ClusterTrustBundle : & v1.ClusterTrustBundleProjection {
150
151
Path : "trust-bundle.crt" ,
151
- SignerName : & tt . signerName ,
152
+ SignerName : & signerName ,
152
153
LabelSelector : tt .selector ,
153
154
Optional : tt .optionalVolume ,
154
155
},
@@ -172,7 +173,7 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
172
173
ctb : & v1.ClusterTrustBundleProjection {
173
174
Optional : ptr .To (false ),
174
175
Path : "trust-bundle.crt" ,
175
- SignerName : ptr .To (testSignerOneName ),
176
+ SignerName : ptr .To (testSignerOneName + f . UniqueName ),
176
177
LabelSelector : & metav1.LabelSelector {
177
178
MatchLabels : map [string ]string {
178
179
"signer.alive" : "unknown" ,
@@ -238,14 +239,14 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
238
239
pod := podForCTBProjection (
239
240
v1.VolumeProjection {
240
241
ClusterTrustBundle : & v1.ClusterTrustBundleProjection {
241
- Name : ptr .To ("test.test.signer-one.4" ),
242
+ Name : ptr .To ("test.test.signer-one.4" + f . UniqueName ),
242
243
Path : "trust-anchors.pem" ,
243
244
},
244
245
},
245
246
v1.VolumeProjection {
246
247
ClusterTrustBundle : & v1.ClusterTrustBundleProjection {
247
248
Path : "trust-bundle.crt" ,
248
- SignerName : ptr .To (testSignerOneName ),
249
+ SignerName : ptr .To (testSignerOneName + f . UniqueName ),
249
250
LabelSelector : & metav1.LabelSelector {
250
251
MatchLabels : map [string ]string {
251
252
"signer.alive" : "false" ,
@@ -269,17 +270,17 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
269
270
var cleanups []func (ctx context.Context )
270
271
var projections []v1.VolumeProjection
271
272
272
- defer func () {
273
+ ginkgo . DeferCleanup ( func (ctx context. Context ) {
273
274
for _ , c := range cleanups {
274
275
c (ctx )
275
276
}
276
- }( )
277
+ })
277
278
for i := range numCTBs {
278
279
ctb := ctbForCA (fmt .Sprintf ("test.test:signer-hundreds:%d" , i ), "test.test/signer-hundreds" , mustMakeCAPEM (fmt .Sprintf ("root%d" , i )), nil )
279
280
initCTBs = append (initCTBs , ctb )
280
281
cleanups = append (cleanups , mustCreateCTB (ctx , f , ctb ))
281
282
projections = append (projections , v1.VolumeProjection {ClusterTrustBundle : & v1.ClusterTrustBundleProjection { // TODO: maybe mount them all to a single pod?
282
- Name : ptr .To (fmt .Sprintf ("test.test:signer-hundreds:%d" , i )),
283
+ Name : ptr .To (fmt .Sprintf ("test.test:signer-hundreds%s :%d" , f . UniqueName , i )),
283
284
Path : fmt .Sprintf ("trust-anchors-%d.pem" , i ),
284
285
},
285
286
})
@@ -367,7 +368,7 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
367
368
pod := podForCTBProjection (v1.VolumeProjection {
368
369
ClusterTrustBundle : & v1.ClusterTrustBundleProjection {
369
370
Path : "trust-anchors.pem" ,
370
- SignerName : ptr .To ("test.test/signer-hundreds" ),
371
+ SignerName : ptr .To ("test.test/signer-hundreds" + f . UniqueName ),
371
372
LabelSelector : & metav1.LabelSelector {}, // == match everything
372
373
},
373
374
})
@@ -503,7 +504,7 @@ func mustInitCTBs(ctx context.Context, f *framework.Framework, ctbs []*certifica
503
504
cleanups := []func (context.Context ){}
504
505
for _ , ctb := range ctbs {
505
506
ctb := ctb
506
- cleanups = append (cleanups , mustCreateCTB (ctx , f , ctb ))
507
+ cleanups = append (cleanups , mustCreateCTB (ctx , f , ctb . DeepCopy () ))
507
508
}
508
509
509
510
return func (ctx context.Context ) {
@@ -514,6 +515,8 @@ func mustInitCTBs(ctx context.Context, f *framework.Framework, ctbs []*certifica
514
515
}
515
516
516
517
func mustCreateCTB (ctx context.Context , f * framework.Framework , ctb * certificatesv1alpha1.ClusterTrustBundle ) func (context.Context ) {
518
+ mutateCTBForTesting (ctb , f .UniqueName )
519
+
517
520
if _ , err := f .ClientSet .CertificatesV1alpha1 ().ClusterTrustBundles ().Create (ctx , ctb , metav1.CreateOptions {}); err != nil {
518
521
framework .Failf ("Error while creating ClusterTrustBundle: %v" , err )
519
522
}
@@ -588,3 +591,21 @@ func ctbsToPEMs(ctbs []*certificatesv1alpha1.ClusterTrustBundle) []string {
588
591
}
589
592
return certPEMs
590
593
}
594
+
595
+ // mutateCTBForTesting mutates the .spec.signerName and .name so that the created cluster
596
+ // objects are unique and the tests can run in parallel
597
+ func mutateCTBForTesting (ctb * certificatesv1alpha1.ClusterTrustBundle , uniqueName string ) {
598
+ signer := ctb .Spec .SignerName
599
+ if len (signer ) == 0 {
600
+ ctb .Name += uniqueName
601
+ return
602
+ }
603
+
604
+ newSigner := ctb .Spec .SignerName + uniqueName
605
+ ctb .Name = strings .Replace (ctb .Name , signerNameToCTBName (signer ), signerNameToCTBName (newSigner ), 1 )
606
+ ctb .Spec .SignerName = newSigner
607
+ }
608
+
609
+ func signerNameToCTBName (signerName string ) string {
610
+ return strings .ReplaceAll (signerName , "/" , ":" )
611
+ }
0 commit comments