From abd0b377a523c27ced0f888ea66a481280b643e9 Mon Sep 17 00:00:00 2001 From: Sascha Schwarze Date: Wed, 18 Oct 2023 22:35:02 +0200 Subject: [PATCH] Fix BuildRun Status source --- deploy/crds/shipwright.io_buildruns.yaml | 68 ++++++++----------- pkg/apis/build/v1beta1/buildrun_conversion.go | 8 +-- pkg/apis/build/v1beta1/buildrun_types.go | 7 +- .../build/v1beta1/zz_generated.deepcopy.go | 10 ++- test/e2e/v1beta1/validators_test.go | 12 ++-- 5 files changed, 44 insertions(+), 61 deletions(-) diff --git a/deploy/crds/shipwright.io_buildruns.yaml b/deploy/crds/shipwright.io_buildruns.yaml index d9278535a..51cb70047 100644 --- a/deploy/crds/shipwright.io_buildruns.yaml +++ b/deploy/crds/shipwright.io_buildruns.yaml @@ -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 diff --git a/pkg/apis/build/v1beta1/buildrun_conversion.go b/pkg/apis/build/v1beta1/buildrun_conversion.go index 4d1e213b7..27f3c0d30 100644 --- a/pkg/apis/build/v1beta1/buildrun_conversion.go +++ b/pkg/apis/build/v1beta1/buildrun_conversion.go @@ -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{} @@ -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, diff --git a/pkg/apis/build/v1beta1/buildrun_types.go b/pkg/apis/build/v1beta1/buildrun_types.go index 2880a4213..7a40e822b 100644 --- a/pkg/apis/build/v1beta1/buildrun_types.go +++ b/pkg/apis/build/v1beta1/buildrun_types.go @@ -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 @@ -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 // diff --git a/pkg/apis/build/v1beta1/zz_generated.deepcopy.go b/pkg/apis/build/v1beta1/zz_generated.deepcopy.go index f7660573f..4c3dc1dfe 100644 --- a/pkg/apis/build/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/build/v1beta1/zz_generated.deepcopy.go @@ -296,12 +296,10 @@ func (in *BuildRunSpec) DeepCopy() *BuildRunSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BuildRunStatus) DeepCopyInto(out *BuildRunStatus) { *out = *in - if in.Sources != nil { - in, out := &in.Sources, &out.Sources - *out = make([]SourceResult, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } + if in.Source != nil { + in, out := &in.Source, &out.Source + *out = new(SourceResult) + (*in).DeepCopyInto(*out) } if in.Output != nil { in, out := &in.Output, &out.Output diff --git a/test/e2e/v1beta1/validators_test.go b/test/e2e/v1beta1/validators_test.go index 46eb6f9a8..05d1bcb2f 100644 --- a/test/e2e/v1beta1/validators_test.go +++ b/test/e2e/v1beta1/validators_test.go @@ -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" { @@ -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": @@ -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" { @@ -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":