Skip to content

Commit 5564e5d

Browse files
committed
remove SetCertificateRequestConditionError
Signed-off-by: Tim Ramlot <[email protected]>
1 parent 3aef2fa commit 5564e5d

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
@@ -91,11 +91,11 @@ func TestCertificateRequestControllerIntegrationIssuerInitiallyNotFoundAndNotRea
9191
MaxRetryDuration: time.Minute,
9292
EventSource: kubeutil.NewEventStore(),
9393
Client: mgr.GetClient(),
94-
Sign: func(_ context.Context, cr signer.CertificateRequestObject, _ v1alpha1.Issuer) (signer.PEMBundle, error) {
94+
Sign: func(_ context.Context, cr signer.CertificateRequestObject, _ v1alpha1.Issuer) (signer.PEMBundle, signer.ExtraConditions, error) {
9595
atomic.AddUint64(&counters[extractIdFromNamespace(t, cr.GetNamespace())], 1)
9696
return signer.PEMBundle{
9797
ChainPEM: []byte("cert"),
98-
}, nil
98+
}, signer.ExtraConditions{}, nil
9999
},
100100
EventRecorder: record.NewFakeRecorder(100),
101101
Clock: clock.RealClock{},
@@ -203,6 +203,11 @@ func TestCertificateRequestControllerIntegrationIssuerInitiallyNotFoundAndNotRea
203203
}
204204
}
205205

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

221226
counter := uint64(0)
222-
signResult := make(chan error, 10)
227+
signResult := make(chan signResults, 10)
223228
ctx = setupControllersAPIServerAndClient(t, ctx, kubeClients,
224229
func(mgr ctrl.Manager) controllerInterface {
225230
return &CertificateRequestReconciler{
@@ -230,13 +235,13 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
230235
MaxRetryDuration: time.Minute,
231236
EventSource: kubeutil.NewEventStore(),
232237
Client: mgr.GetClient(),
233-
Sign: func(ctx context.Context, cr signer.CertificateRequestObject, _ v1alpha1.Issuer) (signer.PEMBundle, error) {
238+
Sign: func(ctx context.Context, cr signer.CertificateRequestObject, _ v1alpha1.Issuer) (signer.PEMBundle, signer.ExtraConditions, error) {
234239
atomic.AddUint64(&counter, 1)
235240
select {
236-
case err := <-signResult:
237-
return signer.PEMBundle{}, err
241+
case res := <-signResult:
242+
return signer.PEMBundle{}, res.extraConditions, res.err
238243
case <-ctx.Done():
239-
return signer.PEMBundle{}, ctx.Err()
244+
return signer.PEMBundle{}, signer.ExtraConditions{}, ctx.Err()
240245
}
241246
},
242247
EventRecorder: record.NewFakeRecorder(100),
@@ -309,19 +314,24 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
309314
markIssuerReady(t, ctx, kubeClients.Client, clock.RealClock{}, fieldOwner, issuer)
310315

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

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

@@ -330,19 +340,24 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
330340
require.NoError(t, err)
331341

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

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

@@ -351,7 +366,7 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
351366
require.NoError(t, err)
352367

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

0 commit comments

Comments
 (0)