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 f5b81b0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 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,26 +335,29 @@ 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 {
a.logger.Error(err, "Failed to annotate build pipelinerun with the snapshot creation status")
return err
}
a.logger.LogAuditEvent("Updated build pipelineRun", a.pipelineRun, h.LogActionUpdate,
h.CreateSnapshotAnnotationName, a.pipelineRun.Annotations[h.CreateSnapshotAnnotationName])
} else {
a.logger.Info("Cannot annotate build pipelinerun annotation 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 {
a.logger.Error(err, "Failed to remove finalizer from build pipelinerun")
return err
}
}
Expand Down Expand Up @@ -402,8 +405,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 f5b81b0

Please sign in to comment.