@@ -164,6 +164,37 @@ func (d *ProjectStatusDescriber) MakeGraph(namespace string) (osgraph.Graph, set
164
164
return g , forbiddenResources , nil
165
165
}
166
166
167
+ func selectorEquals (A , B map [string ]string ) bool {
168
+ if len (A ) == 0 && len (B ) == 0 {
169
+ return true
170
+ }
171
+ if len (A ) == 0 {
172
+ return false
173
+ }
174
+
175
+ for Ak , Av := range A {
176
+ if Bv , exists := B [Ak ]; ! exists || Av != Bv {
177
+ return false
178
+ }
179
+ }
180
+
181
+ return true
182
+ }
183
+
184
+ func containsSelector (selector map [string ]string , selectorGroup []map [string ]string ) bool {
185
+ if len (selector ) == 0 {
186
+ return false
187
+ }
188
+
189
+ for _ , grouppedSelector := range selectorGroup {
190
+ if selectorEquals (selector , grouppedSelector ) {
191
+ return true
192
+ }
193
+ }
194
+
195
+ return false
196
+ }
197
+
167
198
// Describe returns the description of a project
168
199
func (d * ProjectStatusDescriber ) Describe (namespace , name string ) (string , error ) {
169
200
var f formatter = namespacedFormatter {}
@@ -195,9 +226,25 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
195
226
196
227
coveredNodes := graphview.IntSet {}
197
228
198
- services , coveredByServices := graphview .AllServiceGroups (g , coveredNodes )
229
+ allServices , coveredByServices := graphview .AllServiceGroups (g , coveredNodes )
199
230
coveredNodes .Insert (coveredByServices .List ()... )
200
231
232
+ seenSelectors := []map [string ]string {}
233
+
234
+ services := []graphview.ServiceGroup {}
235
+ groupedServices := []graphview.ServiceGroup {}
236
+
237
+ // calculate services with identical selectors
238
+ for _ , svc := range allServices {
239
+ if containsSelector (svc .Service .Spec .Selector , seenSelectors ) {
240
+ groupedServices = append (groupedServices , svc )
241
+ continue
242
+ }
243
+
244
+ services = append (services , svc )
245
+ seenSelectors = append (seenSelectors , svc .Service .Spec .Selector )
246
+ }
247
+
201
248
standaloneDCs , coveredByDCs := graphview .AllDeploymentConfigPipelines (g , coveredNodes )
202
249
coveredNodes .Insert (coveredByDCs .List ()... )
203
250
@@ -243,6 +290,22 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
243
290
sort .Sort (exposedRoutes (exposes ))
244
291
245
292
fmt .Fprintln (out )
293
+
294
+ // print services that should be grouped with this service based on matching selectors
295
+ for _ , groupedSvc := range groupedServices {
296
+ if ! selectorEquals (groupedSvc .Service .Spec .Selector , service .Service .Spec .Selector ) {
297
+ continue
298
+ }
299
+
300
+ var grouppedExposes []string
301
+ for _ , routeNode := range groupedSvc .ExposingRoutes {
302
+ grouppedExposes = append (grouppedExposes , describeRouteInServiceGroup (local , routeNode )... )
303
+ }
304
+ sort .Sort (exposedRoutes (grouppedExposes ))
305
+
306
+ printLines (out , "" , 0 , describeServiceInServiceGroup (f , groupedSvc , grouppedExposes ... )... )
307
+ }
308
+
246
309
printLines (out , "" , 0 , describeServiceInServiceGroup (f , service , exposes ... )... )
247
310
248
311
for _ , dcPipeline := range service .DeploymentConfigPipelines {
0 commit comments