Skip to content

Commit

Permalink
Aggregate CreateOrPatch errors during StoragePolicyQuota reconcile
Browse files Browse the repository at this point in the history
If there is some create or patch error for one StoragePolicyUsage
don't return early from the reconcile: the others may succeed.
This was prompted by the double take of this function ending with
"return err" where by the end err is always nil.

While here, add missing assertion for the expected CABundle.
  • Loading branch information
Bryan Venteicher committed Oct 24, 2024
1 parent 7941a83 commit 686a19d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package storagepolicyquota

import (
"context"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -135,6 +136,7 @@ func (r *Reconciler) ReconcileNormal(
}

// Create the StoragePolicyUsage resources.
var errs []error
for i := range objs {
dst := spqv1.StoragePolicyUsage{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -167,9 +169,9 @@ func (r *Reconciler) ReconcileNormal(
&dst,
fn); err != nil {

return err
errs = append(errs, err)
}
}

return err
return errors.Join(errs...)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func unitTestsReconcile() {
storageQuotaName = "my-storage-quota"
storageClassName = "my-storage-class"
storagePolicyID = "my-storage-policy"
caBundle = "fake-ca-bundle"
)

var (
Expand Down Expand Up @@ -75,7 +76,7 @@ func unitTestsReconcile() {
Webhooks: []admissionv1.ValidatingWebhook{
{
ClientConfig: admissionv1.WebhookClientConfig{
CABundle: []byte("fake-ca-bundle"),
CABundle: []byte(caBundle),
},
},
},
Expand Down Expand Up @@ -173,6 +174,7 @@ func unitTestsReconcile() {
ExpectWithOffset(1, obj.Spec.ResourceKind).To(Equal("VirtualMachine"))
ExpectWithOffset(1, obj.Spec.StorageClassName).To(Equal(storageClassName))
ExpectWithOffset(1, obj.Spec.StoragePolicyId).To(Equal(storagePolicyID))
ExpectWithOffset(1, obj.Spec.CABundle).To(Equal([]byte(caBundle)))
}

When("a StoragePolicyUsage resource does not exist", func() {
Expand Down

0 comments on commit 686a19d

Please sign in to comment.