Skip to content

Commit 44da812

Browse files
committed
further improve conformance test binary
Signed-off-by: Tim Ramlot <[email protected]>
1 parent b52870a commit 44da812

File tree

16 files changed

+186
-169
lines changed

16 files changed

+186
-169
lines changed

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,20 @@ $(BINDIR)/conformance.test: | $(NEEDS_GINKGO)
165165
test: test-unit-deps | $(NEEDS_GO) $(NEEDS_GOTESTSUM) ## Run unit tests.
166166
$(GOTESTSUM) ./... -coverprofile cover.out
167167

168-
# $(GOTESTSUM) ./internal/testsetups/simple/e2e/... -coverprofile cover.out -timeout 5m
169-
170168
.PHONY: test-e2e
171169
test-e2e: test-e2e-deps | $(NEEDS_GOTESTSUM) $(NEEDS_GINKGO) $(BINDIR)/conformance.test ## Run e2e tests. This creates a Kind cluster, installs dependencies, deploys the issuer-lib and runs the E2E tests.
172-
170+
$(GOTESTSUM) ./internal/testsetups/simple/e2e/... -coverprofile cover.out -timeout 5m
173171

174-
kubectl apply -f internal/testsetups/simple/example/simple-cluster-issuer.yaml
172+
kubectl create ns cm-conformance-test || true
173+
kubectl -n cm-conformance-test apply -f internal/testsetups/simple/example/simple-issuer.yaml
174+
kubectl -n cm-conformance-test apply -f internal/testsetups/simple/example/simple-cluster-issuer.yaml
175175

176176
$(GINKGO) -procs=10 run $(BINDIR)/conformance.test -- \
177+
--namespace=cm-conformance-test \
178+
--cm-issuers=testing.cert-manager.io/SimpleIssuer/simple-issuer \
177179
--cm-issuers=testing.cert-manager.io/SimpleClusterIssuer/simple-cluster-issuer \
178180
--k8s-issuers=simpleclusterissuers.testing.cert-manager.io/simple-cluster-issuer \
179-
--unsupported-features=SaveCAToSecret \
181+
--unsupported-features=SaveCAToSecret
180182

181183
##@ Build
182184

api/v1alpha1/issuer_interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Issuer interface {
3535
// issuer type for a Kubernetes CertificateSigningRequest resource based
3636
// on the issuerName field. The value should be formatted as follows:
3737
// "<issuer resource (plural)>.<issuer group>". For example, the value
38-
// "simpleclusterissuers.issuer.cert-manager.io" will match all CSRs
39-
// with an issuerName set to eg. "simpleclusterissuers.issuer.cert-manager.io/issuer1".
38+
// "simpleclusterissuers.testing.cert-manager.io" will match all CSRs
39+
// with an issuerName set to eg. "simpleclusterissuers.testing.cert-manager.io/issuer1".
4040
GetIssuerTypeIdentifier() string
4141
}

