Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Adds retry support to methods called by the operator #58

Merged
merged 4 commits into from
Jun 21, 2017
Merged

Conversation

rossf7
Copy link
Contributor

@rossf7 rossf7 commented Jun 21, 2017

Fixes #10

This is some boyscouting I did a while back I want to finish off. It adds retry support to the methods called in the addFunc and deleteFunc.

@rossf7 rossf7 self-assigned this Jun 21, 2017
"github.com/giantswarm/certctl/service/pki"
"github.com/giantswarm/certctl/service/token"
"github.com/giantswarm/certificatetpr"
microerror "github.com/giantswarm/microkit/error"
)

// SetupPKI creates a PKI backend and policy if one does not exists for the cluster.
const (
setupPKIMaxElapsedTime = 30 * time.Second
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The timeouts are short because the timeout for the secrets watch is only 90 seconds. The operator needs to issue all certs in that time.

Copy link
Contributor

@xh3b4sd xh3b4sd left a comment

Choose a reason for hiding this comment

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

I think the error handling has room for improvements.

operation := func() error {
err := s.SetupPKI(cert)
if err != nil {
s.Logger.Log("info", "failed to setup PKI - retrying")
Copy link
Contributor

Choose a reason for hiding this comment

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

This error handling is a bit uncommon. I would prefer returning the error here masked like we usually do and do logging additionally if desired. Below should be returned nil. Looks strange that the error is always returned. In case SetupPKI does weird things we forward the weirdness here. Lets not do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that SetupPKI would have the normal logging. In the wait wrapper I just wanted to indicate that a retry was taking place.

But it is different to our normal error handling and I get the point about returning the error. I'll take another look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@xh3b4sd xh3b4sd left a comment

Choose a reason for hiding this comment

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

Cool. This is a good step forward. Note that we later can also register error notifiers for the retrier to emit metrics and stuff.

@rossf7 rossf7 merged commit 1e0b039 into master Jun 21, 2017
@rossf7 rossf7 deleted the add-retry branch June 21, 2017 16:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants