Skip to content

Commit 7510a3f

Browse files
committed
Label Filter for Kubernetes Deployment History Tab
Implementation of label filter for Kubernetes deployment history tab
1 parent adf6034 commit 7510a3f

File tree

4 files changed

+107
-56
lines changed

4 files changed

+107
-56
lines changed

app/scripts/controllers/deployment.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ angular.module('openshiftConsole')
1616
EnvironmentService,
1717
HPAService,
1818
ImageStreamResolver,
19+
LabelFilter,
20+
Logger,
1921
ModalsService,
2022
Navigate,
2123
OwnerReferencesService,
22-
Logger,
2324
ProjectsService,
2425
StorageService) {
2526
var imageStreamImageRefByDockerReference = {}; // lets us determine if a particular container's docker image reference belongs to an imageStream
2627

2728
$scope.projectName = $routeParams.project;
2829
$scope.name = $routeParams.deployment;
30+
$scope.replicaSetsForDeployment = {};
31+
$scope.unfilteredReplicaSetsForDeployment = {};
32+
$scope.labelSuggestions = {};
33+
$scope.emptyMessage = "Loading...";
2934
$scope.forms = {};
3035
$scope.alerts = {};
3136
$scope.imagesByDockerReference = {};
@@ -185,10 +190,18 @@ angular.module('openshiftConsole')
185190
group: 'extensions',
186191
resource: 'replicasets'
187192
}, context, function(replicaSetData) {
193+
$scope.emptyMessage = "No deployments to show";
194+
188195
var replicaSets = replicaSetData.by('metadata.name');
189196
replicaSets = OwnerReferencesService.filterForController(replicaSets, deployment);
190197
$scope.inProgressDeployment = _.chain(replicaSets).filter('status.replicas').size() > 1;
191-
$scope.replicaSetsForDeployment = DeploymentsService.sortByRevision(replicaSets);
198+
199+
$scope.unfilteredReplicaSetsForDeployment = DeploymentsService.sortByRevision(replicaSets);
200+
$scope.replicaSetsForDeployment = LabelFilter.getLabelSelector().select($scope.unfilteredReplicaSetsForDeployment);
201+
202+
updateFilterWarning();
203+
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredReplicaSetsForDeployment, $scope.labelSuggestions);
204+
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
192205
}));
193206
},
194207
// failure
@@ -260,6 +273,25 @@ angular.module('openshiftConsole')
260273
Logger.log("builds (subscribe)", $scope.builds);
261274
}));
262275

