Repository navigation
fix(e2e): give each SelfSigned CSR spec its own Secret - #9320
cert-manager-prow[bot] merged 1 commit into
Conversation
The two ClusterIssuer specs in the "CertificateSigningRequests SelfSigned
Secret" suite both created cert-manager/selfsigned-test, with the name and
the namespace hard-coded. make/e2e.sh runs ginkgo with nodes=40 and
--randomize-all, so the two sometimes run at the same time on different
processes, and the second fails with:
secrets "selfsigned-test" already exists
The Secret has to live in the cluster resource namespace, because that is
where a ClusterIssuer resolves the private-key-secret-name annotation, and
the framework does not randomise that namespace. Randomising the name is
the only part we control, so generate it per spec in JustBeforeEach and use
the same value in the annotation.
Generating it there rather than at tree-construction time also means a
retry gets a fresh name. The spec that loses holds the Secret for about a
second, so a retry that reuses the same name is certain to lose again.
Two Secret creates also discarded their error, so only one of the two specs
could report the collision at all. client-go's generic Create returns a
non-nil zero object alongside the error (gentype/type.go:244), so the
losing spec carried on with a nameless Secret, waited 20s for a signature
that never came, and then failed teardown with "resource name may not be
empty". Collisions that went that way looked nothing like a 409, which
makes the flake rarer in the record than it is in reality. Both creates now
assert.
The two Issuer specs keep the fixed name. They write into the framework's
per-spec namespace, so their names are already unique.
Signed-off-by: Richard Wall <[email protected]>
|
/test pull-cert-manager-master-e2e-v1-34 |
| // resource namespace, which the framework does not randomise, so a | ||
| // fixed name would make them collide when Ginkgo runs them in | ||
| // parallel. | ||
| secretName = "selfsigned-test-" + rand.String(10) |
There was a problem hiding this comment.
I tend to use GenerateName instead of rand in tests, but that only works with a real control plane, such as envtest or a real cluster. Can we use it here and read out the name after the secret is created? It is a matter of preference, so not a blocker.
There was a problem hiding this comment.
Good idea, and there is a direct precedent for it that I should acknowledge: suite/conformance/certificatesigningrequests/selfsigned/selfsigned.go#L68 does exactly this — GenerateName, same annotation, same cluster resource namespace, name read back off the created object.
It does not quite work here though, and the reason is ordering rather than preference.
The ClusterIssuer: private key Secret is updated with a valid private key… spec creates the Secret first and the CSR afterwards, so GenerateName would work there, just like the conformance helper.
Its neighbour, ClusterIssuer: the private key Secret is created after the request is created…, goes the other way round. It creates the CSR with the annotation already set, waits for a SecretNotFound warning event, and only then creates the Secret. The annotation has to name a Secret that does not exist yet — that absence is the thing under test — so there is no created object to read a generated name back from.
That would leave GenerateName in one spec and rand.String in the one twelve lines below it. I would rather both ClusterIssuer specs read the same way, so I have kept rand.String for both. rand.String is well established here too — 42 uses across 13 files in test/e2e, including suite/issuers/ca/clusterissuer.go#L39, which names a cluster-scoped issuer's Secret the same way.
Happy to switch the one spec that can use it if you would still prefer that.
erikgb
left a comment
There was a problem hiding this comment.
/lgtm
/approve
/hold
Adding a hold in case you want to do something with my proposal. But feel free to unhold.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: erikgb The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/unhold Thanks @erikgb. I have left both ClusterIssuer specs on |
|
/cherry-pick release-1.21 Backporting for v1.21.2 (tracker: #9237). This is a test-only change. It stops the two The file on |
|
@wallrj-cyberark: new pull request created: #9321 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Pull Request Motivation
Fixes #9318.
Two e2e specs create the same Secret,
cert-manager/selfsigned-test, with the name and the namespace hard-coded.make/e2e.shruns ginkgo withnodes=40and--randomize-all, so the two sometimes run at the same time on different processes, and the second fails:The spec at L192 creates the Secret partway through and deletes it in
JustAfterEach. The spec at L254 creates the same object as its first step. Whichever starts second gets the 409.The Secret has to live in the cluster resource namespace, because that is where a ClusterIssuer resolves the
experimental.cert-manager.io/private-key-secret-nameannotation, and the framework does not randomise that namespace. The name is the only part we control.What changed
Each spec now generates its own Secret name in
JustBeforeEachand uses the same value in the annotation. Generating it there rather than at tree-construction time also means a retry gets a fresh name — the losing spec holds the Secret for about a second, so a retry that reuses the same name is certain to lose again.I also asserted the error on two Secret creates that were discarding it. That is not tidying; it changes how often we can even see this bug.
client-go's genericCreatereturns a non-nil zero object alongside the error (gentype/type.go:244):So the spec that lost the race carried on with a nameless Secret, waited 20 seconds for a signature that was never coming, and then failed teardown with
resource name may not be empty. Only one of the two specs could produce the clean 409 above. Collisions that went the other way looked like an unrelated signing timeout, so this flake is rarer in the record than it is in reality — worth knowing before triaging #9318 on the basis of "we have only seen it once".The two
Issuer:specs keep the fixed name. They write into the framework's per-spec namespace, so their names are already unique.How this was tested
go build -tags e2e_test ./...andgo vet -tags e2e_test ./suite/certificatesigningrequests/...pass in thetest/e2emodule, andgo fmtreports no change.test/e2e/suite/certificaterequests/selfsigned/secret.gosuite, which has ClusterIssuer specs of the same shape. It is not affected: a CertificateRequest is namespaced, so its private key Secret is resolved in the CertificateRequest's own namespace even when the issuer is cluster-scoped, and every Secret there already goes intof.Namespace.Name. Lines 248, 267 and 318 of the file changed here are the only places in the e2e tree that touchSecrets("cert-manager").Please be clear about what a green e2e run proves here. It shows the specs still pass and that the annotation and the Secret still agree. It does not prove the race is gone, because the race is rare and a single run would very likely have passed before this change too. The argument is structural: after this, no two specs can ask for the same Secret name.
Kind
/kind flake
Release Note