Skip to content

Commit

Permalink
Merge pull request #1411 from SaschaSchwarze0/sascha-fix-buildrun-sta…
Browse files Browse the repository at this point in the history
…tus-source

Fix BuildRun Status source
  • Loading branch information
openshift-ci[bot] authored Oct 19, 2023
2 parents 59c8919 + abd0b37 commit 586adf0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 61 deletions.
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

0 comments on commit 586adf0

Please sign in to comment.