Skip to content

Commit

Permalink
Avoid failure when submitting request quickly
Browse files Browse the repository at this point in the history
fix #6408

When submitting quickly, the creation may fail because the cache is not
updated. We can assume that is in progress, and the next reconcile will
handle it based on the actual situation.
  • Loading branch information
l-qing committed Mar 22, 2023
1 parent 5deea1f commit b457654
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/resolution/resource/crd_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
rrclient "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned"
rrlisters "github.com/tektoncd/pipeline/pkg/client/resolution/listers/resolution/v1beta1"
resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)
Expand All @@ -52,9 +53,12 @@ var _ Requester = &CRDRequester{}
// kubernetes cluster, returning any errors experienced while doing so.
// If ResolutionRequest is succeeded then it returns the resolved data.
func (r *CRDRequester) Submit(ctx context.Context, resolver ResolverName, req Request) (ResolvedResource, error) {
rr, _ := r.lister.ResolutionRequests(req.Namespace()).Get(req.Name())
rr, err := r.lister.ResolutionRequests(req.Namespace()).Get(req.Name())
if rr == nil {
if err := r.createResolutionRequest(ctx, resolver, req); err != nil {
if err := r.createResolutionRequest(ctx, resolver, req); err != nil &&
// If the request already exists then we can assume that is in progress.
// The next reconcile will handle it based on the actual situation.
!apierrors.IsAlreadyExists(err) {
return nil, err
}
return nil, resolutioncommon.ErrRequestInProgress
Expand All @@ -74,7 +78,7 @@ func (r *CRDRequester) Submit(ctx context.Context, resolver ResolverName, req Re
}

message := rr.Status.GetCondition(apis.ConditionSucceeded).GetMessage()
err := resolutioncommon.NewError(resolutioncommon.ReasonResolutionFailed, errors.New(message))
err = resolutioncommon.NewError(resolutioncommon.ReasonResolutionFailed, errors.New(message))
return nil, err
}

Expand Down

0 comments on commit b457654

Please sign in to comment.