Skip to content

Commit

Permalink
add retry for pipelinerun annotation update (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
chilianyi authored Feb 15, 2023
1 parent 0075fe1 commit b0ed588
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions controllers/jenkins/pipelinerun/pipelinerun_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,24 @@ func getSCMRefName(prSpec *v1alpha3.PipelineRunSpec) (string, error) {
}

func (r *Reconciler) updateLabelsAndAnnotations(ctx context.Context, pr *v1alpha3.PipelineRun) (err error) {
// get pipeline
prToUpdate := v1alpha3.PipelineRun{}
if err = r.Get(ctx, client.ObjectKey{Namespace: pr.Namespace, Name: pr.Name}, &prToUpdate); err == nil {
if !reflect.DeepEqual(pr.Labels, prToUpdate.Labels) || !reflect.DeepEqual(pr.Annotations, prToUpdate.Annotations) {
prToUpdate = *prToUpdate.DeepCopy()
prToUpdate.Labels = pr.Labels
prToUpdate.Annotations = pr.Annotations
// make sure all PipelineRuns have the finalizer
k8sutil.AddFinalizer(&prToUpdate.ObjectMeta, v1alpha3.PipelineRunFinalizerName)
err = r.Update(ctx, &prToUpdate)
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
// get pipeline
prToUpdate := v1alpha3.PipelineRun{}
err = r.Get(ctx, client.ObjectKey{Namespace: pr.Namespace, Name: pr.Name}, &prToUpdate)
if err != nil {
return err
}
}
return
if reflect.DeepEqual(pr.Labels, prToUpdate.Labels) && reflect.DeepEqual(pr.Annotations, prToUpdate.Annotations) {
return nil
}

prToUpdate = *prToUpdate.DeepCopy()
prToUpdate.Labels = pr.Labels
prToUpdate.Annotations = pr.Annotations
// make sure all PipelineRuns have the finalizer
k8sutil.AddFinalizer(&prToUpdate.ObjectMeta, v1alpha3.PipelineRunFinalizerName)
return r.Update(ctx, &prToUpdate)
})
}

func (r *Reconciler) updateStatus(ctx context.Context, desiredStatus *v1alpha3.PipelineRunStatus, prKey client.ObjectKey) error {
Expand Down

0 comments on commit b0ed588

Please sign in to comment.