forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresourceAlerts.js
194 lines (175 loc) · 6.63 KB
/
resourceAlerts.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
'use strict';
angular.module("openshiftConsole")
.factory("ResourceAlertsService",
function($filter,
AlertMessageService,
DeploymentsService,
Navigate,
NotificationsService,
QuotaService) {
var annotation = $filter('annotation');
var humanizeKind = $filter('humanizeKind');
var deploymentStatus = $filter('deploymentStatus');
var getGroupedPodWarnings = $filter('groupedPodWarnings');
var getPodAlerts = function(pods, namespace) {
if (_.isEmpty(pods)) {
return {};
}
var alerts = {};
var groupedPodWarnings = getGroupedPodWarnings(pods);
_.each(groupedPodWarnings, function(podWarnings, groupID) {
var warning = _.head(podWarnings);
if (!warning) {
return;
}
var alertID = "pod_warning" + groupID;
var alert = {
type: warning.severity || 'warning',
message: warning.message
};
// Handle certain warnings specially.
switch (warning.reason) {
case "Looping":
case "NonZeroExit":
// Add a View Log link for crashing containers.
var podLink = Navigate.resourceURL(warning.pod, "Pod", namespace);
var logLink = URI(podLink).addSearch({ tab: "logs", container: warning.container }).toString();
alert.links = [{
href: logLink,
label: "View Log"
}];
break;
case "NonZeroExitTerminatingPod":
// Allow users to permanently dismiss the non-zero exit code message for terminating pods.
if (AlertMessageService.isAlertPermanentlyHidden(alertID, namespace)) {
return;
}
alert.links = [{
href: "",
label: "Don't Show Me Again",
onClick: function() {
// Hide the alert on future page loads.
AlertMessageService.permanentlyHideAlert(alertID, namespace);
// Return true close the existing alert.
return true;
}
}];
break;
}
alerts[alertID] = alert;
});
return alerts;
};
var setQuotaNotifications = function(quotas, clusterQuotas, projectName) {
var notifications = QuotaService.getQuotaNotifications(quotas, clusterQuotas, projectName);
_.each(notifications, function(notification) {
if(!NotificationsService.isNotificationPermanentlyHidden(notification)) {
NotificationsService.addNotification(notification);
}
});
};
// deploymentConfig, k8s deployment
var getPausedDeploymentAlerts = function(deployment) {
var alerts = {};
if(_.get(deployment, 'spec.paused')) {
alerts[deployment.metadata.uid + '-paused'] = {
type: 'info',
message: deployment.metadata.name + ' is paused.',
details: 'This will stop any new rollouts or triggers from running until resumed.',
links: [{
href: "",
label: 'Resume Rollouts',
onClick: function() {
DeploymentsService.setPaused(deployment, false, {namespace: deployment.metadata.namespace}).then(
_.noop,
function(e) {
alerts[deployment.metadata.uid + '-pause-error'] = {
type: "error",
message: "An error occurred resuming the " + humanizeKind(deployment.kind) + ".",
details: $filter('getErrorDetails')(e)
};
});
return true;
}
}]
};
}
return alerts;
};
var getDeploymentStatusAlerts = function(deploymentConfig, mostRecentRC) {
if (!deploymentConfig || !mostRecentRC) {
return {};
}
var alerts = {};
var dcName = _.get(deploymentConfig, 'metadata.name');
// Show messages about cancelled or failed deployments.
var logLink;
var status = deploymentStatus(mostRecentRC);
var version = annotation(mostRecentRC, 'deploymentVersion');
var displayName = version ? (dcName + ' #' + version) : mostRecentRC.metadata.name;
var rcLink = Navigate.resourceURL(mostRecentRC);
switch (status) {
case 'Cancelled':
alerts[mostRecentRC.metadata.uid + '-cancelled'] = {
type: 'info',
message: 'Deployment ' + displayName + ' was cancelled.',
// TODO: Add back start deployment link from previous overview (see serviceGroupNotifications.js)
links: [{
href: rcLink,
label: 'View Deployment'
}]
};
break;
case 'Failed':
logLink = URI(rcLink).addSearch({ tab: "logs" }).toString();
alerts[mostRecentRC.metadata.uid + '-failed'] = {
type: 'error',
message: 'Deployment ' + displayName + ' failed.',
reason: annotation(mostRecentRC, 'openshift.io/deployment.status-reason'),
links: [{
href: logLink,
label: 'View Log'
}, {
// Show all events since the event might not be on the replication controller itself.
href: 'project/' + mostRecentRC.metadata.namespace + '/browse/events',
label: 'View Events'
}]
};
break;
}
return alerts;
};
var makeConditionAlert = function(alerts, uid, condition, type) {
alerts[uid+'-'+condition.reason] = {
type: type,
message: condition.message
};
};
var getServiceInstanceAlerts = function(instance) {
var alerts = {};
if(!instance) {
return alerts;
}
var uid = instance.metadata.uid;
var namespaceError = _.find(instance.status.conditions, {reason: 'ErrorFindingNamespaceForInstance'});
var provisionFail = _.find(instance.status.conditions, {reason: 'ProvisionFailed'});
var deprovisionFail = _.find(instance.status.conditions, {reason: 'DeprovisioningFailed'});
if(namespaceError) {
makeConditionAlert(alerts, uid, namespaceError, 'warning');
}
if(provisionFail) {
makeConditionAlert(alerts, uid, provisionFail, 'error');
}
if(deprovisionFail) {
makeConditionAlert(alerts, uid, deprovisionFail, 'error');
}
return alerts;
};
return {
getPodAlerts: getPodAlerts,
getDeploymentStatusAlerts: getDeploymentStatusAlerts,
getPausedDeploymentAlerts: getPausedDeploymentAlerts,
getServiceInstanceAlerts: getServiceInstanceAlerts,
setQuotaNotifications: setQuotaNotifications
};
});