Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BuildRun Status source #1411

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 29 additions & 39 deletions deploy/crds/shipwright.io_buildruns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12520,45 +12520,35 @@ spec:
format: int64
type: integer
type: object
sources:
description: Sources holds the results emitted from the step definition
of different sources
items:
description: SourceResult holds the results emitted from the different
sources
properties:
git:
description: Git holds the results emitted from the source step
of type git
properties:
branchName:
description: BranchName holds the default branch name of
the git source this will be set only when revision is
not specified in Build object
type: string
commitAuthor:
description: CommitAuthor holds the commit author of a git
source
type: string
commitSha:
description: CommitSha holds the commit sha of git source
type: string
type: object
name:
description: Name is the name of source
type: string
ociArtifact:
description: OciArtifact holds the results emitted from the
source step of type ociArtifact
properties:
digest:
description: Digest hold the image digest result
type: string
type: object
required:
- name
type: object
type: array
source:
description: Source holds the results emitted from the source step
properties:
git:
description: Git holds the results emitted from the source step
of type git
properties:
branchName:
description: BranchName holds the default branch name of the
git source this will be set only when revision is not specified
in Build object
type: string
commitAuthor:
description: CommitAuthor holds the commit author of a git
source
type: string
commitSha:
description: CommitSha holds the commit sha of git source
type: string
type: object
ociArtifact:
description: OciArtifact holds the results emitted from the source
step of type ociArtifact
properties:
digest:
description: Digest hold the image digest result
type: string
type: object
type: object
startTime:
description: StartTime is the time the build is actually started.
format: date-time
Expand Down
8 changes: 3 additions & 5 deletions pkg/apis/build/v1beta1/buildrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ func (src *BuildRun) ConvertFrom(ctx context.Context, obj *unstructured.Unstruct

src.Spec.ConvertFrom(&alphaBuildRun.Spec)

sources := []SourceResult{}
var sourceStatus *SourceResult
for _, s := range alphaBuildRun.Status.Sources {
sr := SourceResult{
Name: s.Name,
sourceStatus = &SourceResult{
Git: (*GitSourceResult)(s.Git),
OciArtifact: (*OciArtifactSourceResult)(s.Bundle),
}
sources = append(sources, sr)
}

conditions := []Condition{}
Expand All @@ -169,7 +167,7 @@ func (src *BuildRun) ConvertFrom(ctx context.Context, obj *unstructured.Unstruct
}

src.Status = BuildRunStatus{
Sources: sources,
Source: sourceStatus,
Output: (*Output)(alphaBuildRun.Status.Output),
Conditions: conditions,
TaskRunName: alphaBuildRun.Status.LatestTaskRunRef,
Expand Down
7 changes: 2 additions & 5 deletions pkg/apis/build/v1beta1/buildrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ const (

// SourceResult holds the results emitted from the different sources
type SourceResult struct {
// Name is the name of source
Name string `json:"name"`

// Git holds the results emitted from the
// source step of type git
Expand Down Expand Up @@ -162,11 +160,10 @@ type Output struct {

// BuildRunStatus defines the observed state of BuildRun
type BuildRunStatus struct {
// Sources holds the results emitted from the step definition
// of different sources
// Source holds the results emitted from the source step
//
// +optional
Sources []SourceResult `json:"sources,omitempty"`
Source *SourceResult `json:"source,omitempty"`

// Output holds the results emitted from step definition of an output
//
Expand Down
10 changes: 4 additions & 6 deletions pkg/apis/build/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions test/e2e/v1beta1/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func validateBuildRunResultsFromGitSource(testBuildRun *buildv1beta1.BuildRun) {
testBuildRun, err := testBuild.GetBR(testBuildRun.Name)
Expect(err).ToNot(HaveOccurred())

Expect(len(testBuildRun.Status.Sources)).To(Equal(1))
Expect(testBuildRun.Status.Source).ToNot(BeNil())

// Only run the TaskRun checks if Tekton objects can be accessed
if os.Getenv(EnvVarVerifyTektonObjects) == "true" {
Expand All @@ -167,11 +167,11 @@ func validateBuildRunResultsFromGitSource(testBuildRun *buildv1beta1.BuildRun) {
for _, result := range tr.Status.TaskRunResults {
switch result.Name {
case "shp-source-default-commit-sha":
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Sources[0].Git.CommitSha))
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Source.Git.CommitSha))
case "shp-source-default-commit-author":
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Sources[0].Git.CommitAuthor))
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Source.Git.CommitAuthor))
case "shp-source-default-branch-name":
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Sources[0].Git.BranchName))
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Source.Git.BranchName))
case "shp-image-digest":
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Output.Digest))
case "shp-image-size":
Expand All @@ -187,7 +187,7 @@ func validateBuildRunResultsFromBundleSource(testBuildRun *buildv1beta1.BuildRun
testBuildRun, err := testBuild.GetBR(testBuildRun.Name)
Expect(err).ToNot(HaveOccurred())

Expect(len(testBuildRun.Status.Sources)).To(Equal(1))
Expect(testBuildRun.Status.Source).ToNot(BeNil())

// Only run the TaskRun checks if Tekton objects can be accessed
if os.Getenv(EnvVarVerifyTektonObjects) == "true" {
Expand All @@ -197,7 +197,7 @@ func validateBuildRunResultsFromBundleSource(testBuildRun *buildv1beta1.BuildRun
for _, result := range tr.Status.TaskRunResults {
switch result.Name {
case "shp-source-default-image-digest":
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Sources[0].OciArtifact.Digest))
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Source.OciArtifact.Digest))
case "shp-image-digest":
Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Output.Digest))
case "shp-image-size":
Expand Down