diff --git a/docs/content/docs/guide/statuses.md b/docs/content/docs/guide/statuses.md index 87572987c..2ae6e3110 100644 --- a/docs/content/docs/guide/statuses.md +++ b/docs/content/docs/guide/statuses.md @@ -140,22 +140,14 @@ found here: ## Tekton Results Annotation -A specialized annotation designed explicitly for use with Tekton Results. -This annotation is automatically added by Pipelines-as-Code to every PipelineRun -it initiates. -Unlike other annotations, which might be stored in `PipelineRun` or `TaskRun` metadata, -this custom annotation is selectively captured to provide additional information -specifically in the Tekton Results API. - -Tekton Results will capture and store this custom annotation in a database, -making it available through the Tekton Result's List API. This allows -Dashboard/CLI clients to display more contextual information about each Result -without having to query additional APIs or sift through unrelated metadata. - -### Annotation Format - The specialized annotation for Tekton Results is stored in a specific format: ```json results.tekton.dev/recordSummaryAnnotations:{"repo":"pac-demo","commit":"62f8c8b7e4c3fc38cfbe7fcce2660e5b95de2d9a","eventType":"pull_request","pull_request-id":7} ``` + +This annotation is automatically added by Pipelines-as-Code to every PipelineRun +it initiates. +Unlike other annotations, which might be stored in `PipelineRun` or `TaskRun` metadata, +this custom annotation is selectively captured to provide additional information +specifically in the Tekton Results API. diff --git a/pkg/kubeinteraction/labels.go b/pkg/kubeinteraction/labels.go index 9277a732b..eecb54cc0 100644 --- a/pkg/kubeinteraction/labels.go +++ b/pkg/kubeinteraction/labels.go @@ -1,6 +1,7 @@ package kubeinteraction import ( + "fmt" "strconv" "github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode" @@ -10,7 +11,6 @@ import ( "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" "github.com/openshift-pipelines/pipelines-as-code/pkg/params/version" tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "go.uber.org/zap" ) const ( @@ -20,7 +20,7 @@ const ( StateFailed = "failed" ) -func AddLabelsAndAnnotations(event *info.Event, pipelineRun *tektonv1.PipelineRun, repo *apipac.Repository, providerinfo *info.ProviderConfig, logger *zap.SugaredLogger) { +func AddLabelsAndAnnotations(event *info.Event, pipelineRun *tektonv1.PipelineRun, repo *apipac.Repository, providerinfo *info.ProviderConfig) error { // Add labels on the soon to be created pipelinerun so UI/CLI can easily // query them. labels := map[string]string{ @@ -90,6 +90,8 @@ func AddLabelsAndAnnotations(event *info.Event, pipelineRun *tektonv1.PipelineRu // Add annotations to PipelineRuns to integrate with Tekton Results err := AddResultsAnnotation(event, pipelineRun) if err != nil { - logger.Errorf("Failed to add results annotations to PipelineRuns with error: %w", err) + return fmt.Errorf("failed to add results annotations with error: %w", err) } + + return nil } diff --git a/pkg/kubeinteraction/labels_test.go b/pkg/kubeinteraction/labels_test.go index 76da54b54..ff2d27f5d 100644 --- a/pkg/kubeinteraction/labels_test.go +++ b/pkg/kubeinteraction/labels_test.go @@ -7,7 +7,6 @@ import ( apipac "github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1" "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "go.uber.org/zap" "gotest.tools/v3/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -51,7 +50,8 @@ func TestAddLabelsAndAnnotations(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AddLabelsAndAnnotations(tt.args.event, tt.args.pipelineRun, tt.args.repo, &info.ProviderConfig{}, &zap.SugaredLogger{}) + err := AddLabelsAndAnnotations(tt.args.event, tt.args.pipelineRun, tt.args.repo, &info.ProviderConfig{}) + assert.NilError(t, err) assert.Assert(t, tt.args.pipelineRun.Labels[keys.URLOrg] == tt.args.event.Organization, "'%s' != %s", tt.args.pipelineRun.Labels[keys.URLOrg], tt.args.event.Organization) assert.Assert(t, tt.args.pipelineRun.Annotations[keys.URLOrg] == tt.args.event.Organization, "'%s' != %s", diff --git a/pkg/pipelineascode/pipelineascode.go b/pkg/pipelineascode/pipelineascode.go index 78547bc28..dbe16738f 100644 --- a/pkg/pipelineascode/pipelineascode.go +++ b/pkg/pipelineascode/pipelineascode.go @@ -146,7 +146,10 @@ func (p *PacRun) startPR(ctx context.Context, match matcher.Match) (*tektonv1.Pi } // Add labels and annotations to pipelinerun - kubeinteraction.AddLabelsAndAnnotations(p.event, match.PipelineRun, match.Repo, p.vcx.GetConfig(), p.logger) + err := kubeinteraction.AddLabelsAndAnnotations(p.event, match.PipelineRun, match.Repo, p.vcx.GetConfig()) + if err != nil { + p.logger.Errorf("Error adding labels/annotations to PipelineRun '%s' in namespace '%s': %v", match.PipelineRun.GetName(), match.Repo.GetName(), err) + } // if concurrency is defined then start the pipelineRun in pending state and // state as queued