Skip to content

Commit d8093cc

Browse files
authored
Merge pull request kubernetes#129053 from stlaz/e2e_ctb_parallel
e2e: ctb: make it possible to run the tests in parallel
2 parents afc4647 + c9bfc3b commit d8093cc

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

test/e2e/auth/projected_clustertrustbundle.go

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
mathrand "math/rand/v2"
3030
"os"
3131
"regexp"
32+
"strings"
3233
"time"
3334

3435
certificatesv1alpha1 "k8s.io/api/certificates/v1alpha1"
@@ -56,14 +57,13 @@ const (
5657
noSignerKey = "no-signer"
5758
)
5859

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() {
6161
f := framework.NewDefaultFramework("projected-clustertrustbundle")
6262
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
6363

6464
initCTBs, pemMapping := initCTBData()
6565

66-
ginkgo.JustBeforeEach(func(ctx context.Context) {
66+
ginkgo.BeforeEach(func(ctx context.Context) {
6767
cleanup := mustInitCTBs(ctx, f, initCTBs)
6868
ginkgo.DeferCleanup(cleanup)
6969
})
@@ -78,7 +78,7 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
7878
}{
7979
{
8080
name: "name of an existing CTB",
81-
ctbName: "test.test.signer-one.4",
81+
ctbName: "test.test.signer-one.4" + f.UniqueName,
8282
expectedOutput: expectedRegexFromPEMs(initCTBs[4].Spec.TrustBundle),
8383
},
8484
{
@@ -145,10 +145,11 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
145145
},
146146
} {
147147
ginkgo.It(tt.name, func(ctx context.Context) {
148+
signerName := tt.signerName + f.UniqueName
148149
pod := podForCTBProjection(v1.VolumeProjection{
149150
ClusterTrustBundle: &v1.ClusterTrustBundleProjection{
150151
Path: "trust-bundle.crt",
151-
SignerName: &tt.signerName,
152+
SignerName: &signerName,
152153
LabelSelector: tt.selector,
153154
Optional: tt.optionalVolume,
154155
},
@@ -172,7 +173,7 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
172173
ctb: &v1.ClusterTrustBundleProjection{
173174
Optional: ptr.To(false),
174175
Path: "trust-bundle.crt",
175-
SignerName: ptr.To(testSignerOneName),
176+
SignerName: ptr.To(testSignerOneName + f.UniqueName),
176177
LabelSelector: &metav1.LabelSelector{
177178
MatchLabels: map[string]string{
178179
"signer.alive": "unknown",
@@ -238,14 +239,14 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
238239
pod := podForCTBProjection(
239240
v1.VolumeProjection{
240241
ClusterTrustBundle: &v1.ClusterTrustBundleProjection{
241-
Name: ptr.To("test.test.signer-one.4"),
242+
Name: ptr.To("test.test.signer-one.4" + f.UniqueName),
242243
Path: "trust-anchors.pem",
243244
},
244245
},
245246
v1.VolumeProjection{
246247
ClusterTrustBundle: &v1.ClusterTrustBundleProjection{
247248
Path: "trust-bundle.crt",
248-
SignerName: ptr.To(testSignerOneName),
249+
SignerName: ptr.To(testSignerOneName + f.UniqueName),
249250
LabelSelector: &metav1.LabelSelector{
250251
MatchLabels: map[string]string{
251252
"signer.alive": "false",
@@ -269,17 +270,17 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
269270
var cleanups []func(ctx context.Context)
270271
var projections []v1.VolumeProjection
271272

272-
defer func() {
273+
ginkgo.DeferCleanup(func(ctx context.Context) {
273274
for _, c := range cleanups {
274275
c(ctx)
275276
}
276-
}()
277+
})
277278
for i := range numCTBs {
278279
ctb := ctbForCA(fmt.Sprintf("test.test:signer-hundreds:%d", i), "test.test/signer-hundreds", mustMakeCAPEM(fmt.Sprintf("root%d", i)), nil)
279280
initCTBs = append(initCTBs, ctb)
280281
cleanups = append(cleanups, mustCreateCTB(ctx, f, ctb))
281282
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)),
283284
Path: fmt.Sprintf("trust-anchors-%d.pem", i),
284285
},
285286
})
@@ -367,7 +368,7 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec
367368
pod := podForCTBProjection(v1.VolumeProjection{
368369
ClusterTrustBundle: &v1.ClusterTrustBundleProjection{
369370
Path: "trust-anchors.pem",
370-
SignerName: ptr.To("test.test/signer-hundreds"),
371+
SignerName: ptr.To("test.test/signer-hundreds" + f.UniqueName),
371372
LabelSelector: &metav1.LabelSelector{}, // == match everything
372373
},
373374
})
@@ -503,7 +504,7 @@ func mustInitCTBs(ctx context.Context, f *framework.Framework, ctbs []*certifica
503504
cleanups := []func(context.Context){}
504505
for _, ctb := range ctbs {
505506
ctb := ctb
506-
cleanups = append(cleanups, mustCreateCTB(ctx, f, ctb))
507+
cleanups = append(cleanups, mustCreateCTB(ctx, f, ctb.DeepCopy()))
507508
}
508509

509510
return func(ctx context.Context) {
@@ -514,6 +515,8 @@ func mustInitCTBs(ctx context.Context, f *framework.Framework, ctbs []*certifica
514515
}
515516

516517
func mustCreateCTB(ctx context.Context, f *framework.Framework, ctb *certificatesv1alpha1.ClusterTrustBundle) func(context.Context) {
518+
mutateCTBForTesting(ctb, f.UniqueName)
519+
517520
if _, err := f.ClientSet.CertificatesV1alpha1().ClusterTrustBundles().Create(ctx, ctb, metav1.CreateOptions{}); err != nil {
518521
framework.Failf("Error while creating ClusterTrustBundle: %v", err)
519522
}
@@ -588,3 +591,21 @@ func ctbsToPEMs(ctbs []*certificatesv1alpha1.ClusterTrustBundle) []string {
588591
}
589592
return certPEMs
590593
}
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

Comments
 (0)