Skip to content

Commit 7360a53

Browse files
committed
remove SetCertificateRequestConditionError
Signed-off-by: Tim Ramlot <[email protected]>
1 parent c77d8be commit 7360a53

8 files changed

+271
-299
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ The business logic of the controllers can be provided to the libary through the
7676
If it returns a normal error, the controller will retry with backoff until the `Check` function succeeds.
7777
If the error is of type `signer.PermanentError`, the controller will not retry automatically. Instead, an increase in Generation is required to recheck the issuer.
7878

79-
- The `Sign` function is used by the CertificateRequest controller.
79+
- The `Sign` function is used by the CertificateRequest controller.
8080
If it returns a normal error, the `Sign` function will be retried as long as we have not spent more than the configured `MaxRetryDuration` after the certificate request was created.
8181
If the error is of type `signer.IssuerError`, the error is an error that should be set on the issuer instead of the CertificateRequest.
82-
If the error is of type `signer.SetCertificateRequestConditionError`, the controller will, additional to setting the ready condition, also set the specified condition. This can be used in case we have to store some additional state in the status.
8382
If the error is of type `signer.PermanentError`, the controller will not retry automatically. Instead, a new CertificateRequest has to be created.
8483

8584
## Reconciliation loops

controllers/certificaterequest_controller_integration_test.go

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ func TestCertificateRequestControllerIntegrationIssuerInitiallyNotFoundAndNotRea
9090
MaxRetryDuration: time.Minute,
9191
EventSource: kubeutil.NewEventStore(),
9292
Client: mgr.GetClient(),
93-
Sign: func(_ context.Context, cr signer.CertificateRequestObject, _ v1alpha1.Issuer) (signer.PEMBundle, error) {
93+
Sign: func(_ context.Context, cr signer.CertificateRequestObject, _ v1alpha1.Issuer) (signer.PEMBundle, signer.ExtraConditions, error) {
9494
atomic.AddUint64(&counters[extractIdFromNamespace(t, cr.GetNamespace())], 1)
9595
return signer.PEMBundle{
9696
ChainPEM: []byte("cert"),
97-
}, nil
97+
}, signer.ExtraConditions{}, nil
9898
},
9999
EventRecorder: record.NewFakeRecorder(100),
100100
Clock: clock.RealClock{},
@@ -202,6 +202,11 @@ func TestCertificateRequestControllerIntegrationIssuerInitiallyNotFoundAndNotRea
202202
}
203203
}
204204

205+
type signResults struct {
206+
err error
207+
extraConditions []cmapi.CertificateRequestCondition
208+
}
209+
205210
// TestCertificateRequestControllerIntegrationSetCondition runs the
206211
// CertificateRequestController against a real Kubernetes API server.
207212
func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
@@ -218,7 +223,7 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
218223
kubeClients := testresource.KubeClients(t, nil)
219224

220225
counter := uint64(0)
221-
signResult := make(chan error, 10)
226+
signResult := make(chan signResults, 10)
222227
ctx = setupControllersAPIServerAndClient(t, ctx, kubeClients,
223228
func(mgr ctrl.Manager) controllerInterface {
224229
return &CertificateRequestReconciler{
@@ -229,13 +234,13 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
229234
MaxRetryDuration: time.Minute,
230235
EventSource: kubeutil.NewEventStore(),
231236
Client: mgr.GetClient(),
232-
Sign: func(ctx context.Context, cr signer.CertificateRequestObject, _ v1alpha1.Issuer) (signer.PEMBundle, error) {
237+
Sign: func(ctx context.Context, cr signer.CertificateRequestObject, _ v1alpha1.Issuer) (signer.PEMBundle, signer.ExtraConditions, error) {
233238
atomic.AddUint64(&counter, 1)
234239
select {
235-
case err := <-signResult:
236-
return signer.PEMBundle{}, err
240+
case res := <-signResult:
241+
return signer.PEMBundle{}, res.extraConditions, res.err
237242
case <-ctx.Done():
238-
return signer.PEMBundle{}, ctx.Err()
243+
return signer.PEMBundle{}, signer.ExtraConditions{}, ctx.Err()
239244
}
240245
},
241246
EventRecorder: record.NewFakeRecorder(100),
@@ -308,19 +313,24 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
308313
markIssuerReady(t, ctx, kubeClients.Client, clock.RealClock{}, fieldOwner, issuer)
309314

310315
checkComplete = kubeClients.StartObjectWatch(t, ctx, cr)
311-
signResult <- signer.SetCertificateRequestConditionError{
312-
Err: fmt.Errorf("[err message1]"),
313-
ConditionType: "[condition type]",
314-
Status: cmmeta.ConditionTrue,
315-
Reason: "[reason]",
316+
signResult <- signResults{
317+
err: fmt.Errorf("[err message1]"),
318+
extraConditions: []cmapi.CertificateRequestCondition{
319+
{
320+
Type: "[condition type]",
321+
Status: cmmeta.ConditionTrue,
322+
Reason: "[condition reason]",
323+
Message: "[condition message1]",
324+
},
325+
},
316326
}
317327
err = checkComplete(func(obj runtime.Object) error {
318328
customCondition := cmutil.GetCertificateRequestCondition(obj.(*cmapi.CertificateRequest), "[condition type]")
319329

320330
if (customCondition == nil) ||
321331
(customCondition.Status != cmmeta.ConditionTrue) ||
322-
(customCondition.Reason != "[reason]") ||
323-
(customCondition.Message != "[err message1]") {
332+
(customCondition.Reason != "[condition reason]") ||
333+
(customCondition.Message != "[condition message1]") {
324334
return fmt.Errorf("incorrect custom condition: %v", customCondition)
325335
}
326336

@@ -329,19 +339,24 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
329339
require.NoError(t, err)
330340

331341
checkComplete = kubeClients.StartObjectWatch(t, ctx, cr)
332-
signResult <- signer.SetCertificateRequestConditionError{
333-
Err: fmt.Errorf("[err message2]"),
334-
ConditionType: "[condition type]",
335-
Status: cmmeta.ConditionTrue,
336-
Reason: "[reason]",
342+
signResult <- signResults{
343+
err: fmt.Errorf("[err message2]"),
344+
extraConditions: []cmapi.CertificateRequestCondition{
345+
{
346+
Type: "[condition type]",
347+
Status: cmmeta.ConditionTrue,
348+
Reason: "[condition reason]",
349+
Message: "[condition message2]",
350+
},
351+
},
337352
}
338353
err = checkComplete(func(obj runtime.Object) error {
339354
customCondition := cmutil.GetCertificateRequestCondition(obj.(*cmapi.CertificateRequest), "[condition type]")
340355

341356
if (customCondition == nil) ||
342357
(customCondition.Status != cmmeta.ConditionTrue) ||
343-
(customCondition.Reason != "[reason]") ||
344-
(customCondition.Message != "[err message2]") {
358+
(customCondition.Reason != "[condition reason]") ||
359+
(customCondition.Message != "[condition message2]") {
345360
return fmt.Errorf("incorrect custom condition: %v", customCondition)
346361
}
347362

@@ -350,7 +365,7 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
350365
require.NoError(t, err)
351366

352367
checkComplete = kubeClients.StartObjectWatch(t, ctx, cr)
353-
signResult <- nil
368+
signResult <- signResults{}
354369
t.Log("Waiting for the controller to marks the CertificateRequest as Ready")
355370
err = checkComplete(func(obj runtime.Object) error {
356371
readyCondition := cmutil.GetCertificateRequestCondition(obj.(*cmapi.CertificateRequest), cmapi.CertificateRequestConditionReady)

0 commit comments

Comments
 (0)