@@ -162,6 +162,91 @@ func FindCircularBuilds(g osgraph.Graph, f osgraph.Namer) []osgraph.Marker {
162
162
return markers
163
163
}
164
164
165
+ // multiBCStartBuildSuggestion builds the `oc start-build` suggestion string with multiple build configs
166
+ func multiBCStartBuildSuggestion (bcNodes []* buildgraph.BuildConfigNode ) string {
167
+ var ret string
168
+ if len (bcNodes ) > 1 {
169
+ ret = "Run one of the following commands: "
170
+ }
171
+ for i , bcNode := range bcNodes {
172
+ // use of f.ResourceName(bcNode) will produce a string like oc start-build BuildConfig|example/ruby-hello-world
173
+ ret = ret + fmt .Sprintf ("oc start-build %s" , bcNode .BuildConfig .GetName ())
174
+ if i < (len (bcNodes ) - 1 ) {
175
+ ret = ret + ", "
176
+ }
177
+ }
178
+ return ret
179
+ }
180
+
181
+ // bcNodesToRelatedNodes takes an array of BuildConfigNode's and returns an array of graph.Node's for the Marker.RelatedNodes field
182
+ func bcNodesToRelatedNodes (bcNodes []* buildgraph.BuildConfigNode ) []graph.Node {
183
+ relatedNodes := []graph.Node {}
184
+ for _ , bcNode := range bcNodes {
185
+ relatedNodes = append (relatedNodes , graph .Node (bcNode ))
186
+ }
187
+ return relatedNodes
188
+ }
189
+
190
+ // findPendingTagMarkers is the guts behind FindPendingTags .... break out some of the content and reduce some indentation
191
+ func findPendingTagMarkers (istNode * imagegraph.ImageStreamTagNode , g osgraph.Graph , f osgraph.Namer ) []osgraph.Marker {
192
+ markers := []osgraph.Marker {}
193
+
194
+ buildFound := false
195
+ bcNodes := buildedges .BuildConfigsForTag (g , graph .Node (istNode ))
196
+ for _ , bcNode := range bcNodes {
197
+ latestBuild := buildedges .GetLatestBuild (g , bcNode )
198
+
199
+ // A build config points to the non existent tag but no current build exists.
200
+ if latestBuild == nil {
201
+ continue
202
+ }
203
+ buildFound = true
204
+
205
+ // A build config points to the non existent tag but something is going on with
206
+ // the latest build.
207
+ // TODO: Handle other build phases.
208
+ switch latestBuild .Build .Status .Phase {
209
+ case buildapi .BuildPhaseCancelled :
210
+ // TODO: Add a warning here.
211
+ case buildapi .BuildPhaseError :
212
+ // TODO: Add a warning here.
213
+ case buildapi .BuildPhaseComplete :
214
+ // We should never hit this. The output of our build is missing but the build is complete.
215
+ // Most probably the user has messed up?
216
+ case buildapi .BuildPhaseFailed :
217
+ // Since the tag hasn't been populated yet, we assume there hasn't been a successful
218
+ // build so far.
219
+ markers = append (markers , osgraph.Marker {
220
+ Node : graph .Node (latestBuild ),
221
+ RelatedNodes : []graph.Node {graph .Node (istNode ), graph .Node (bcNode )},
222
+
223
+ Severity : osgraph .ErrorSeverity ,
224
+ Key : LatestBuildFailedErr ,
225
+ Message : fmt .Sprintf ("%s has failed." , f .ResourceName (latestBuild )),
226
+ Suggestion : osgraph .Suggestion (fmt .Sprintf ("Inspect the build failure with 'oc logs -f bc/%s'" , bcNode .BuildConfig .GetName ())),
227
+ })
228
+ default :
229
+ // Do nothing when latest build is new, pending, or running.
230
+ }
231
+
232
+ }
233
+
234
+ // if no current builds exist for any of the build configs, append marker for that
235
+ // but ignore ISTs which have no build configs
236
+ if ! buildFound && len (bcNodes ) > 0 {
237
+ markers = append (markers , osgraph.Marker {
238
+ Node : graph .Node (istNode ),
239
+ RelatedNodes : bcNodesToRelatedNodes (bcNodes ),
240
+
241
+ Severity : osgraph .WarningSeverity ,
242
+ Key : TagNotAvailableWarning ,
243
+ Message : fmt .Sprintf ("%s needs to be imported or created by a build." , f .ResourceName (istNode )),
244
+ Suggestion : osgraph .Suggestion (multiBCStartBuildSuggestion (bcNodes )),
245
+ })
246
+ }
247
+ return markers
248
+ }
249
+
165
250
// FindPendingTags inspects all imageStreamTags that serve as outputs to builds.
166
251
//
167
252
// Precedence of failures:
@@ -172,49 +257,8 @@ func FindPendingTags(g osgraph.Graph, f osgraph.Namer) []osgraph.Marker {
172
257
173
258
for _ , uncastIstNode := range g .NodesByKind (imagegraph .ImageStreamTagNodeKind ) {
174
259
istNode := uncastIstNode .(* imagegraph.ImageStreamTagNode )
175
- if bcNode := buildedges .BuildConfigForTag (g , uncastIstNode ); bcNode != nil && ! istNode .Found () {
176
- latestBuild := buildedges .GetLatestBuild (g , bcNode )
177
-
178
- // A build config points to the non existent tag but no current build exists.
179
- if latestBuild == nil {
180
- markers = append (markers , osgraph.Marker {
181
- Node : graph .Node (bcNode ),
182
- RelatedNodes : []graph.Node {uncastIstNode },
183
-
184
- Severity : osgraph .WarningSeverity ,
185
- Key : TagNotAvailableWarning ,
186
- Message : fmt .Sprintf ("%s needs to be imported or created by a build." , f .ResourceName (istNode )),
187
- Suggestion : osgraph .Suggestion (fmt .Sprintf ("oc start-build %s" , f .ResourceName (bcNode ))),
188
- })
189
- continue
190
- }
191
-
192
- // A build config points to the non existent tag but something is going on with
193
- // the latest build.
194
- // TODO: Handle other build phases.
195
- switch latestBuild .Build .Status .Phase {
196
- case buildapi .BuildPhaseCancelled :
197
- // TODO: Add a warning here.
198
- case buildapi .BuildPhaseError :
199
- // TODO: Add a warning here.
200
- case buildapi .BuildPhaseComplete :
201
- // We should never hit this. The output of our build is missing but the build is complete.
202
- // Most probably the user has messed up?
203
- case buildapi .BuildPhaseFailed :
204
- // Since the tag hasn't been populated yet, we assume there hasn't been a successful
205
- // build so far.
206
- markers = append (markers , osgraph.Marker {
207
- Node : graph .Node (latestBuild ),
208
- RelatedNodes : []graph.Node {uncastIstNode , graph .Node (bcNode )},
209
-
210
- Severity : osgraph .ErrorSeverity ,
211
- Key : LatestBuildFailedErr ,
212
- Message : fmt .Sprintf ("%s has failed." , f .ResourceName (latestBuild )),
213
- Suggestion : osgraph .Suggestion (fmt .Sprintf ("Inspect the build failure with 'oc logs %s'" , f .ResourceName (latestBuild ))),
214
- })
215
- default :
216
- // Do nothing when latest build is new, pending, or running.
217
- }
260
+ if ! istNode .Found () {
261
+ markers = append (markers , findPendingTagMarkers (istNode , g , f )... )
218
262
}
219
263
}
220
264
0 commit comments