Skip to content

Conversation

@tchap
Copy link
Contributor

@tchap tchap commented Nov 27, 2025

This is actually not affecting the logic, but a wrong error is returned.

Improved the unit test to check events and annotation keys.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Nov 27, 2025
@openshift-ci-robot
Copy link

@tchap: This pull request explicitly references no jira issue.

In response to this:

This is actually not affecting the logic, but a wrong error is returned.

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested review from bertinatto and deads2k November 27, 2025 10:47
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 27, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tchap
Once this PR has been reviewed and has the lgtm label, please assign jsafrane for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tchap tchap force-pushed the certrotation branch 2 times, most recently from 84b8a5b to 247b85e Compare November 27, 2025 13:30

func TestEnsureSigningCertKeyPair(t *testing.T) {
verifyActionFunc := func(check func(t *testing.T, action clienttesting.Action)) func(t *testing.T, client *kubefake.Clientset, controllerUpdatedSecret bool) {
return func(t *testing.T, client *kubefake.Clientset, controllerUpdatedSecret bool) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is just copied and refactored so that it can be used for both create and update.

"auth.openshift.io/certificate-issuer",
"certificates.openshift.io/refresh-period",
"openshift.io/owning-component",
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added checking for annotation keys. Getting the precise values would require mocking time and what not, which is not currently possible. But it could be done if we changed some public functions.

RefreshOnlyWhenExpired: false,
verifyActions: verifyActionsOnUpdated,
expectedEvents: []*corev1.Event{
{Reason: "SignerUpdateRequired", Message: `"signer" in "ns" requires a new signing cert/key pair: missing notBefore`},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually ensures the reason as fixed in this PR works now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ic, normally i would prefer to create a valid secret and then remove the notBefore annotation but i understand that would require more work.


verifyActions func(t *testing.T, client *kubefake.Clientset, controllerUpdatedSecret bool)
expectedError string
verifyActions func(t *testing.T, client *kubefake.Clientset, controllerUpdatedSecret bool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to change the signature to []func(t *testing.T, client *kubefake.Clientset, controllerUpdatedSecret bool) ?

and then the usage would be:

[verifyFn1, verifyFn2]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will rather rename it to verifyAction, because there is at most one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I am making it better or worse now, but I updated it to use verifyAction. Not specifying any function means that no action is expected.

@tchap tchap force-pushed the certrotation branch 2 times, most recently from 919786a to dff2a0e Compare November 27, 2025 15:35
This is actually not affecting the logic, but a wrong error is returned.

Improved the unit test to check events and annotation keys.
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 27, 2025

@tchap: all tests passed!

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

)

func TestEnsureSigningCertKeyPair(t *testing.T) {
newVerifyActionFunc := func(check func(t *testing.T, action clienttesting.Action)) func(t *testing.T, action clienttesting.Action) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we change the signature of this method to accept the required object ?
in that case this function would be responsible for validating that object.

t.Helper()
if !action.Matches("create", "secrets") {
t.Fatalf("Expected a Create action, got %s", spew.Sdump(action))
}
Copy link
Contributor

@p0lyn0mial p0lyn0mial Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then in this function we would validate the action, extract the object and call newVerifyActionFunc (we could rename the function to newVerifyObjectFunc`)

t.Helper()
if !action.Matches("update", "secrets") {
t.Fatalf("Expected an Update action, got %s", spew.Sdump(action))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

test.verifyActions(t, client, updated)
actions := client.Actions()
if test.verifyAction == nil {
if len(actions) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we change this code to the previous version where we used the verifyEmptyAction function that was used on the test cases

}
}

if events := pruneEventFieldsForComparison(recorder.Events()); !cmp.Equal(events, test.expectedEvents) {
Copy link
Contributor

@p0lyn0mial p0lyn0mial Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually don't verify the events.
is this the only way to verify the new test cases ?

UPDATE: I just saw #2061 (comment)

not ideal but changing it would require more work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have you decided to remove the validation of the updated var?

if certType, _ := CertificateTypeFromObject(actual); certType != CertificateTypeSigner {
t.Errorf("expected certificate type 'signer', got: %v", certType)
}
if len(actual.Data["tls.crt"]) == 0 || len(actual.Data["tls.key"]) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is pre-existing (we don't have to change it now) but I would expect the tests to at least check if the cert and the key are valid.

}
}

if events := pruneEventFieldsForComparison(recorder.Events()); !cmp.Equal(events, test.expectedEvents) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have you decided to remove the validation of the updated var?

RefreshOnlyWhenExpired: false,
verifyActions: verifyActionsOnUpdated,
expectedEvents: []*corev1.Event{
{Reason: "SignerUpdateRequired", Message: `"signer" in "ns" requires a new signing cert/key pair: missing notBefore`},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ic, normally i would prefer to create a valid secret and then remove the notBefore annotation but i understand that would require more work.

@tchap
Copy link
Contributor Author

tchap commented Nov 28, 2025

In the end I opened #2062 to refactor tests first. Once merged, I will rebase and fix the issue with event messages. But this will still require checking events, I think.

@tchap
Copy link
Contributor Author

tchap commented Nov 28, 2025

^^^

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants