Skip to content

Commit

Permalink
[SECURESIGN-1455] Fix Ensure function
Browse files Browse the repository at this point in the history
  • Loading branch information
bouskaJ committed Oct 7, 2024
1 parent 2650d09 commit 778cc9e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/controller/common/action/base_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/securesign/operator/internal/controller/annotations"
"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

Expand Down Expand Up @@ -99,7 +99,6 @@ func (action *BaseAction) Ensure(ctx context.Context, obj client2.Object, opts .
var (
expected client2.Object
ok bool
err error
result controllerutil.OperationResult
)

Expand All @@ -113,10 +112,11 @@ func (action *BaseAction) Ensure(ctx context.Context, obj client2.Object, opts .
return false, errors.New("can't create DeepCopy object")
}

err = retry.OnError(retry.DefaultRetry, func(err error) bool {
return apierrors.IsConflict(err) || apierrors.IsAlreadyExists(err)
err := retry.OnError(retry.DefaultRetry, func(err error) bool {
return apiErrors.IsConflict(err) || apiErrors.IsAlreadyExists(err)
}, func() error {
result, err = controllerutil.CreateOrUpdate(ctx, action.Client, obj, func() error {
var createUpdateError error
result, createUpdateError = controllerutil.CreateOrUpdate(ctx, action.Client, obj, func() error {
annoStr, find := obj.GetAnnotations()[annotations.PausedReconciliation]
if find {
annoBool, _ := strconv.ParseBool(annoStr)
Expand All @@ -126,15 +126,15 @@ func (action *BaseAction) Ensure(ctx context.Context, obj client2.Object, opts .
}

for _, opt := range opts {
err = opt(obj, expected)
if err != nil {
return err
optError := opt(obj, expected)
if optError != nil {
return optError
}
}

return nil
})
return err
return createUpdateError
})

if err != nil {
Expand Down

0 comments on commit 778cc9e

Please sign in to comment.