Skip to content

Commit c3c8e53

Browse files
committed
fix: Do not return error when PipelineRun patching is failed
when PipelineRun patch is failed in startPR func, PaC was returning error which was creating a failed check on git provider though PipelineRun was running and it was making user confused, this commit fixes that. https://issues.redhat.com/browse/SRVKP-9345 Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 565420c commit c3c8e53

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

pkg/pipelineascode/pipelineascode.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ func (p *PacRun) startPR(ctx context.Context, match matcher.Match) (*tektonv1.Pi
310310
if len(patchAnnotations) > 0 || len(patchLabels) > 0 {
311311
pr, err = action.PatchPipelineRun(ctx, p.logger, whatPatching, p.run.Clients.Tekton, pr, getMergePatch(patchAnnotations, patchLabels))
312312
if err != nil {
313-
// we still return the created PR with error, and allow caller to decide what to do with the PR, and avoid
314-
// unneeded SIGSEGV's
315-
return pr, fmt.Errorf("cannot patch pipelinerun %s: %w", pr.GetGenerateName(), err)
313+
// if PipelineRun patch is failed then do not return error, just log the error
314+
// because its a false negative and on startPR return a failed check is being created
315+
// due to this.
316+
p.logger.Errorf("cannot patch pipelinerun %s: %w", pr.GetGenerateName(), err)
317+
return pr, nil
316318
}
317319
currentReason := ""
318320
if len(pr.Status.GetConditions()) > 0 {

pkg/pipelineascode/pipelineascode_startpr_test.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -765,31 +765,29 @@ func TestStartPR_PatchBehavior(t *testing.T) {
765765
patchErrorMsg string
766766
expectError bool
767767
expectErrorContains []string
768+
expectedLogSnippet string
768769
verifyAnnotations bool // whether to verify annotations were set correctly
769770
}{
770771
{
771-
name: "successful patch - all annotations set",
772-
simulatePatchError: false,
773-
expectError: false,
774-
verifyAnnotations: true,
772+
name: "successful patch - all annotations set",
773+
verifyAnnotations: true,
775774
},
776775
{
777-
name: "patch failure - PR still returned with error",
778-
simulatePatchError: true,
779-
patchErrorMsg: "etcd unavailable",
780-
expectError: true,
781-
expectErrorContains: []string{"cannot patch pipelinerun", "etcd unavailable"},
782-
verifyAnnotations: false,
776+
name: "patch failure - PR still returned with error",
777+
simulatePatchError: true,
778+
patchErrorMsg: "etcd unavailable",
779+
expectedLogSnippet: "cannot patch pipelinerun",
780+
verifyAnnotations: false,
783781
},
784782
}
785783

786784
for _, tt := range tests {
787785
t.Run(tt.name, func(t *testing.T) {
786+
observer, log := zapobserver.New(zap.InfoLevel)
787+
logger := zap.New(observer).Sugar()
788788
if tt.simulatePatchError {
789789
// Need custom reactor to simulate patch failure
790790
ctx, _ := rtesting.SetupFakeContext(t)
791-
observer, _ := zapobserver.New(zap.InfoLevel)
792-
logger := zap.New(observer).Sugar()
793791

794792
stdata, _ := testclient.SeedTestData(t, ctx, testclient.Data{
795793
Namespaces: []*corev1.Namespace{
@@ -889,6 +887,11 @@ func TestStartPR_PatchBehavior(t *testing.T) {
889887
assert.NilError(t, err)
890888
assert.Assert(t, pr != nil, "PipelineRun should be returned")
891889

890+
if tt.expectedLogSnippet != "" {
891+
logmsg := log.FilterMessageSnippet(tt.expectedLogSnippet).TakeAll()
892+
assert.Assert(t, len(logmsg) > 0, "log messages", logmsg, tt.expectedLogSnippet)
893+
}
894+
892895
if tt.verifyAnnotations {
893896
state, hasState := pr.GetAnnotations()[keys.State]
894897
assert.Assert(t, hasState, "State annotation should be patched")

0 commit comments

Comments
 (0)