Skip to content

Commit 96a5104

Browse files
committed
commonize bc input across strategies; better insure bc ouput is set
1 parent 91aabbd commit 96a5104

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

pkg/api/graph/graphview/image_pipeline.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func NewImagePipelineFromBuildConfigNode(g osgraph.Graph, bcNode *buildgraph.Bui
7575
flow.Source = src
7676
flow.Build = bcNode
7777
flow.LastSuccessfulBuild, flow.LastUnsuccessfulBuild, flow.ActiveBuilds = buildedges.RelevantBuilds(g, flow.Build)
78+
flow.Image = findBuildOutput(g, bcNode)
7879

7980
// we should have at most one
8081
for _, buildOutputNode := range g.SuccessorNodesByEdgeKind(bcNode, buildedges.BuildOutputEdgeKind) {
@@ -162,6 +163,14 @@ func findBuildInputs(g osgraph.Graph, bcNode *buildgraph.BuildConfigNode) (base
162163
return
163164
}
164165

166+
func findBuildOutput(g osgraph.Graph, bcNode *buildgraph.BuildConfigNode) (result ImageTagLocation) {
167+
for _, output := range g.SuccessorNodesByEdgeKind(bcNode, buildedges.BuildOutputEdgeKind) {
168+
result = output.(ImageTagLocation)
169+
return
170+
}
171+
return
172+
}
173+
165174
type SortedImagePipelines []ImagePipeline
166175

167176
func (m SortedImagePipelines) Len() int { return len(m) }

pkg/cmd/cli/describe/projectstatus.go

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ func describeDeploymentConfigTrigger(dc *deployapi.DeploymentConfig) string {
672672
func describeStandaloneBuildGroup(f formatter, pipeline graphview.ImagePipeline, namespace string) []string {
673673
switch {
674674
case pipeline.Build != nil:
675-
lines := []string{describeBuildInPipeline(f, pipeline.Build.BuildConfig, pipeline.BaseImage)}
675+
lines := []string{describeBuildInPipeline(f, pipeline, namespace)}
676676
if pipeline.Image != nil {
677677
lines = append(lines, fmt.Sprintf("pushes to %s", describeImageTagInPipeline(f, pipeline.Image, namespace)))
678678
}
@@ -687,11 +687,11 @@ func describeStandaloneBuildGroup(f formatter, pipeline graphview.ImagePipeline,
687687
func describeImageInPipeline(f formatter, pipeline graphview.ImagePipeline, namespace string) string {
688688
switch {
689689
case pipeline.Image != nil && pipeline.Build != nil:
690-
return fmt.Sprintf("%s <- %s", describeImageTagInPipeline(f, pipeline.Image, namespace), describeBuildInPipeline(f, pipeline.Build.BuildConfig, pipeline.BaseImage))
690+
return fmt.Sprintf("%s <- %s", describeImageTagInPipeline(f, pipeline.Image, namespace), describeBuildInPipeline(f, pipeline, namespace))
691691
case pipeline.Image != nil:
692692
return describeImageTagInPipeline(f, pipeline.Image, namespace)
693693
case pipeline.Build != nil:
694-
return describeBuildInPipeline(f, pipeline.Build.BuildConfig, pipeline.BaseImage)
694+
return describeBuildInPipeline(f, pipeline, namespace)
695695
default:
696696
return "<unknown>"
697697
}
@@ -709,33 +709,36 @@ func describeImageTagInPipeline(f formatter, image graphview.ImageTagLocation, n
709709
}
710710
}
711711

712-
func describeBuildInPipeline(f formatter, build *buildapi.BuildConfig, baseImage graphview.ImageTagLocation) string {
712+
func describeBuildInPipeline(f formatter, pipeline graphview.ImagePipeline, namespace string) string {
713+
bldType := ""
713714
switch {
714-
case build.Spec.Strategy.DockerStrategy != nil:
715-
// TODO: handle case where no source repo
716-
source, ok := describeSourceInPipeline(&build.Spec.Source)
717-
if !ok {
718-
return fmt.Sprintf("bc/%s unconfigured docker build - no source set", build.Name)
719-
}
720-
return fmt.Sprintf("bc/%s docker build of %s", build.Name, source)
721-
case build.Spec.Strategy.SourceStrategy != nil:
722-
source, ok := describeSourceInPipeline(&build.Spec.Source)
723-
if !ok {
724-
return fmt.Sprintf("bc/%s unconfigured source build", build.Name)
725-
}
726-
if baseImage == nil {
727-
return fmt.Sprintf("bc/%s %s; no image set", build.Name, source)
728-
}
729-
return fmt.Sprintf("bc/%s builds %s with %s", build.Name, source, baseImage.ImageSpec())
730-
case build.Spec.Strategy.CustomStrategy != nil:
731-
source, ok := describeSourceInPipeline(&build.Spec.Source)
732-
if !ok {
733-
return fmt.Sprintf("bc/%s custom build ", build.Name)
734-
}
735-
return fmt.Sprintf("bc/%s custom build of %s", build.Name, source)
715+
case pipeline.Build.BuildConfig.Spec.Strategy.DockerStrategy != nil:
716+
bldType = "docker"
717+
case pipeline.Build.BuildConfig.Spec.Strategy.SourceStrategy != nil:
718+
bldType = "source"
719+
case pipeline.Build.BuildConfig.Spec.Strategy.CustomStrategy != nil:
720+
bldType = "custom"
721+
case pipeline.Build.BuildConfig.Spec.Strategy.JenkinsPipelineStrategy != nil:
722+
return fmt.Sprintf("bc/%s is a Jenkins Pipeline", pipeline.Build.BuildConfig.Name)
736723
default:
737-
return fmt.Sprintf("bc/%s unrecognized build", build.Name)
724+
return fmt.Sprintf("bc/%s unrecognized build", pipeline.Build.BuildConfig.Name)
725+
}
726+
727+
source, ok := describeSourceInPipeline(&pipeline.Build.BuildConfig.Spec.Source)
728+
if !ok {
729+
return fmt.Sprintf("bc/%s unconfigured %s build", pipeline.Build.BuildConfig.Name, bldType)
730+
}
731+
732+
retStr := fmt.Sprintf("bc/%s %s build of %s", pipeline.Build.BuildConfig.Name, bldType, source)
733+
if pipeline.BaseImage == nil {
734+
retStr = retStr + " no base image set"
735+
} else {
736+
retStr = retStr + fmt.Sprintf(" with %s", describeImageTagInPipeline(f, pipeline.BaseImage, namespace))
737+
}
738+
if pipeline.Image == nil {
739+
retStr = retStr + " no output image set"
738740
}
741+
return retStr
739742
}
740743

741744
func describeAdditionalBuildDetail(build *buildgraph.BuildConfigNode, lastSuccessfulBuild *buildgraph.BuildNode, lastUnsuccessfulBuild *buildgraph.BuildNode, activeBuilds []*buildgraph.BuildNode, pushTargetResolved bool, includeSuccess bool) []string {

pkg/cmd/cli/describe/projectstatus_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ func TestProjectStatus(t *testing.T) {
150150
Contains: []string{
151151
"In project example on server https://example.com:8443\n",
152152
"svc/sinatra-example-2 - 172.30.17.48:8080",
153-
"builds git://github.com",
153+
"deploys istag/sinatra-example-2:latest <-",
154+
"build of git://github.com",
154155
"with docker.io/centos/ruby-22-centos7:latest",
155156
"not built yet",
156157
"deployment #1 waiting on image or update",
@@ -180,6 +181,8 @@ func TestProjectStatus(t *testing.T) {
180181
Contains: []string{
181182
// this makes sure that status knows this can push. If it fails, there's a "(can't push image)" next to like #8
182183
" hours\n build #7",
184+
"with fedora:23",
185+
"pushes to repo-base:latest",
183186
},
184187
Time: mustParseTime("2015-12-17T20:36:15Z"),
185188
},
@@ -193,6 +196,8 @@ func TestProjectStatus(t *testing.T) {
193196
ErrFn: func(err error) bool { return err == nil },
194197
Contains: []string{
195198
"Cycle detected in build configurations:",
199+
"with istag/ruby-22-centos7:latest",
200+
"pushes to istag/ruby-hello-world:latest",
196201
},
197202
},
198203
"running build": {
@@ -206,7 +211,7 @@ func TestProjectStatus(t *testing.T) {
206211
Contains: []string{
207212
"In project example on server https://example.com:8443\n",
208213
"svc/sinatra-example-1 - 172.30.17.47:8080",
209-
"builds git://github.com",
214+
"build of git://github.com",
210215
"with docker.io/centos/ruby-22-centos7:latest",
211216
"build #1 running for about a minute",
212217
"deployment #1 waiting on image or update",
@@ -250,6 +255,7 @@ func TestProjectStatus(t *testing.T) {
250255
"svc/database-external (all nodes):31000 -> 3306",
251256
"database test deploys",
252257
"frontend deploys",
258+
"istag/origin-ruby-sample:latest <-",
253259
"with docker.io/centos/ruby-22-centos7:latest",
254260
"deployment #3 pending on image",
255261
"deployment #2 failed less than a second ago: unable to contact server - 0/1 pods",

0 commit comments

Comments
 (0)