276+
function updateFilterWarning() {
277+
if (!LabelFilter.getLabelSelector().isEmpty() && _.isEmpty($scope.replicaSetsForDeployment) && !_.isEmpty($scope.unfilteredReplicaSetsForDeployment)) {
278+
$scope.alerts["filter-hiding-all"] = {
279+
type: "warning",
280+
details: "The active filters are hiding all rollout history."
281+
};
282+
}
283+
else {
284+
delete $scope.alerts["filter-hiding-all"];
285+
}
286+
}
287+
288+
LabelFilter.onActiveFiltersChanged(function(labelSelector) {
289+
$scope.$evalAsync(function() {
290+
$scope.replicaSetsForDeployment = labelSelector.select($scope.unfilteredReplicaSetsForDeployment);
291+
updateFilterWarning();
292+
});
293+
});
294+
263295
$scope.scale = function(replicas) {
264296
var showScalingError = function(result) {
265297
$scope.alerts = $scope.alerts || {};

app/views/browse/deployment.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ <h1 class="contains-actions">
9292
<uib-tabset>
9393
<uib-tab active="selectedTab.history">
9494
<uib-tab-heading>History</uib-tab-heading>
95-
<div ng-if="replicaSetsForDeployment | hashSize">
95+
<div class="table-filter-wrapper">
96+
<project-filter></project-filter>
97+
</div>
9698
<table class="table table-bordered table-hover table-mobile table-layout-fixed">
9799
<colgroup>
98100
<col class="col-sm-2">
@@ -108,7 +110,10 @@ <h1 class="contains-actions">
108110
<th>Created</th>
109111
</tr>
110112
</thead>
111-
<tbody>
113+
<tbody ng-if="(replicaSetsForDeployment | size) == 0">
114+
<tr><td colspan="4"><em>{{emptyMessage}}</em></td></tr>
115+
</tbody>
116+
<tbody ng-if="(replicaSetsForDeployment | size) > 0">
112117
<tr ng-repeat="replicaSet in replicaSetsForDeployment">
113118
<td data-title="Version">
114119
#{{replicaSet | annotation : 'deployment.kubernetes.io/revision'}}
@@ -125,7 +130,6 @@ <h1 class="contains-actions">
125130
</tr>
126131
</tbody>
127132
</table>
128-
</div>
129133
</uib-tab>
130134
<uib-tab active="selectedTab.configuration">
131135
<uib-tab-heading>Configuration</uib-tab-heading>

dist/scripts/scripts.js

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5361,19 +5361,19 @@ a.deploymentConfigs = b.select(a.unfilteredDeploymentConfigs), a.replicationCont
53615361
d.unwatchAll(n);
53625362
});
53635363
}));
5364-
} ]), angular.module("openshiftConsole").controller("DeploymentController", [ "$scope", "$filter", "$routeParams", "DataService", "DeploymentsService", "EnvironmentService", "HPAService", "ImageStreamResolver", "ModalsService", "Navigate", "OwnerReferencesService", "Logger", "ProjectsService", "StorageService", function(a, b, c, d, e, f, g, h, i, j, k, l, m, n) {
5365-
var o = {};
5366-
a.projectName = c.project, a.name = c.deployment, a.forms = {}, a.alerts = {}, a.imagesByDockerReference = {}, a.breadcrumbs = [ {
5364+
} ]), angular.module("openshiftConsole").controller("DeploymentController", [ "$scope", "$filter", "$routeParams", "DataService", "DeploymentsService", "EnvironmentService", "HPAService", "ImageStreamResolver", "LabelFilter", "Logger", "ModalsService", "Navigate", "OwnerReferencesService", "ProjectsService", "StorageService", function(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) {
5365+
var p = {};
5366+
a.projectName = c.project, a.name = c.deployment, a.replicaSetsForDeployment = {}, a.unfilteredReplicaSetsForDeployment = {}, a.labelSuggestions = {}, a.emptyMessage = "Loading...", a.forms = {}, a.alerts = {}, a.imagesByDockerReference = {}, a.breadcrumbs = [ {
53675367
title:"Deployments",
53685368
link:"project/" + c.project + "/browse/deployments"
53695369
}, {
53705370
title:c.deployment
5371-
} ], a.healthCheckURL = j.healthCheckURL(c.project, "Deployment", c.deployment, "extensions");
5372-
var p = !1, q = function(b, c) {
5373-
if (!p) {
5371+
} ], a.healthCheckURL = l.healthCheckURL(c.project, "Deployment", c.deployment, "extensions");
5372+
var q = !1, r = function(b, c) {
5373+
if (!q) {
53745374
if (!a.forms.deploymentEnvVars || a.forms.deploymentEnvVars.$pristine) return void (a.updatedDeployment = f.copyAndNormalize(b));
53755375
if (f.isEnvironmentEqual(b, c)) return void (a.updatedDeployment = f.mergeEdits(a.updatedDeployment, b));
5376-
p = !0, a.alerts["env-conflict"] = {
5376+
q = !0, a.alerts["env-conflict"] = {
53775377
type:"warning",
53785378
message:"The environment variables for the deployment have been updated in the background. Saving your changes may create a conflict or cause loss of data.",
53795379
links:[ {
@@ -5384,31 +5384,37 @@ return a.clearEnvVarUpdates(), !0;
53845384
} ]
53855385
};
53865386
}
5387-
}, r = b("orderByDisplayName"), s = b("getErrorDetails"), t = function(b, c) {
5387+
}, s = b("orderByDisplayName"), t = b("getErrorDetails"), u = function(b, c) {
53885388
a.alerts["from-value-objects"] = {
53895389
type:"error",
53905390
message:b,
53915391
details:c
53925392
};
5393-
}, u = [];
5394-
m.get(c.project).then(_.spread(function(j, m) {
5395-
a.project = j, a.projectContext = m;
5396-
var v, w = {}, x = function() {
5397-
g.getHPAWarnings(a.deployment, a.autoscalers, w, j).then(function(b) {
5393+
}, v = [];
5394+
n.get(c.project).then(_.spread(function(l, n) {
5395+
function w() {
5396+
i.getLabelSelector().isEmpty() || !_.isEmpty(a.replicaSetsForDeployment) || _.isEmpty(a.unfilteredReplicaSetsForDeployment) ? delete a.alerts["filter-hiding-all"] :a.alerts["filter-hiding-all"] = {
5397+
type:"warning",
5398+
details:"The active filters are hiding all rollout history."
5399+
};
5400+
}
5401+
a.project = l, a.projectContext = n;
5402+
var x, y = {}, z = function() {
5403+
g.getHPAWarnings(a.deployment, a.autoscalers, y, l).then(function(b) {
53985404
a.hpaWarnings = b;
53995405
});
54005406
};
54015407
d.get({
54025408
group:"extensions",
54035409
resource:"deployments"
5404-
}, c.deployment, m, {
5410+
}, c.deployment, n, {
54055411
errorNotification:!1
54065412
}).then(function(g) {
5407-
a.loaded = !0, a.deployment = g, x(), a.saveEnvVars = function() {
5408-
f.compact(a.updatedDeployment), v = d.update({
5413+
a.loaded = !0, a.deployment = g, z(), a.saveEnvVars = function() {
5414+
f.compact(a.updatedDeployment), x = d.update({
54095415
group:"extensions",
54105416
resource:"deployments"
5411-
}, c.deployment, a.updatedDeployment, m), v.then(function() {
5417+
}, c.deployment, a.updatedDeployment, n), x.then(function() {
54125418
a.alerts.saveEnvSuccess = {
54135419
type:"success",
54145420
message:c.deployment + " was updated."
@@ -5420,63 +5426,68 @@ message:c.deployment + " was not updated.",
54205426
details:b("getErrorDetails")(d)
54215427
};
54225428
})["finally"](function() {
5423-
v = null;
5429+
x = null;
54245430
});
54255431
}, a.clearEnvVarUpdates = function() {
5426-
a.updatedDeployment = f.copyAndNormalize(a.deployment), a.forms.deploymentEnvVars.$setPristine(), p = !1;
5427-
}, u.push(d.watchObject({
5432+
a.updatedDeployment = f.copyAndNormalize(a.deployment), a.forms.deploymentEnvVars.$setPristine(), q = !1;
5433+
}, v.push(d.watchObject({
54285434
group:"extensions",
54295435
resource:"deployments"
5430-
}, c.deployment, m, function(b, c) {
5436+
}, c.deployment, n, function(b, c) {
54315437
"DELETED" === c && (a.alerts.deleted = {
54325438
type:"warning",
54335439
message:"This deployment has been deleted."
54345440
});
54355441
var d = a.deployment;
5436-
a.deployment = b, a.updatingPausedState = !1, x(), q(b, d), v ? v["finally"](function() {
5437-
q(b, d);
5438-
}) :q(b, d), h.fetchReferencedImageStreamImages([ b.spec.template ], a.imagesByDockerReference, o, m);
5439-
})), u.push(d.watch({
5442+
a.deployment = b, a.updatingPausedState = !1, z(), r(b, d), x ? x["finally"](function() {
5443+
r(b, d);
5444+
}) :r(b, d), h.fetchReferencedImageStreamImages([ b.spec.template ], a.imagesByDockerReference, p, n);
5445+
})), v.push(d.watch({
54405446
group:"extensions",
54415447
resource:"replicasets"
5442-
}, m, function(b) {
5448+
}, n, function(b) {
5449+
a.emptyMessage = "No deployments to show";
54435450
var c = b.by("metadata.name");
5444-
c = k.filterForController(c, g), a.inProgressDeployment = _.chain(c).filter("status.replicas").size() > 1, a.replicaSetsForDeployment = e.sortByRevision(c);
5451+
c = m.filterForController(c, g), a.inProgressDeployment = _.chain(c).filter("status.replicas").size() > 1, a.unfilteredReplicaSetsForDeployment = e.sortByRevision(c), a.replicaSetsForDeployment = i.getLabelSelector().select(a.unfilteredReplicaSetsForDeployment), w(), i.addLabelSuggestionsFromResources(a.unfilteredReplicaSetsForDeployment, a.labelSuggestions), i.setLabelSuggestions(a.labelSuggestions);
54455452
}));
54465453
}, function(c) {
54475454
a.loaded = !0, a.alerts.load = {
54485455
type:"error",
54495456
message:404 === c.status ? "This deployment can not be found, it may have been deleted." :"The deployment details could not be loaded.",
54505457
details:b("getErrorDetails")(c)
54515458
};
5452-
}), d.list("limitranges", m).then(function(a) {
5453-
w = a.by("metadata.name"), x();
5459+
}), d.list("limitranges", n).then(function(a) {
5460+
y = a.by("metadata.name"), z();
54545461
});
5455-
var y = [], z = [];
5456-
a.valueFromObjects = [], d.list("configmaps", m, null, {
5462+
var A = [], B = [];
5463+
a.valueFromObjects = [], d.list("configmaps", n, null, {
54575464
errorNotification:!1
54585465
}).then(function(b) {
5459-
y = r(b.by("metadata.name")), a.valueFromObjects = y.concat(z);
5466+
A = s(b.by("metadata.name")), a.valueFromObjects = A.concat(B);
54605467
}, function(a) {
5461-
403 !== a.code && t("Could not load config maps", s(a));
5462-
}), d.list("secrets", m, null, {
5468+
403 !== a.code && u("Could not load config maps", t(a));
5469+
}), d.list("secrets", n, null, {
54635470
errorNotification:!1
54645471
}).then(function(b) {
5465-
z = r(b.by("metadata.name")), a.valueFromObjects = z.concat(y);
5472+
B = s(b.by("metadata.name")), a.valueFromObjects = B.concat(A);
54665473
}, function(a) {
5467-
403 !== a.code && t("Could not load secrets", s(a));
5468-
}), u.push(d.watch("imagestreams", m, function(b) {
5474+
403 !== a.code && u("Could not load secrets", t(a));
5475+
}), v.push(d.watch("imagestreams", n, function(b) {
54695476
var c = b.by("metadata.name");
5470-
h.buildDockerRefMapForImageStreams(c, o), a.deployment && h.fetchReferencedImageStreamImages([ a.deployment.spec.template ], a.imagesByDockerReference, o, m), l.log("imagestreams (subscribe)", a.imageStreams);
5471-
})), u.push(d.watch({
5477+
h.buildDockerRefMapForImageStreams(c, p), a.deployment && h.fetchReferencedImageStreamImages([ a.deployment.spec.template ], a.imagesByDockerReference, p, n), j.log("imagestreams (subscribe)", a.imageStreams);
5478+
})), v.push(d.watch({
54725479
group:"autoscaling",
54735480
resource:"horizontalpodautoscalers",
54745481
version:"v1"
5475-
}, m, function(b) {
5476-
a.autoscalers = g.filterHPA(b.by("metadata.name"), "Deployment", c.deployment), x();
5477-
})), u.push(d.watch("builds", m, function(b) {
5478-
a.builds = b.by("metadata.name"), l.log("builds (subscribe)", a.builds);
5479-
})), a.scale = function(c) {
5482+
}, n, function(b) {
5483+
a.autoscalers = g.filterHPA(b.by("metadata.name"), "Deployment", c.deployment), z();
5484+
})), v.push(d.watch("builds", n, function(b) {
5485+
a.builds = b.by("metadata.name"), j.log("builds (subscribe)", a.builds);
5486+
})), i.onActiveFiltersChanged(function(b) {
5487+
a.$evalAsync(function() {
5488+
a.replicaSetsForDeployment = b.select(a.unfilteredReplicaSetsForDeployment), w();
5489+
});
5490+
}), a.scale = function(c) {
54805491
var d = function(c) {
54815492
a.alerts = a.alerts || {}, a.alerts.scale = {
54825493
type:"error",
@@ -5486,7 +5497,7 @@ details:b("getErrorDetails")(c)
54865497
};
54875498
e.scale(a.deployment, c).then(_.noop, d);
54885499
}, a.setPaused = function(c) {
5489-
a.updatingPausedState = !0, e.setPaused(a.deployment, c, m).then(_.noop, function(d) {
5500+
a.updatingPausedState = !0, e.setPaused(a.deployment, c, n).then(_.noop, function(d) {
54905501
a.updatingPausedState = !1, a.alerts = a.alerts || {}, a.alerts.scale = {
54915502
type:"error",
54925503
message:"An error occurred " + (c ? "pausing" :"resuming") + " the deployment.",
@@ -5496,18 +5507,18 @@ details:b("getErrorDetails")(d)
54965507
}, a.removeVolume = function(b) {
54975508
var c;
54985509
c = _.get(a, "deployment.spec.paused") ? "This will remove the volume from the deployment." :"This will remove the volume from the deployment and start a new rollout.", b.persistentVolumeClaim ? c += " It will not delete the persistent volume claim." :b.secret ? c += " It will not delete the secret." :b.configMap && (c += " It will not delete the config map.");
5499-
var d = i.confirm({
5510+
var d = k.confirm({
55005511
message:"Remove volume " + b.name + "?",
55015512
details:c,
55025513
okButtonText:"Remove",
55035514
okButtonClass:"btn-danger",
55045515
cancelButtonText:"Cancel"
55055516
}), e = function() {
5506-
n.removeVolume(a.deployment, b, m);
5517+
o.removeVolume(a.deployment, b, n);
55075518
};
55085519
d.then(e);
55095520
}, a.$on("$destroy", function() {
5510-
d.unwatchAll(u);
5521+
d.unwatchAll(v);
55115522
});
55125523
}));
55135524
} ]), angular.module("openshiftConsole").controller("DeploymentConfigController", [ "$scope", "$filter", "$routeParams", "BreadcrumbsService", "DataService", "DeploymentsService", "EnvironmentService", "HPAService", "ImageStreamResolver", "ModalsService", "Navigate", "NotificationsService", "Logger", "ProjectsService", "StorageService", "LabelFilter", "labelNameFilter", function(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) {

dist/scripts/templates.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,7 +2711,9 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
27112711
"<uib-tabset>\n" +
27122712
"<uib-tab active=\"selectedTab.history\">\n" +
27132713
"<uib-tab-heading>History</uib-tab-heading>\n" +
2714-
"<div ng-if=\"replicaSetsForDeployment | hashSize\">\n" +
2714+
"<div class=\"table-filter-wrapper\">\n" +
2715+
"<project-filter></project-filter>\n" +
2716+
"</div>\n" +
27152717
"<table class=\"table table-bordered table-hover table-mobile table-layout-fixed\">\n" +
27162718
"<colgroup>\n" +
27172719
"<col class=\"col-sm-2\">\n" +
@@ -2727,7 +2729,10 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
27272729
"<th>Created</th>\n" +
27282730
"</tr>\n" +
27292731
"</thead>\n" +
2730-
"<tbody>\n" +
2732+
"<tbody ng-if=\"(replicaSetsForDeployment | size) == 0\">\n" +
2733+
"<tr><td colspan=\"4\"><em>{{emptyMessage}}</em></td></tr>\n" +
2734+
"</tbody>\n" +
2735+
"<tbody ng-if=\"(replicaSetsForDeployment | size) > 0\">\n" +
27312736
"<tr ng-repeat=\"replicaSet in replicaSetsForDeployment\">\n" +
27322737
"<td data-title=\"Version\">\n" +
27332738
"#{{replicaSet | annotation : 'deployment.kubernetes.io/revision'}}\n" +
@@ -2744,7 +2749,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
27442749
"</tr>\n" +
27452750
"</tbody>\n" +
27462751
"</table>\n" +
2747-
"</div>\n" +
27482752
"</uib-tab>\n" +
27492753
"<uib-tab active=\"selectedTab.configuration\">\n" +
27502754
"<uib-tab-heading>Configuration</uib-tab-heading>\n" +

0 commit comments

Comments
 (0)