Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/controller/bucket/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
"github.com/crossplane/crossplane-runtime/v2/pkg/meta"
"github.com/crossplane/crossplane-runtime/v2/pkg/resource"
"github.com/linode/provider-ceph/apis/provider-ceph/v1alpha1"
"github.com/linode/provider-ceph/internal/backendstore"
"github.com/linode/provider-ceph/internal/consts"
Expand Down Expand Up @@ -238,13 +237,22 @@ const (
// if err != nil {
// // Handle error
// }
//
//nolint:cyclop // cyclomatic complexity is accepted.
func (c *external) updateBucketCR(ctx context.Context, bucket *v1alpha1.Bucket, callbacks ...func(*v1alpha1.Bucket) UpdateRequired) error {
ctx, span := otel.Tracer("").Start(ctx, "bucket.external.updateBucketCR")
defer span.End()
ctx, log := traces.InjectTraceAndLogger(ctx, c.log)

shouldRetry := func(err error) bool {
return kerrors.IsConflict(err) ||
kerrors.IsInternalError(err) ||
kerrors.IsServerTimeout(err) ||
kerrors.IsServiceUnavailable(err)
}

for i, cb := range callbacks {
err := retry.OnError(retry.DefaultRetry, resource.IsAPIError, func() error {
err := retry.OnError(retry.DefaultBackoff, shouldRetry, func() error {
// If there are multiple callbacks, we can only use the cached kube client for
// the first Get(). Subsequent Get() calls must use the kube reader which reads
// directly from the API. This is necessary as we are doing Patch and Get calls
Expand Down
12 changes: 9 additions & 3 deletions internal/controller/providerconfig/healthcheck/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
"github.com/crossplane/crossplane-runtime/v2/pkg/resource"
apisv1alpha1 "github.com/linode/provider-ceph/apis/v1alpha1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -47,19 +46,26 @@ import (
func UpdateProviderConfigStatus(ctx context.Context, kubeClient client.Client, pc *apisv1alpha1.ProviderConfig, callback func(*apisv1alpha1.ProviderConfig, *apisv1alpha1.ProviderConfig)) error {
const (
steps = 4
factor = 0.5
factor = 5.0
jitter = 0.1
)

nn := types.NamespacedName{Name: pc.GetName(), Namespace: pc.Namespace}
pcDeepCopy := pc.DeepCopy()

shouldRetry := func(err error) bool {
return kerrors.IsConflict(err) ||
kerrors.IsInternalError(err) ||
kerrors.IsServerTimeout(err) ||
kerrors.IsServiceUnavailable(err)
}

err := retry.OnError(wait.Backoff{
Steps: steps,
Duration: (time.Duration(pc.Spec.HealthCheckIntervalSeconds) * time.Second) - time.Second,
Factor: factor,
Jitter: jitter,
}, resource.IsAPIError, func() error {
}, shouldRetry, func() error {
if err := kubeClient.Get(ctx, nn, pc); err != nil {
return err
}
Expand Down
Loading