-
Notifications
You must be signed in to change notification settings - Fork 7
Adds retry support to methods called by the operator #58
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,39 @@ package ca | |
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff" | ||
"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 | ||
) | ||
|
||
// SetupPKIAndWait creates a PKI backend and policy if one does not exist for | ||
// the cluster. If an error occurs an exponential backoff is used. After the | ||
// max elapsed time the error is returned to the caller. | ||
func (s *Service) SetupPKIAndWait(cert certificatetpr.Spec) error { | ||
initBackoff := backoff.NewExponentialBackOff() | ||
initBackoff.MaxElapsedTime = setupPKIMaxElapsedTime | ||
|
||
operation := func() error { | ||
err := s.SetupPKI(cert) | ||
if err != nil { | ||
s.Logger.Log("info", "failed to setup PKI - retrying") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
|
||
return err | ||
} | ||
|
||
return backoff.Retry(operation, initBackoff) | ||
} | ||
|
||
// SetupPKI creates a PKI backend and policy if one does not exist for the cluster. | ||
func (s *Service) SetupPKI(cert certificatetpr.Spec) error { | ||
s.Config.Logger.Log("debug", fmt.Sprintf("setting up PKI for cluster '%s'", cert.ClusterID)) | ||
|
||
|
There was a problem hiding this comment.
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.