Skip to content

Commit 50cabc9

Browse files
committed
clayton's changes
1 parent 0333762 commit 50cabc9

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

pkg/build/apis/build/types.go

-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ const (
9090
// if the buildconfig does not specify a value. This only applies to buildconfigs created
9191
// via the new group api resource, not the legacy resource.
9292
DefaultFailedBuildsHistoryLimit = int32(5)
93-
94-
// ExcerptLength is the maximum length of the LogSnippet on a build.
95-
ExcerptLength = 5
9693
)
9794

9895
var (

pkg/build/apis/build/v1/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ type BuildStatus struct {
214214
// occured within each stage.
215215
Stages []StageInfo `json:"stages,omitempty" protobuf:"bytes,11,opt,name=stages"`
216216

217-
// LogSnippet is the last few lines of the build log. This value is only set for builds that failed.
217+
// logSnippet is the last few lines of the build log. This value is only set for builds that failed.
218218
LogSnippet string `json:"logSnippet,omitempty" protobuf:"bytes,12,opt,name=logSnippet"`
219219
}
220220

pkg/build/controller/build/build_controller.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ import (
4343

4444
const (
4545
maxRetries = 15
46+
47+
// maxExcerptLength is the maximum length of the LogSnippet on a build.
48+
maxExcerptLength = 5
4649
)
4750

4851
// BuildController watches builds and synchronizes them with their
@@ -634,13 +637,13 @@ func (bc *BuildController) updateBuild(build *buildapi.Build, update *buildUpdat
634637
// patchBuild generates a patch for the given build and buildUpdate
635638
// and applies that patch using the REST client
636639
func (bc *BuildController) patchBuild(build *buildapi.Build, update *buildUpdate) (*buildapi.Build, error) {
637-
638640
// Create a patch using the buildUpdate object
639641
updatedBuild, err := buildutil.BuildDeepCopy(build)
640642
if err != nil {
641643
return nil, fmt.Errorf("cannot create a deep copy of build %s: %v", buildDesc(build), err)
642644
}
643645
update.apply(updatedBuild)
646+
644647
patch, err := validation.CreateBuildPatch(build, updatedBuild)
645648
if err != nil {
646649
return nil, fmt.Errorf("failed to create a build patch: %v", err)
@@ -843,8 +846,8 @@ func setBuildCompletionData(build *buildapi.Build, pod *v1.Pod, update *buildUpd
843846
if len(msg) != 0 {
844847
parts := strings.Split(strings.TrimRight(msg, "\n"), "\n")
845848

846-
excerptLength := buildapi.ExcerptLength
847-
if len(parts) < buildapi.ExcerptLength {
849+
excerptLength := maxExcerptLength
850+
if len(parts) < maxExcerptLength {
848851
excerptLength = len(parts)
849852
}
850853
excerpt := parts[len(parts)-excerptLength:]

pkg/build/controller/build/build_controller_test.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,15 @@ func TestHandleBuild(t *testing.T) {
267267
update,
268268
},
269269
{
270-
name: "failed -> failed with completion timestamp",
271-
build: withCompletionTS(build(buildapi.BuildPhaseFailed)),
272-
pod: pod(v1.PodFailed),
273-
expectUpdate: nil,
270+
name: "failed -> failed with completion timestamp+message",
271+
build: withCompletionTS(build(buildapi.BuildPhaseFailed)),
272+
pod: pod(v1.PodFailed),
273+
expectOnComplete: true,
274+
expectUpdate: newUpdate().
275+
startTime(now).
276+
completionTime(now).
277+
logSnippet("").
278+
update,
274279
},
275280
}
276281

@@ -1188,6 +1193,11 @@ func (b *updateBuilder) podNameAnnotation(podName string) *updateBuilder {
11881193
return b
11891194
}
11901195

1196+
func (b *updateBuilder) logSnippet(message string) *updateBuilder {
1197+
b.update.setLogSnippet(message)
1198+
return b
1199+
}
1200+
11911201
type fakeRunPolicy struct {
11921202
notRunnable bool
11931203
onCompleteCalled bool

0 commit comments

Comments
 (0)