Skip to content

Commit

Permalink
address reviews
Browse files Browse the repository at this point in the history
Signed-off-by: Satyam Bhardwaj <[email protected]>
  • Loading branch information
Satyam Bhardwaj committed Dec 11, 2023
1 parent 4a6b861 commit f41862e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
20 changes: 6 additions & 14 deletions docs/content/docs/guide/statuses.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 5 additions & 3 deletions pkg/kubeinteraction/labels.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kubeinteraction

import (
"fmt"
"strconv"

"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode"
Expand All @@ -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 (
Expand All @@ -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{
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions pkg/kubeinteraction/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion pkg/pipelineascode/pipelineascode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f41862e

Please sign in to comment.