Skip to content

Commit

Permalink
add stable itter for tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Wöhrl <[email protected]>
  • Loading branch information
woehrl01 committed Oct 22, 2024
1 parent 08154b2 commit fbf28db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func main() {
Recorder: mgr.GetEventRecorderFor("awspcaissuer-controller"),

Clock: clock.RealClock{},
RequeueItter: controllers.NewRequeueItter(),
CheckApprovedCondition: !disableApprovedCheck,
MaxRetryDuration: maxRetryDuration,
}).SetupWithManager(mgr); err != nil {
Expand Down
20 changes: 17 additions & 3 deletions pkg/controllers/certificaterequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ import (
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
)

type RequeueItter interface {
RequeueAfter() time.Duration
}

type requeueItter struct {
}

func (r *requeueItter) RequeueAfter() time.Duration {
return 1*time.Minute + time.Duration(rand.Intn(60))*time.Second
}

func NewRequeueItter() RequeueItter {
return &requeueItter{}
}

// CertificateRequestReconciler reconciles a AWSPCAIssuer object
type CertificateRequestReconciler struct {
client.Client
Expand All @@ -50,6 +65,7 @@ type CertificateRequestReconciler struct {
Recorder record.EventRecorder

Clock clock.Clock
RequeueItter RequeueItter
CheckApprovedCondition bool
MaxRetryDuration time.Duration
}
Expand Down Expand Up @@ -154,10 +170,8 @@ func (r *CertificateRequestReconciler) Reconcile(ctx context.Context, req ctrl.R
return ctrl.Result{}, r.setPermanentStatus(ctx, cr, cmmeta.ConditionFalse, cmapi.CertificateRequestReasonFailed, "Permanent error signing certificate: %s", err.Error())
}

retryAfter := 1*time.Minute + time.Duration(rand.Intn(60))*time.Second

return ctrl.Result{
RequeueAfter: retryAfter,
RequeueAfter: r.RequeueItter.RequeueAfter(),
}, r.setTemporaryStatus(ctx, cr, cmmeta.ConditionFalse, cmapi.CertificateRequestReasonFailed, "Temporary error signing certificate, retry again: %s", err.Error())
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/controllers/certificaterequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func (p *fakeProvisioner) Sign(ctx context.Context, cr *cmapi.CertificateRequest

type createMockProvisioner func()

type fakeRequeueItter struct {
}

func (r *fakeRequeueItter) RequeueAfter() time.Duration {
return 1 * time.Hour
}

func TestProvisonerOperation(t *testing.T) {
provisioner := awspca.NewProvisioner(aws.Config{}, "arn")
awspca.StoreProvisioner(types.NamespacedName{Namespace: "ns1", Name: "issuer1"}, provisioner)
Expand Down Expand Up @@ -408,6 +415,7 @@ func TestCertificateRequestReconcile(t *testing.T) {
expectedReadyConditionStatus: cmmeta.ConditionUnknown,
expectedReadyConditionReason: "",
expectedError: true,
expectedResult: ctrl.Result{RequeueAfter: 1 * time.Hour},
retryDuration: 1 * time.Hour,
},
"failure-sign-failure": {
Expand Down Expand Up @@ -488,6 +496,7 @@ func TestCertificateRequestReconcile(t *testing.T) {
Scheme: scheme,
Recorder: record.NewFakeRecorder(10),
Clock: clock.RealClock{},
RequeueItter: &fakeRequeueItter{},
MaxRetryDuration: tc.retryDuration,
}

Expand Down

0 comments on commit fbf28db

Please sign in to comment.