Skip to content

Commit

Permalink
fix(STONEINTG-1086): annotate build PLR when failing to create snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Hongwei Liu <[email protected]>
  • Loading branch information
hongweiliu17 committed Nov 20, 2024
1 parent b3d9c11 commit 6de7e8f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/controller/buildpipeline/buildpipeline_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (a *Adapter) EnsureSnapshotExists() (result controller.OperationResult, err
var canRemoveFinalizer bool

defer func() {
updateErr := a.updateBuildPipelineRunWithFinalInfo(canRemoveFinalizer)
updateErr := a.updateBuildPipelineRunWithFinalInfo(canRemoveFinalizer, err)
if updateErr != nil {
if errors.IsNotFound(updateErr) {
result, err = controller.ContinueProcessing()
Expand Down Expand Up @@ -335,23 +335,23 @@ func (a *Adapter) annotateBuildPipelineRunWithSnapshot(snapshot *applicationapiv

// updateBuildPipelineRunWithFinalInfo adds the final pieces of information to the pipelineRun in order to ensure
// that anything that happened during the reconciliation is reflected in the CR
func (a *Adapter) updateBuildPipelineRunWithFinalInfo(canRemoveFinalizer bool) error {
func (a *Adapter) updateBuildPipelineRunWithFinalInfo(canRemoveFinalizer bool, cerr error) error {
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
var err error
a.pipelineRun, err = a.loader.GetPipelineRun(a.context, a.client, a.pipelineRun.Name, a.pipelineRun.Namespace)
if err != nil {
return err
}

if a.pipelineRun.GetDeletionTimestamp() != nil {
err = tekton.AnnotateBuildPipelineRunWithCreateSnapshotAnnotation(a.context, a.pipelineRun, a.client, err)
if a.pipelineRun.GetDeletionTimestamp() == nil {
err = tekton.AnnotateBuildPipelineRunWithCreateSnapshotAnnotation(a.context, a.pipelineRun, a.client, cerr)
if err != nil {
return err
}
a.logger.LogAuditEvent("Updated build pipelineRun", a.pipelineRun, h.LogActionUpdate,
h.CreateSnapshotAnnotationName, a.pipelineRun.Annotations[h.CreateSnapshotAnnotationName])
}

a.logger.Info("Cannot annotate build pipelinerun annotaion with the snapshot creation status since it has been marked as deleted")
if canRemoveFinalizer {
err = h.RemoveFinalizerFromPipelineRun(a.context, a.client, a.logger, a.pipelineRun, h.IntegrationPipelineRunFinalizer)
if err != nil {
Expand Down Expand Up @@ -402,8 +402,8 @@ func (a *Adapter) handleSnapshotCreationFailure(canRemoveFinalizer *bool, cerr e
a.logger.Error(cerr, "Failed to create Snapshot")
if errors.IsForbidden(cerr) {
// we cannot create a snapshot (possibly because the snapshot quota is hit) and we don't want to block resources, user has to retry
// // we still return the error to make build PLR annotated when meeting quota limitation issue
*canRemoveFinalizer = true
return controller.StopProcessing()
}
return controller.RequeueWithError(cerr)
}
Expand Down

0 comments on commit 6de7e8f

Please sign in to comment.