Skip to content

Commit eb0a20e

Browse files
committed
commonize bc input across strategies; better insure bc ouput is set
1 parent 1b04cb2 commit eb0a20e

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
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: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,9 @@ 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 {
677-
lines = append(lines, fmt.Sprintf("pushes to %s", describeImageTagInPipeline(f, pipeline.Image, namespace)))
677+
lines = append(lines, fmt.Sprintf("-> %s", describeImageTagInPipeline(f, pipeline.Image, namespace)))
678678
}
679679
return lines
680680
case pipeline.Image != nil:
@@ -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,31 @@ 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 builds %s", pipeline.Build.BuildConfig.Name, bldType, source)
733+
if pipeline.BaseImage != nil {
734+
retStr = retStr + fmt.Sprintf(" on %s", describeImageTagInPipeline(f, pipeline.BaseImage, namespace))
738735
}
736+
return retStr
739737
}
740738

741739
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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ 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+
"deploys istag/sinatra-example-2:latest <-",
153154
"builds git://github.com",
154-
"with docker.io/centos/ruby-22-centos7:latest",
155+
"on docker.io/centos/ruby-22-centos7:latest",
155156
"not built yet",
156157
"deployment #1 waiting on image or update",
157158
"View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.",
@@ -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+
"on fedora:23",
185+
"-> 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+
"on istag/ruby-22-centos7:latest",
200+
"-> istag/ruby-hello-world:latest",
196201
},
197202
},
198203
"running build": {
@@ -207,7 +212,7 @@ func TestProjectStatus(t *testing.T) {
207212
"In project example on server https://example.com:8443\n",
208213
"svc/sinatra-example-1 - 172.30.17.47:8080",
209214
"builds git://github.com",
210-
"with docker.io/centos/ruby-22-centos7:latest",
215+
"on docker.io/centos/ruby-22-centos7:latest",
211216
"build #1 running for about a minute",
212217
"deployment #1 waiting on image or update",
213218
"View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.",
@@ -227,7 +232,7 @@ func TestProjectStatus(t *testing.T) {
227232
"svc/sinatra-app-example - 172.30.17.49:8080",
228233
"sinatra-app-example-a deploys",
229234
"sinatra-app-example-b deploys",
230-
"with docker.io/centos/ruby-22-centos7:latest",
235+
"on docker.io/centos/ruby-22-centos7:latest",
231236
"build #1 running for about a minute",
232237
"- 7a4f354: Prepare v1beta3 Template types (Roy Programmer <[email protected]>)",
233238
"View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.",
@@ -250,7 +255,8 @@ func TestProjectStatus(t *testing.T) {
250255
"svc/database-external (all nodes):31000 -> 3306",
251256
"database test deploys",
252257
"frontend deploys",
253-
"with docker.io/centos/ruby-22-centos7:latest",
258+
"istag/origin-ruby-sample:latest <-",
259+
"on 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",
256262
"deployment #1 deployed less than a second ago",

0 commit comments

Comments
 (0)