Skip to content

Commit

Permalink
fix: add startAt and endAt for Tekton runs (#84)
Browse files Browse the repository at this point in the history
Why:
- currently the pipeline start at and end at are not properly set

---------

Signed-off-by: lijie <lijie@pingcap.com>
  • Loading branch information
lijie0123 committed Feb 28, 2024
1 parent 4ebfa44 commit 191def3
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 50 deletions.
13 changes: 8 additions & 5 deletions tibuild/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ const docTemplate = `{
"platform": {
"type": "string"
},
"sha256OciFile": {
"$ref": "#/definitions/service.OciFile"
},
"sha256URL": {
"type": "string"
},
Expand Down Expand Up @@ -672,6 +675,9 @@ const docTemplate = `{
"service.TektonPipeline": {
"type": "object",
"properties": {
"endAt": {
"type": "string"
},
"gitHash": {
"type": "string"
},
Expand All @@ -690,13 +696,10 @@ const docTemplate = `{
"$ref": "#/definitions/service.OciArtifact"
}
},
"pipelineEndAt": {
"type": "string"
},
"pipelineStartAt": {
"platform": {
"type": "string"
},
"platform": {
"startAt": {
"type": "string"
},
"status": {
Expand Down
13 changes: 8 additions & 5 deletions tibuild/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@
"platform": {
"type": "string"
},
"sha256OciFile": {
"$ref": "#/definitions/service.OciFile"
},
"sha256URL": {
"type": "string"
},
Expand Down Expand Up @@ -660,6 +663,9 @@
"service.TektonPipeline": {
"type": "object",
"properties": {
"endAt": {
"type": "string"
},
"gitHash": {
"type": "string"
},
Expand All @@ -678,13 +684,10 @@
"$ref": "#/definitions/service.OciArtifact"
}
},
"pipelineEndAt": {
"type": "string"
},
"pipelineStartAt": {
"platform": {
"type": "string"
},
"platform": {
"startAt": {
"type": "string"
},
"status": {
Expand Down
10 changes: 6 additions & 4 deletions tibuild/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ definitions:
$ref: '#/definitions/service.OciFile'
platform:
type: string
sha256OciFile:
$ref: '#/definitions/service.OciFile'
sha256URL:
type: string
url:
Expand Down Expand Up @@ -244,6 +246,8 @@ definitions:
type: object
service.TektonPipeline:
properties:
endAt:
type: string
gitHash:
type: string
images:
Expand All @@ -256,12 +260,10 @@ definitions:
items:
$ref: '#/definitions/service.OciArtifact'
type: array
pipelineEndAt:
type: string
pipelineStartAt:
type: string
platform:
type: string
startAt:
type: string
status:
$ref: '#/definitions/service.BuildStatus'
url:
Expand Down
16 changes: 8 additions & 8 deletions tibuild/pkg/rest/service/dev_build_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ func collectTektonArtifacts(pipelines []TektonPipeline, report *BuildReport) {
func getTektonStartAt(pipelines []TektonPipeline) *time.Time {
var startAt *time.Time = nil
for _, pipeline := range pipelines {
if pipeline.PipelineStartAt != nil {
if pipeline.StartAt != nil {
if startAt == nil {
startAt = pipeline.PipelineStartAt
} else if pipeline.PipelineStartAt.Before(*startAt) {
startAt = pipeline.PipelineStartAt
startAt = pipeline.StartAt
} else if pipeline.StartAt.Before(*startAt) {
startAt = pipeline.StartAt
}
}
}
Expand Down Expand Up @@ -445,11 +445,11 @@ func computeTektonPhase(pipelines []TektonPipeline) BuildStatus {
func getLatestEndAt(pipelines []TektonPipeline) *time.Time {
var latest_endat *time.Time
for _, pipeline := range pipelines {
if pipeline.PipelineEndAt != nil {
if pipeline.EndAt != nil {
if latest_endat == nil {
latest_endat = pipeline.PipelineEndAt
} else if latest_endat.Before(*pipeline.PipelineEndAt) {
latest_endat = pipeline.PipelineEndAt
latest_endat = pipeline.EndAt
} else if latest_endat.Before(*pipeline.EndAt) {
latest_endat = pipeline.EndAt
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions tibuild/pkg/rest/service/dev_build_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ func TestTektonStatusMerge(t *testing.T) {
tekton := &TektonStatus{
Pipelines: []TektonPipeline{
{Name: "pipelinerun1", Status: BuildStatusSuccess, Platform: LinuxAmd64,
PipelineStartAt: &starttime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Tag: "master", Files: []string{"a.tar.gz", "b.tar.gz"}}},
Images: []ImageArtifact{{URL: "harbor.net/org/image:tag1"}}},
StartAt: &starttime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Tag: "master", Files: []string{"a.tar.gz", "b.tar.gz"}}},
Images: []ImageArtifact{{URL: "harbor.net/org/image:tag1"}}},
{Name: "pipelinerun2", Status: BuildStatusSuccess, Platform: LinuxArm64,
PipelineStartAt: &starttime,
PipelineEndAt: &endtime,
Images: []ImageArtifact{{URL: "harbor.net/org/image:tag2"}},
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Tag: "master", Files: []string{"c.tar.gz", "d.tar.gz"}}}},
StartAt: &starttime,
EndAt: &endtime,
Images: []ImageArtifact{{URL: "harbor.net/org/image:tag2"}},
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Tag: "master", Files: []string{"c.tar.gz", "d.tar.gz"}}}},
},
}
status := &DevBuildStatus{TektonStatus: tekton}
Expand All @@ -388,13 +388,13 @@ func TestTektonStatusMerge(t *testing.T) {
tekton := &TektonStatus{
Pipelines: []TektonPipeline{
{Name: "pipelinerun1", Status: BuildStatusSuccess, Platform: LinuxAmd64,
PipelineStartAt: &starttime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Files: []string{"a.tar.gz", "b.tar.gz"}}},
Images: []ImageArtifact{{URL: "harbor.net/org/image:tag1"}}},
StartAt: &starttime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Files: []string{"a.tar.gz", "b.tar.gz"}}},
Images: []ImageArtifact{{URL: "harbor.net/org/image:tag1"}}},
{Name: "pipelinerun2", Status: BuildStatusProcessing, Platform: LinuxArm64,
PipelineStartAt: &starttime,
PipelineEndAt: &endtime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Files: []string{"c.tar.gz", "d.tar.gz"}}}},
StartAt: &starttime,
EndAt: &endtime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Files: []string{"c.tar.gz", "d.tar.gz"}}}},
},
}
status := &DevBuildStatus{TektonStatus: tekton}
Expand All @@ -405,13 +405,13 @@ func TestTektonStatusMerge(t *testing.T) {
tekton := &TektonStatus{
Pipelines: []TektonPipeline{
{Name: "pipelinerun1", Status: BuildStatusSuccess, Platform: LinuxAmd64,
PipelineStartAt: &starttime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Tag: "latest", Files: []string{"a.tar.gz", "b.tar.gz"}}},
Images: []ImageArtifact{{URL: "harbor.net/org/image:tag1"}}},
StartAt: &starttime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Tag: "latest", Files: []string{"a.tar.gz", "b.tar.gz"}}},
Images: []ImageArtifact{{URL: "harbor.net/org/image:tag1"}}},
{Name: "pipelinerun2", Status: BuildStatusFailure, Platform: LinuxArm64,
PipelineStartAt: &starttime,
PipelineEndAt: &endtime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Files: []string{"c.tar.gz", "d.tar.gz"}}}},
StartAt: &starttime,
EndAt: &endtime,
OciArtifacts: []OciArtifact{{Repo: "harbor.net/org/repo", Files: []string{"c.tar.gz", "d.tar.gz"}}}},
},
}
status := &DevBuildStatus{TektonStatus: tekton}
Expand Down
18 changes: 9 additions & 9 deletions tibuild/pkg/rest/service/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ type TektonStatus struct {
}

type TektonPipeline struct {
Name string `json:"name"`
URL string `json:"url,omitempty"`
GitHash string `json:"gitHash,omitempty"`
Status BuildStatus `json:"status"`
Platform Platform `json:"platform,omitempty"`
PipelineStartAt *time.Time `json:"pipelineStartAt,omitempty"`
PipelineEndAt *time.Time `json:"pipelineEndAt,omitempty"`
OciArtifacts []OciArtifact `json:"ociArtifacts,omitempty"`
Images []ImageArtifact `json:"images,omitempty"`
Name string `json:"name"`
URL string `json:"url,omitempty"`
GitHash string `json:"gitHash,omitempty"`
Status BuildStatus `json:"status"`
Platform Platform `json:"platform,omitempty"`
StartAt *time.Time `json:"startAt,omitempty"`
EndAt *time.Time `json:"endAt,omitempty"`
OciArtifacts []OciArtifact `json:"ociArtifacts,omitempty"`
Images []ImageArtifact `json:"images,omitempty"`
}

type OciArtifact struct {
Expand Down
2 changes: 2 additions & 0 deletions tibuild/pkg/webhook/service/cloudevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func toDevbuildPipeline(pipeline tekton.PipelineRun) (*rest.TektonPipeline, erro
GitHash: parseGitHash(pipeline),
OciArtifacts: convertOciArtifacts(pipeline),
Images: images,
StartAt: &pipeline.Status.StartTime.Time,
EndAt: &pipeline.Status.CompletionTime.Time,
}, nil
}

Expand Down

0 comments on commit 191def3

Please sign in to comment.