conformance/certificates/suite.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ type Suite struct {
4444
// created with this issuer reference.
4545
IssuerRef cmmeta.ObjectReference
4646

47+
// Namespace is the namespace in which the Certificate resources will be
48+
// created.
49+
Namespace string
50+
4751
// DomainSuffix is a suffix used on all domain requests.
4852
// This is useful when the issuer being tested requires special
4953
// configuration for a set of domains in order for certificates to be
@@ -72,6 +76,10 @@ func (s *Suite) complete(f *framework.Framework) {
7276
Fail("IssuerRef must be set")
7377
}
7478

79+
if s.Namespace == "" {
80+
Fail("Namespace must be set")
81+
}
82+
7583
if s.DomainSuffix == "" {
7684
s.DomainSuffix = "example.com"
7785
}

conformance/certificates/tests.go

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/types"
3535
"k8s.io/client-go/util/retry"
36+
"sigs.k8s.io/controller-runtime/pkg/client"
3637

3738
"conformance/framework"
3839
"conformance/framework/helper/featureset"
@@ -49,7 +50,16 @@ import (
4950
// automatically called.
5051
func (s *Suite) Define() {
5152
Describe("with issuer type "+s.Name, func() {
52-
f := framework.NewFramework("certificates", s.KubeClientConfig)
53+
f := framework.NewFramework(
54+
"certificates",
55+
s.KubeClientConfig,
56+
s.Namespace,
57+
[]client.Object{
58+
&cmapi.Certificate{},
59+
&cmapi.CertificateRequest{},
60+
&corev1.Secret{},
61+
},
62+
)
5363

5464
sharedIPAddress := "127.0.0.1"
5565

@@ -371,14 +381,26 @@ func (s *Suite) Define() {
371381

372382
defineTest := func(test testCase) {
373383
s.it(f, test.name, func(ctx context.Context, issuerRef cmmeta.ObjectReference) {
384+
randomTestID := e2eutil.RandStringRunes(10)
374385
certificate := &cmapi.Certificate{
375386
ObjectMeta: metav1.ObjectMeta{
376-
Name: "testcert",
377-
Namespace: f.Namespace.Name,
387+
Name: "e2e-conformance-" + randomTestID,
388+
Namespace: f.Namespace,
389+
Labels: map[string]string{
390+
f.CleanupLabel: "true",
391+
},
392+
Annotations: map[string]string{
393+
"conformance.cert-manager.io/test-name": s.Name + " " + test.name,
394+
},
378395
},
379396
Spec: cmapi.CertificateSpec{
380-
SecretName: "testcert-tls",
397+
SecretName: "e2e-conformance-tls-" + randomTestID,
381398
IssuerRef: issuerRef,
399+
SecretTemplate: &cmapi.CertificateSecretTemplate{
400+
Labels: map[string]string{
401+
f.CleanupLabel: "true",
402+
},
403+
},
382404
},
383405
}
384406

@@ -407,15 +429,27 @@ func (s *Suite) Define() {
407429
}
408430

409431
s.it(f, "should issue another certificate with the same private key if the existing certificate and CertificateRequest are deleted", func(ctx context.Context, issuerRef cmmeta.ObjectReference) {
432+
randomTestID := e2eutil.RandStringRunes(10)
410433
testCertificate := &cmapi.Certificate{
411434
ObjectMeta: metav1.ObjectMeta{
412-
Name: "testcert",
413-
Namespace: f.Namespace.Name,
435+
Name: "e2e-conformance-" + randomTestID,
436+
Namespace: f.Namespace,
437+
Labels: map[string]string{
438+
f.CleanupLabel: "true",
439+
},
440+
Annotations: map[string]string{
441+
"conformance.cert-manager.io/test-name": s.Name + " should issue another certificate with the same private key if the existing certificate and CertificateRequest are deleted",
442+
},
414443
},
415444
Spec: cmapi.CertificateSpec{
416-
SecretName: "testcert-tls",
445+
SecretName: "e2e-conformance-tls-" + randomTestID,
417446
DNSNames: []string{e2eutil.RandomSubdomain(s.DomainSuffix)},
418447
IssuerRef: issuerRef,
448+
SecretTemplate: &cmapi.CertificateSecretTemplate{
449+
Labels: map[string]string{
450+
f.CleanupLabel: "true",
451+
},
452+
},
419453
},
420454
}
421455
By("Creating a Certificate")
@@ -431,7 +465,7 @@ func (s *Suite) Define() {
431465
Expect(err).NotTo(HaveOccurred())
432466

433467
By("Deleting existing certificate data in Secret")
434-
sec, err := f.KubeClientSet.CoreV1().Secrets(f.Namespace.Name).
468+
sec, err := f.KubeClientSet.CoreV1().Secrets(f.Namespace).
435469
Get(ctx, testCertificate.Spec.SecretName, metav1.GetOptions{})
436470
Expect(err).NotTo(HaveOccurred(), "failed to get secret containing signed certificate key pair data")
437471

@@ -442,11 +476,11 @@ func (s *Suite) Define() {
442476

443477
sec.Data[corev1.TLSCertKey] = []byte{}
444478

445-
_, err = f.KubeClientSet.CoreV1().Secrets(f.Namespace.Name).Update(ctx, sec, metav1.UpdateOptions{})
479+
_, err = f.KubeClientSet.CoreV1().Secrets(f.Namespace).Update(ctx, sec, metav1.UpdateOptions{})
446480
Expect(err).NotTo(HaveOccurred(), "failed to update secret by deleting the signed certificate data")
447481

448482
By("Waiting for the Certificate to re-issue a certificate")
449-
sec, err = f.Helper().WaitForSecretCertificateData(ctx, sec.Name, f.Namespace.Name, time.Minute*8)
483+
sec, err = f.Helper().WaitForSecretCertificateData(ctx, sec.Name, f.Namespace, time.Minute*8)
450484
Expect(err).NotTo(HaveOccurred(), "failed to wait for secret to have a valid 2nd certificate")
451485

452486
crtPEM2 := sec.Data[corev1.TLSCertKey]
@@ -463,15 +497,27 @@ func (s *Suite) Define() {
463497
}, featureset.ReusePrivateKeyFeature, featureset.OnlySAN)
464498

465499
s.it(f, "should allow updating an existing certificate with a new DNS Name", func(ctx context.Context, issuerRef cmmeta.ObjectReference) {
500+
randomTestID := e2eutil.RandStringRunes(10)
466501
testCertificate := &cmapi.Certificate{
467502
ObjectMeta: metav1.ObjectMeta{
468-
Name: "testcert",
469-
Namespace: f.Namespace.Name,
503+
Name: "e2e-conformance-" + randomTestID,
504+
Namespace: f.Namespace,
505+
Labels: map[string]string{
506+
f.CleanupLabel: "true",
507+
},
508+
Annotations: map[string]string{
509+
"conformance.cert-manager.io/test-name": s.Name + " should allow updating an existing certificate with a new DNS Name",
510+
},
470511
},
471512
Spec: cmapi.CertificateSpec{
472-
SecretName: "testcert-tls",
513+
SecretName: "e2e-conformance-tls-" + randomTestID,
473514
DNSNames: []string{e2eutil.RandomSubdomain(s.DomainSuffix)},
474515
IssuerRef: issuerRef,
516+
SecretTemplate: &cmapi.CertificateSecretTemplate{
517+
Labels: map[string]string{
518+
f.CleanupLabel: "true",
519+
},
520+
},
475521
},
476522
}
477523
validations := validation.CertificateSetForUnsupportedFeatureSet(s.UnsupportedFeatures)

conformance/certificatesigningrequests/tests.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
corev1 "k8s.io/api/core/v1"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/utils/pointer"
32+
"sigs.k8s.io/controller-runtime/pkg/client"
3233

3334
"conformance/framework"
3435
"conformance/framework/helper/featureset"
@@ -49,7 +50,14 @@ import (
4950
// they are not active, these tests will fail.
5051
func (s *Suite) Define() {
5152
Describe("CertificateSigningRequest with issuer type "+s.Name, func() {
52-
f := framework.NewFramework("certificatesigningrequests", s.KubeClientConfig)
53+
f := framework.NewFramework(
54+
"certificatesigningrequests",
55+
s.KubeClientConfig,
56+
"",
57+
[]client.Object{
58+
&certificatesv1.CertificateSigningRequest{},
59+
},
60+
)
5361

5462
sharedIPAddress := "127.0.0.1"
5563
sharedURI, err := url.Parse("spiffe://cluster.local/ns/sandbox/sa/foo")
@@ -435,17 +443,33 @@ func (s *Suite) Define() {
435443
},
436444
}
437445

446+
addAnnotation := func(annotations map[string]string, key, value string) map[string]string {
447+
if annotations == nil {
448+
annotations = map[string]string{}
449+
}
450+
annotations[key] = value
451+
return annotations
452+
}
453+
438454
defineTest := func(test testCase) {
439455
s.it(f, test.name, func(ctx context.Context, signerName string) {
440456
// Generate request CSR
441457
csr, key, err := gen.CSR(test.keyAlgo, test.csrModifiers...)
442458
Expect(err).NotTo(HaveOccurred())
443459

444460
// Create CertificateSigningRequest
461+
randomTestID := e2eutil.RandStringRunes(10)
445462
kubeCSR := &certificatesv1.CertificateSigningRequest{
446463
ObjectMeta: metav1.ObjectMeta{
447-
GenerateName: "e2e-conformance-",
448-
Annotations: test.kubeCSRAnnotations,
464+
Name: "e2e-conformance-" + randomTestID,
465+
Labels: map[string]string{
466+
f.CleanupLabel: "true",
467+
},
468+
Annotations: addAnnotation(
469+
test.kubeCSRAnnotations,
470+
"conformance.cert-manager.io/test-name",
471+
s.Name+" "+test.name,
472+
),
449473
},
450474
Spec: certificatesv1.CertificateSigningRequestSpec{
451475
Request: csr,
@@ -458,9 +482,6 @@ func (s *Suite) Define() {
458482
// Create the request, and delete at the end of the test
459483
By("Creating a CertificateSigningRequest")
460484
Expect(f.CRClient.Create(ctx, kubeCSR)).NotTo(HaveOccurred())
461-
DeferCleanup(func(ctx context.Context) {
462-
Expect(f.CRClient.Delete(ctx, kubeCSR)).NotTo(HaveOccurred())
463-
})
464485

465486
// Approve the request for testing, so that cert-manager may sign the
466487
// request.

conformance/conformance_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ func (i *arrayFlags) Set(value string) error {
2626
return nil
2727
}
2828

29+
var namespace string
2930
var unsupportedFeatures arrayFlags
30-
3131
var cmIssuerReferences arrayFlags
3232
var k8sIssuerReferences arrayFlags
3333

3434
func init() {
35+
flag.StringVar(&namespace, "namespace", "", "list of issuer references to use for conformance tests")
3536
flag.Var(&unsupportedFeatures, "unsupported-features", "list of features that are not supported by this invocation of the test suite")
3637
flag.Var(&cmIssuerReferences, "cm-issuers", "list of issuer references to use for conformance tests")
3738
flag.Var(&k8sIssuerReferences, "k8s-issuers", "list of issuer references to use for conformance tests")
@@ -71,6 +72,7 @@ func TestConformance(t *testing.T) {
7172
(&certificates.Suite{
7273
KubeClientConfig: restConfig,
7374
Name: ref,
75+
Namespace: namespace,
7476
IssuerRef: parseCMReference(g, ref),
7577
UnsupportedFeatures: unsupportedFeatureSet,
7678
}).Define()

0 commit comments

Comments
 (0)