forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverview.js
1380 lines (1201 loc) · 51 KB
/
overview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
angular.module('openshiftConsole').controller('OverviewController', [
'$scope',
'$filter',
'$routeParams',
'AlertMessageService',
'APIService',
'AppsService',
'BuildsService',
'CatalogService',
'Constants',
'DataService',
'DeploymentsService',
'HPAService',
'HTMLService',
'ImageStreamResolver',
'KeywordService',
'LabelFilter',
'Logger',
'MetricsService',
'Navigate',
'OwnerReferencesService',
'PodsService',
'ProjectsService',
'BindingService',
'ResourceAlertsService',
'RoutesService',
OverviewController
]);
function OverviewController($scope,
$filter,
$routeParams,
AlertMessageService,
APIService,
AppsService,
BuildsService,
CatalogService,
Constants,
DataService,
DeploymentsService,
HPAService,
HTMLService,
ImageStreamResolver,
KeywordService,
LabelFilter,
Logger,
MetricsService,
Navigate,
OwnerReferencesService,
PodsService,
ProjectsService,
BindingService,
ResourceAlertsService,
RoutesService) {
var overview = this;
var limitWatches = $filter('isIE')() || $filter('isEdge')();
var DEFAULT_POLL_INTERVAL = 60 * 1000; // milliseconds
$scope.projectName = $routeParams.project;
// Filters used by this controller.
var annotation = $filter('annotation');
var getBuildConfigName = $filter('buildConfigForBuild');
var deploymentIsInProgress = $filter('deploymentIsInProgress');
var imageObjectRef = $filter('imageObjectRef');
var isJenkinsPipelineStrategy = $filter('isJenkinsPipelineStrategy');
var isNewerResource = $filter('isNewerResource');
var label = $filter('label');
var getPodTemplate = $filter('podTemplate');
var deploymentsByUID;
var imageStreams;
var labelSuggestions = {};
var pipelineLabelSuggestions = {};
// The most recent replication controller by deployment config name. This
// might not be the active deployment if failed or cancelled.
var mostRecentByDeploymentConfig = {};
// `overview.state` tracks common state that is shared with overview-list-row.
// This avoids having to pass the same values as attributes again and again
// for different types, but lets us update these maps in one place as needed
// from watch callbacks in the overview controller.
//
// NOTE: Do not change or remove properties without updating overview-list-row.
var state = overview.state = {
alerts: {},
builds: {},
clusterQuotas: {},
imageStreamImageRefByDockerReference: {},
imagesByDockerReference: {},
limitRanges: {},
limitWatches: limitWatches,
notificationsByObjectUID: {},
pipelinesByDeploymentConfig: {},
podsByOwnerUID: {},
quotas: {},
recentPipelinesByDeploymentConfig: {},
routesByService: {},
servicesByObjectUID: {},
serviceInstances: {},
bindingsByInstanceRef: {},
bindingsByApplicationUID: {},
applicationsByBinding: {},
// Set to true below when metrics are available.
showMetrics: false
};
// Track the breakpoint ourselves so we can remove elements from the page,
// rather than hiding them using CSS. This avoids rendering charts more than
// once for the responsive layout, which switches to tabs at smaller screen
// widths.
overview.state.breakpoint = HTMLService.getBreakpoint();
var onResize = _.throttle(function() {
var breakpoint = HTMLService.getBreakpoint();
if (overview.state.breakpoint !== breakpoint) {
$scope.$evalAsync(function() {
overview.state.breakpoint = breakpoint;
});
}
}, 50);
$(window).on('resize.overview', onResize);
overview.showGetStarted = false;
overview.showLoading = true;
overview.filterByOptions = [{
id: 'name',
label: 'Name'
}, {
id: 'label',
label: 'Label'
}];
// If there is a label filter persisted (such as in the URL), default to filtering by label.
overview.filterBy = LabelFilter.getLabelSelector().isEmpty() ? 'name' : 'label';
overview.viewByOptions = [{
id: 'app',
label: 'Application'
}, {
id: 'resource',
label: 'Resource Type'
}, {
id: 'pipeline',
label: 'Pipeline'
}];
var getName = function(apiObject) {
return _.get(apiObject, 'metadata.name');
};
var getUID = function(apiObject) {
return _.get(apiObject, 'metadata.uid');
};
// The size of all visible top-level items.
var size = function() {
return _.size(overview.deploymentConfigs) +
_.size(overview.vanillaReplicationControllers) +
_.size(overview.deployments) +
_.size(overview.vanillaReplicaSets) +
_.size(overview.statefulSets) +
_.size(overview.monopods) +
_.size(overview.state.serviceInstances);
};
// The size of all visible top-level items after filtering.
var filteredSize = function() {
return _.size(overview.filteredDeploymentConfigs) +
_.size(overview.filteredReplicationControllers) +
_.size(overview.filteredDeployments) +
_.size(overview.filteredReplicaSets) +
_.size(overview.filteredStatefulSets) +
_.size(overview.filteredMonopods) +
_.size(overview.filteredServiceInstances);
};
// Show the "Get Started" message if the project is empty.
var updateShowGetStarted = function() {
overview.size = size();
overview.filteredSize = filteredSize();
// Check if there is any data visible in the overview.
var projectEmpty = overview.size === 0;
// Check if we've loaded the top-level items we show on the overview.
var loaded = overview.deploymentConfigs &&
overview.replicationControllers &&
overview.deployments &&
overview.replicaSets &&
overview.statefulSets &&
overview.pods &&
overview.state.serviceInstances;
state.expandAll = loaded && overview.size === 1;
overview.showGetStarted = loaded && projectEmpty;
overview.showLoading = !loaded && projectEmpty;
overview.everythingFiltered = !projectEmpty && !overview.filteredSize;
overview.hidePipelineOtherResources = overview.viewBy === 'pipeline' &&
(overview.filterActive || _.isEmpty(overview.pipelineBuildConfigs));
};
// Group a collection of resources by app label. Returns a map where the key
// is the app label value and the value is an array of objects, sorted by
// `metadata.name`.
var groupByApp = function(collection) {
return AppsService.groupByApp(collection, 'metadata.name');
};
var getBestRoute = function(routes) {
var bestRoute = null;
_.each(routes, function(candidate) {
if (!bestRoute) {
bestRoute = candidate;
return;
}
// Is candidate better than the current display route?
bestRoute = RoutesService.getPreferredDisplayRoute(bestRoute, candidate);
});
return bestRoute;
};
// Debounce so we're not reevaluating this too often.
var updateRoutesByApp = _.debounce(function() {
$scope.$evalAsync(function() {
overview.bestRouteByApp = {};
if (!overview.routes) {
return;
}
// Any of the following can have services that have routes.
var toCheck = [
overview.filteredDeploymentConfigsByApp,
overview.filteredReplicationControllersByApp,
overview.filteredDeploymentsByApp,
overview.filteredReplicaSetsByApp,
overview.filteredStatefulSetsByApp,
overview.filteredMonopodsByApp
];
// Find the best route for each app.
_.each(overview.apps, function(app) {
// Create a map of routes, keyed by route name to avoid adding them twice.
var routesForApp = {};
_.each(toCheck, function(byApp) {
var apiObjects = _.get(byApp, app, []);
_.each(apiObjects, function(apiObject) {
var uid = getUID(apiObject);
var services = _.get(state, ['servicesByObjectUID', uid], []);
_.each(services, function(service) {
// Only need to get the first route, since they're already sorted by score.
var routes = _.get(state, ['routesByService', service.metadata.name], []);
_.assign(routesForApp, _.keyBy(routes, 'metadata.name'));
});
});
});
overview.bestRouteByApp[app] = getBestRoute(routesForApp);
});
});
}, 300, { maxWait: 1500 });
// Group each resource kind by app and update the list of app label values.
var updateApps = function() {
overview.filteredDeploymentConfigsByApp = groupByApp(overview.filteredDeploymentConfigs);
overview.filteredReplicationControllersByApp = groupByApp(overview.filteredReplicationControllers);
overview.filteredDeploymentsByApp = groupByApp(overview.filteredDeployments);
overview.filteredReplicaSetsByApp = groupByApp(overview.filteredReplicaSets);
overview.filteredStatefulSetsByApp = groupByApp(overview.filteredStatefulSets);
overview.filteredMonopodsByApp = groupByApp(overview.filteredMonopods);
overview.apps = _.union(_.keys(overview.filteredDeploymentConfigsByApp),
_.keys(overview.filteredReplicationControllersByApp),
_.keys(overview.filteredDeploymentsByApp),
_.keys(overview.filteredReplicaSetsByApp),
_.keys(overview.filteredStatefulSetsByApp),
_.keys(overview.filteredMonopodsByApp));
AppsService.sortAppNames(overview.apps);
updateRoutesByApp();
};
var updatePipelineOtherResources = function() {
// Find deployment configs not associated with a pipeline.
var otherDeploymentConfigs = _.filter(overview.deploymentConfigs, function(deploymentConfig) {
var name = getName(deploymentConfig);
return _.isEmpty(state.pipelinesByDeploymentConfig[name]);
});
overview.deploymentConfigsNoPipeline = _.sortBy(otherDeploymentConfigs, 'metadata.name');
overview.pipelineViewHasOtherResources =
!_.isEmpty(overview.deploymentConfigsNoPipeline) ||
!_.isEmpty(overview.vanillaReplicationControllers) ||
!_.isEmpty(overview.deployments) ||
!_.isEmpty(overview.vanillaReplicaSets) ||
!_.isEmpty(overview.statefulSets) ||
!_.isEmpty(overview.monopods);
};
var updateFilterDisabledState = function() {
overview.disableFilter = overview.viewBy === 'pipeline' && _.isEmpty(overview.pipelineBuildConfigs);
};
var filterByLabel = function(items) {
return LabelFilter.getLabelSelector().select(items);
};
// Updated on viewBy changes to include the app label when appropriate.
var filterFields = ['metadata.name', 'spec.serviceClassName'];
var filterByName = function(items) {
return KeywordService.filterForKeywords(items, filterFields, state.filterKeywords);
};
var filterItems = function(items) {
switch (overview.filterBy) {
case 'label':
return filterByLabel(items);
case 'name':
return filterByName(items);
}
return items;
};
var isFilterActive = function() {
switch (overview.filterBy) {
case 'label':
return !LabelFilter.getLabelSelector().isEmpty();
case 'name':
return !_.isEmpty(state.filterKeywords);
}
};
var updateFilter = function() {
overview.filteredDeploymentConfigs = filterItems(overview.deploymentConfigs);
overview.filteredReplicationControllers = filterItems(overview.vanillaReplicationControllers);
overview.filteredDeployments = filterItems(overview.deployments);
overview.filteredReplicaSets = filterItems(overview.vanillaReplicaSets);
overview.filteredStatefulSets = filterItems(overview.statefulSets);
overview.filteredMonopods = filterItems(overview.monopods);
overview.filteredPipelineBuildConfigs = filterItems(overview.pipelineBuildConfigs);
overview.filteredServiceInstances = filterItems(state.orderedServiceInstances);
overview.filterActive = isFilterActive();
updateApps();
updateShowGetStarted();
};
// Track view-by state in localStorage.
var viewByKey = $routeParams.project + '/overview/view-by';
overview.viewBy = localStorage.getItem(viewByKey) || 'app';
$scope.$watch(function() {
return overview.viewBy;
},function(value){
localStorage.setItem(viewByKey, value);
updateFilterDisabledState();
filterFields = overview.viewBy === 'app' ? ['metadata.name', 'metadata.labels.app'] : ['metadata.name'];
updateFilter();
if (overview.viewBy === 'pipeline') {
LabelFilter.setLabelSuggestions(pipelineLabelSuggestions);
} else {
LabelFilter.setLabelSuggestions(labelSuggestions);
}
});
if (!Constants.DISABLE_OVERVIEW_METRICS) {
// Check if a metrics URL has been configured for overview metrics.
MetricsService.isAvailable(true).then(function(available) {
state.showMetrics = available;
});
// Show a page-level alert when we fail to connect to Hawkular metrics.
$scope.$on('metrics-connection-failed', function(e, data) {
var hidden = AlertMessageService.isAlertPermanentlyHidden('metrics-connection-failed');
if (hidden || state.alerts['metrics-connection-failed']) {
return;
}
state.alerts['metrics-connection-failed'] = {
type: 'warning',
message: 'An error occurred getting metrics.',
links: [{
href: data.url,
label: 'Open Metrics URL',
target: '_blank'
}, {
href: '',
label: "Don't Show Me Again",
onClick: function() {
// Hide the alert on future page loads.
AlertMessageService.permanentlyHideAlert('metrics-connection-failed');
// Return true close the existing alert.
return true;
}
}]
};
});
}
var isPod = function(apiObject) {
return apiObject && apiObject.kind === 'Pod';
};
var getPods = function(apiObject) {
var uid = getUID(apiObject);
if (!uid) {
return [];
}
if (isPod(apiObject)) {
return [apiObject];
}
return _.get(overview, ['state', 'podsByOwnerUID', uid], []);
};
var setNotifications = function(apiObject, notifications) {
var uid = getUID(apiObject);
state.notificationsByObjectUID[uid] = notifications || {};
};
var getNotifications = function(apiObject) {
var uid = getUID(apiObject);
if (!uid) {
return {};
}
return _.get(state, ['notificationsByObjectUID', uid], {});
};
// Set pod warnings for pods owned by `apiObject`, which can be a set like
// a replication controller or replica set, or just a pod itself.
//
// Updates `state.notificationsByObjectUID`
// key: object UID
// value: alerts object
var updatePodWarningsForObject = function(apiObject) {
var uid = getUID(apiObject);
if (!uid) {
return;
}
var pods = getPods(apiObject);
var notifications = ResourceAlertsService.getPodAlerts(pods, $routeParams.project);
setNotifications(apiObject, notifications);
};
// Updates pod warnings for a collection of API objects such as replication
// controllers or monopods.
var updatePodWarnings = function(apiObjects) {
_.each(apiObjects, updatePodWarningsForObject);
};
// Get the most recently-created replication controller for a deployment
// config. This might not be the active deployment if it was a failed or
// cancelled.
var getMostRecentReplicationController = function(deploymentConfig) {
var name = getName(deploymentConfig);
if (!name) {
return null;
}
return mostRecentByDeploymentConfig[name];
};
// Get the replication controllers that are displayed for a deployment
// config. This will return only the active replication controller unless a
// deployment is in progress.
var getVisibleReplicationControllers = function(deploymentConfig) {
var name = getName(deploymentConfig);
if (!name) {
return [];
}
return _.get(overview, ['replicationControllersByDeploymentConfig', name]);
};
// Get the "previous" replication controller (when a deployment is in
// progress and more than one is active). This is the donut that appears on
// the left when we show two. Returns null if there is no deployment in
// progress or the previous has been scaled down.
overview.getPreviousReplicationController = function(deploymentConfig) {
var replicationControllers = getVisibleReplicationControllers(deploymentConfig);
if (_.size(replicationControllers) < 2) {
return null;
}
// The array is sorted by age, most recent first. Return the second item.
return replicationControllers[1];
};
// Set warnings for a deployment config, including warnings for any active
// replication controllers and cancelled and failed deployments.
//
// Updates `state.notificationsByObjectUID`
// key: object UID
// value: alerts object
var updateDeploymentConfigWarnings = function(deploymentConfig) {
var notifications = {};
// Add any failed / canceled deployment notifications.
var mostRecent = getMostRecentReplicationController(deploymentConfig);
_.assign(
notifications,
ResourceAlertsService.getDeploymentStatusAlerts(deploymentConfig, mostRecent),
ResourceAlertsService.getPausedDeploymentAlerts(deploymentConfig)
);
// Roll up notifications like pod warnings for any visible replication controller.
var visibleReplicationControllers = getVisibleReplicationControllers(deploymentConfig);
_.each(visibleReplicationControllers, function(replicationController) {
var rcNotifications = getNotifications(replicationController);
_.assign(notifications, rcNotifications);
});
setNotifications(deploymentConfig, notifications);
};
// Update warnings for all deployment configs.
var updateAllDeploymentConfigWarnings = function() {
_.each(overview.deploymentConfigs, updateDeploymentConfigWarnings);
};
// Get the replica sets that are displayed for a deployment. This will return
// only the active replica set unless a deployment is in progress.
var getVisibleReplicaSets = function(deployment) {
var uid = getUID(deployment);
if (!uid) {
return {};
}
return _.get(overview, ['replicaSetsByDeploymentUID', uid]);
};
// Set warnings for a Kubernetes deployment, including any active replica sets.
//
// Updates `state.notificationsByObjectUID`
// key: object UID
// value: alerts object
var updateDeploymentWarnings = function(deployment) {
var notifications = ResourceAlertsService.getPausedDeploymentAlerts(deployment);
// Roll up notifications like pod warnings for any visible replica set.
var visibleReplicaSets = getVisibleReplicaSets(deployment);
_.each(visibleReplicaSets, function(replicaSet) {
var replicaSetNotifications = getNotifications(replicaSet);
_.assign(notifications, replicaSetNotifications);
});
setNotifications(deployment, notifications);
};
// Update warnings for all Kubernetes deployments.
var updateAllDeploymentWarnings = function() {
_.each(overview.deployments, updateDeploymentWarnings);
};
// Update all pod warnings, indexing the errors by owner UID.
var updateAllPodWarnings = function() {
updatePodWarnings(overview.replicationControllers);
updatePodWarnings(overview.replicaSets);
updatePodWarnings(overview.statefulSets);
updatePodWarnings(overview.monopods);
};
// Update warnings for all kinds. Debounce so we're not reevaluating this too often.
var updateWarnings = _.debounce(function() {
$scope.$evalAsync(function() {
updateAllPodWarnings();
updateAllDeploymentConfigWarnings();
updateAllDeploymentWarnings();
});
}, 500);
// Update the label filter suggestions for a list of objects. This should
// only be called for filterable top-level items to avoid polluting the list.
var updateLabelSuggestions = function(objects) {
if (_.isEmpty(objects)) {
return;
}
LabelFilter.addLabelSuggestionsFromResources(objects, labelSuggestions);
if (overview.viewBy !== 'pipeline') {
LabelFilter.setLabelSuggestions(labelSuggestions);
}
};
// Update the label suggestions used when viewBy === 'pipeline'.
var updatePipelineLabelSuggestions = function(pipelineBuildConfigs) {
if (_.isEmpty(pipelineBuildConfigs)) {
return;
}
LabelFilter.addLabelSuggestionsFromResources(pipelineBuildConfigs, pipelineLabelSuggestions);
if (overview.viewBy === 'pipeline') {
LabelFilter.setLabelSuggestions(pipelineLabelSuggestions);
}
};
// Filter out monopods we know we don't want to see.
var showMonopod = function(pod) {
// Hide pods in the succeeded and failed phases since these are run once
// pods that are done.
if (pod.status.phase === 'Succeeded' ||
pod.status.phase === 'Failed') {
// TODO: We may want to show pods for X amount of time after they have completed.
return false;
}
// Hide our deployer pods since it is obvious the deployment is happening
// when the new deployment appears.
if (label(pod, "openshift.io/deployer-pod-for.name")) {
return false;
}
// Hide our build pods since we are already showing details for currently
// running or recently run builds under the appropriate areas.
if (annotation(pod, "openshift.io/build.name")) {
return false;
}
// Hide Jenkins slave pods.
if (label(pod, "jenkins") === "slave") {
return false;
}
return true;
};
// Group all pods by owner, tracked in the `state.podsByOwnerUID` map.
var groupPods = function() {
state.podsByOwnerUID = PodsService.groupByOwnerUID(overview.pods);
overview.monopods = _.filter(state.podsByOwnerUID[''], showMonopod);
};
// Determine if a replication controller is visible, either as part of a
// deployment config or a standalone replication controller.
var isReplicationControllerVisible = function(replicationController) {
if (_.get(replicationController, 'status.replicas')) {
return true;
}
var dcName = annotation(replicationController, 'deploymentConfig');
if (!dcName) {
return true;
}
return deploymentIsInProgress(replicationController);
};
// Get the deployment config name for a replication controller by reading the
// "openshift.io/deployment-config.name" annotation.
var getDeploymentConfigName = function(replicationController) {
return annotation(replicationController, 'deploymentConfig');
};
// Group replication controllers by deployment config and filter the visible
// replication controllers.
var groupReplicationControllers = function() {
if (!overview.deploymentConfigs || !overview.replicationControllers) {
return;
}
// "Vanilla" replication controllers are those not owned by a deployment config.
var vanillaReplicationControllers = [];
overview.replicationControllersByDeploymentConfig = {};
overview.currentByDeploymentConfig = {};
mostRecentByDeploymentConfig = {};
// The "active" replication controller by deployment config name. This is the
// most recent successful deployment.
var activeByDeploymentConfig = {};
// Add the replication controllers to a temporary map until we have them all and can sort.
var rcByDC = {};
_.each(overview.replicationControllers, function(replicationController) {
var dcName = getDeploymentConfigName(replicationController) || '';
if (!dcName || (!overview.deploymentConfigs[dcName] && _.get(replicationController, 'status.replicas'))) {
vanillaReplicationControllers.push(replicationController);
}
// Keep track of the most recent replication controller even if not
// visible to show failed/canceled deployment notifications.
var mostRecent = mostRecentByDeploymentConfig[dcName];
if (!mostRecent || isNewerResource(replicationController, mostRecent)) {
mostRecentByDeploymentConfig[dcName] = replicationController;
}
// Also find the most recent successful deployment. We always show that,
// even if scaled down. This is not always "latest" since a more recent
// deployment might have failed or been cancelled.
var active;
if (annotation(replicationController, 'deploymentStatus') === 'Complete') {
active = activeByDeploymentConfig[dcName];
if (!active || isNewerResource(replicationController, active)) {
activeByDeploymentConfig[dcName] = replicationController;
}
}
// Only track the visible replication controllers. This way we only sort
// and check warnings for things we're showing.
if (isReplicationControllerVisible(replicationController)) {
_.set(rcByDC, [dcName, replicationController.metadata.name], replicationController);
}
});
// Make sure the active replication controllers are in `rcByDC` map. This
// isn't checked by `isReplicationControllerVisible` since that function is
// called before the loop completes and active is known.
_.each(activeByDeploymentConfig, function(replicationController, dcName) {
_.set(rcByDC, [dcName, replicationController.metadata.name], replicationController);
});
// Sort the visible replication controllers.
_.each(rcByDC, function(replicationControllers, dcName) {
var ordered = DeploymentsService.sortByDeploymentVersion(replicationControllers, true);
overview.replicationControllersByDeploymentConfig[dcName] = ordered;
// "Current" is considered the most recent visible replication
// controller, even if the deployment hasn't completed.
overview.currentByDeploymentConfig[dcName] = _.head(ordered);
});
overview.vanillaReplicationControllers = _.sortBy(vanillaReplicationControllers, 'metadata.name');
// Since the visible replication controllers for each deployment config
// have changed, update the deployment config warnings.
updateAllDeploymentConfigWarnings();
};
// Determine if a replica set is visible, either as part of a deployment or
// as a standalone replica set.
var isReplicaSetVisible = function(replicaSet, deployment) {
// If the replica set has pods, show it.
if (_.get(replicaSet, 'status.replicas')) {
return true;
}
var revision = DeploymentsService.getRevision(replicaSet);
// If not part of a deployment, always show the replica set.
if (!revision) {
return true;
}
// If the deployment has been deleted and the replica set has no replicas, hide it.
// Otherwise all old replica sets for a deleted deployment will be visible.
if (!deployment) {
return false;
}
// Show the replica set if it's the latest revision.
return DeploymentsService.getRevision(deployment) === revision;
};
// Group replica sets by deployment and filter the visible replica sets.
var groupReplicaSets = function() {
if (!overview.replicaSets || !deploymentsByUID) {
return;
}
overview.replicaSetsByDeploymentUID = OwnerReferencesService.groupByControllerUID(overview.replicaSets);
overview.currentByDeploymentUID = {};
// Sort the visible replica sets.
_.each(overview.replicaSetsByDeploymentUID, function(replicaSets, deploymentUID) {
if (!deploymentUID) {
return;
}
var deployment = deploymentsByUID[deploymentUID];
var visibleReplicaSets = _.filter(replicaSets, function(replicaSet) {
return isReplicaSetVisible(replicaSet, deployment);
});
var ordered = DeploymentsService.sortByRevision(visibleReplicaSets);
overview.replicaSetsByDeploymentUID[deploymentUID] = ordered;
overview.currentByDeploymentUID[deploymentUID] = _.head(ordered);
});
overview.vanillaReplicaSets = _.sortBy(overview.replicaSetsByDeploymentUID[''], 'metadata.name');
// Since the visible replica sets for each deployment have changed, update
// the deployment warnings.
updateAllDeploymentWarnings();
};
// Find the services that direct traffic to each API object.
//
// Updates `state.servicesByObjectUID`
// key: object UID
// value: array of sorted services
var selectorsByService = {};
var updateServicesForObjects = function(apiObjects) {
if (!apiObjects || !state.allServices) {
return;
}
_.each(apiObjects, function(apiObject) {
var services = [];
var uid = getUID(apiObject);
var podTemplate = getPodTemplate(apiObject);
_.each(selectorsByService, function(selector, serviceName) {
if (selector.matches(podTemplate)) {
services.push(state.allServices[serviceName]);
}
});
state.servicesByObjectUID[uid] = _.sortBy(services, 'metadata.name');
});
};
// Update the list of services for all API objects.
//
// Updates `state.servicesByObjectUID`
// key: object UID
// value: array of sorted services
var groupServices = function() {
if (!state.allServices) {
return;
}
selectorsByService = _.mapValues(state.allServices, function(service) {
return new LabelSelector(service.spec.selector);
});
var toUpdate = [
overview.deploymentConfigs,
overview.vanillaReplicationControllers,
overview.deployments,
overview.vanillaReplicaSets,
overview.statefulSets,
overview.monopods
];
_.each(toUpdate, updateServicesForObjects);
updateRoutesByApp();
};
// Group routes by the services they route to (either as a primary service or
// alternate backend).
//
// Updates `state.routesByService`
// key: service name
// value: array of routes, sorted by RoutesService.sortRoutesByScore
var groupRoutes = function() {
var routesByService = RoutesService.groupByService(overview.routes, true);
state.routesByService = _.mapValues(routesByService, RoutesService.sortRoutesByScore);
updateRoutesByApp();
};
// Group HPAs by the object they scale.
//
// Updates `state.hpaByResource`
// key: hpaByResource[kind][name]
// value: array of HPA objects
var groupHPAs = function() {
state.hpaByResource = HPAService.groupHPAs(overview.horizontalPodAutoscalers);
};
// Adds a recent pipeline build to the following maps:
//
// `overview.recentPipelinesByBuildConfig``
// key: build config name
// value: array of pipeline builds
//
// `state.recentPipelinesByDeploymentConfig`
// key: deployment config name
// value: array of pipeline builds
var groupPipeline = function(build) {
var bcName = getBuildConfigName(build);
var buildConfig = overview.buildConfigs[bcName];
if (!buildConfig) {
return;
}
overview.recentPipelinesByBuildConfig[bcName] = overview.recentPipelinesByBuildConfig[bcName] || [];
overview.recentPipelinesByBuildConfig[bcName].push(build);
// Index running pipelines by DC name.
var dcNames = BuildsService.usesDeploymentConfigs(buildConfig);
_.each(dcNames, function(dcName) {
state.recentPipelinesByDeploymentConfig[dcName] = state.recentPipelinesByDeploymentConfig[dcName] || [];
state.recentPipelinesByDeploymentConfig[dcName].push(build);
});
updatePipelineOtherResources();
};
// Group build configs by their output image. This lets us match them to
// deployment config image change triggers.
var buildConfigsByOutputImage = {};
var groupBuildConfigsByOutputImage = function() {
buildConfigsByOutputImage = BuildsService.groupBuildConfigsByOutputImage(overview.buildConfigs);
};
var getBuildConfigsForObject = function(apiObject) {
var uid = getUID(apiObject);
if (!uid) {
return;
}
return _.get(state, ['buildConfigsByObjectUID', uid], []);
};
// Find all recent builds for `deploymentConfig` from each of `buildConfigs`.
//
// Updates `state.recentBuildsByDeploymentConfig`
// key: deployment config name
// value: array of builds, sorted in descending order by creation date
var updateRecentBuildsForDeploymentConfig = function(deploymentConfig) {
var builds = [];
var buildConfigs = getBuildConfigsForObject(deploymentConfig);
_.each(buildConfigs, function(buildConfig) {
var recentForConfig = _.get(state, ['recentBuildsByBuildConfig', buildConfig.metadata.name], []);
builds = builds.concat(recentForConfig);
});
// These builds are only used to show a count, so don't need to be sorted.
var dcName = getName(deploymentConfig);
_.set(state, ['recentBuildsByDeploymentConfig', dcName], builds);
};
var setBuildConfigsForObject = function(buildConfigs, apiObject) {
var uid = getUID(apiObject);
if (!uid) {
return;
}
_.set(state, ['buildConfigsByObjectUID', uid], buildConfigs);
};
// Find build configs that use the pipeline strategy and have a
// "pipeline.alpha.openshift.io/uses" annotation pointing to a deployment
// config.
//
// Updates `state.pipelinesByDeploymentConfig`
// key: deployment config name
// value: array of pipeline build configs
var groupPipelineBuildConfigsByDeploymentConfig = function() {
var pipelineBuildConfigs = [];
overview.deploymentConfigsByPipeline = {};
state.pipelinesByDeploymentConfig = {};
_.each(overview.buildConfigs, function(buildConfig) {
if (!isJenkinsPipelineStrategy(buildConfig)) {
return;
}
pipelineBuildConfigs.push(buildConfig);
// TODO: Handle other types.
// Preserve the order they appear in the annotation.
var dcNames = BuildsService.usesDeploymentConfigs(buildConfig);
var bcName = getName(buildConfig);
_.set(overview, ['deploymentConfigsByPipeline', bcName], dcNames);
_.each(dcNames, function(dcName) {
state.pipelinesByDeploymentConfig[dcName] = state.pipelinesByDeploymentConfig[dcName] || [];
state.pipelinesByDeploymentConfig[dcName].push(buildConfig);
});
});
overview.pipelineBuildConfigs = _.sortBy(pipelineBuildConfigs, 'metadata.name');
updatePipelineOtherResources();
updatePipelineLabelSuggestions(overview.pipelineBuildConfigs);
updateFilterDisabledState();
};
// Find build configs with an output image that matches the deployment config
// image change trigger.
//
// Updates `state.buildConfigsByObjectUID`
// key: deployment config UID
// value: array of build configs, sorted by name
var matchOutputImagesToImageChangeTriggers = function() {
state.buildConfigsByObjectUID = {};
_.each(overview.deploymentConfigs, function(deploymentConfig) {
var buildConfigs = [];
var triggers = _.get(deploymentConfig, 'spec.triggers');
_.each(triggers, function(trigger) {
var from = _.get(trigger, 'imageChangeParams.from');
if (!from) {
return;
}
var ref = imageObjectRef(from, deploymentConfig.metadata.namespace);
var buildConfigsForRef = buildConfigsByOutputImage[ref];
if (!_.isEmpty(buildConfigsForRef)) {
buildConfigs = buildConfigs.concat(buildConfigsForRef);
}
});
buildConfigs = _.sortBy(buildConfigs, 'metadata.name');
setBuildConfigsForObject(buildConfigs, deploymentConfig);
updateRecentBuildsForDeploymentConfig(deploymentConfig);
});
};
// Find the build configs that relate to each deployment config. Pipeline
// build configs are grouped using an annotation. Other build configs are
// grouping using output images matched against a deployment config image
// change trigger.
var groupBuildConfigsByDeploymentConfig = function() {