Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuously retry updating the cert secret #280

Merged
merged 7 commits into from
Aug 20, 2021

Conversation

tvoran
Copy link
Member

@tvoran tvoran commented Aug 10, 2021

Uses retry with exponential backoff to retry updating the cert secret
if there's an error. Sync's with caller via a stop channel, caller
waits on stop channel before starting a new update thread.

Uses retry with exponential backoff to retry updating the cert secret
if there's an error. Sync's with caller via a stop channel, caller
waits on stop channel before starting a new update thread.
@tvoran tvoran requested review from tomhjp, benashz and calvn August 16, 2021 04:26
Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

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

LGTM, mainly just one question about whether we can simplify a little.

helper/cert/source_gen.go Outdated Show resolved Hide resolved
helper/cert/source_gen.go Outdated Show resolved Hide resolved
helper/cert/source_gen.go Outdated Show resolved Hide resolved
helper/cert/source_gen.go Outdated Show resolved Hide resolved
result.Cert = []byte(cert)
result.Key = []byte(key)
if err != nil {
return result, err
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 that this is being done elsewhere above the code, but I wonder if it's better to return an empty object since result has been partially set at this point (unless that's something that we explicitly want to do).

result.CACert = s.caCert

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is probably technically ok because the result is discarded if there's an error, but I'll let Theron confirm.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is indeed being discarded in notify.Run() if there's an error. Which is good, because the next block there is comparing the new result to the old one, so it would also think an empty result is a new result. All this to say I think we might as well leave it up to the caller when returning an error, and technically s.caCert is valid at this point and will continue to be used on the next pass.

helper/cert/source_gen.go Outdated Show resolved Hide resolved
}
}
if s.LeaderElector != nil {
s.retryUpdateSecret(ctx, leaderCh, result)
Copy link
Contributor

@calvn calvn Aug 17, 2021

Choose a reason for hiding this comment

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

This sync call might affect <-retryTicker.C in Notify.Run(). For instance, if this call blocks for 6s it will be skipping the next tick (and every increment of 5 seconds that this blocks skips 1 tick). This may or may not be fine depending if there are other things within that loop that is expecting the ticker to run every 5 seconds.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine to me, the Notify.Run() loop only notifies upstream when there is a new result to report, so I think it should be ok to reattempt until we get something worth reporting, and we're still cancellable via the context.

Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

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

One more small suggestion. LGTM otherwise!

result.Cert = []byte(cert)
result.Key = []byte(key)
if err != nil {
return result, err
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is probably technically ok because the result is discarded if there's an error, but I'll let Theron confirm.

}
}
if s.LeaderElector != nil {
s.retryUpdateSecret(ctx, leaderCh, result)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine to me, the Notify.Run() loop only notifies upstream when there is a new result to report, so I think it should be ok to reattempt until we get something worth reporting, and we're still cancellable via the context.

helper/cert/source_gen.go Outdated Show resolved Hide resolved
tvoran and others added 2 commits August 17, 2021 11:31
Co-authored-by: Calvin Leung Huang <[email protected]>
Retries until the certificate would be renewed. Actually return an
error if all attempts time out.
helper/cert/source_gen.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

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

LGTM!

@tvoran tvoran merged commit 99a06ef into master Aug 20, 2021
@tvoran tvoran deleted the VAULT-2403/update-cert-secret-reliably branch August 20, 2021 16:52
RemcoBuddelmeijer pushed a commit to RemcoBuddelmeijer/vault-k8s that referenced this pull request Feb 22, 2022
Uses retry with exponential backoff to retry updating the cert secret
if there's an error. Retries until the certificate would be renewed.

Co-authored-by: Tom Proctor <[email protected]>
Co-authored-by: Calvin Leung Huang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants