Skip to content

Commit 4cfded4

Browse files
committed
Label Filter for Kubernetes Deployment History Tab
Implementation of label filter for Kubernetes deployment history tab
1 parent 15c6d1b commit 4cfded4

File tree

4 files changed

+145
-86
lines changed

4 files changed

+145
-86
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: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,48 @@ <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">
96-
<table class="table table-bordered table-hover table-mobile table-layout-fixed">
97-
<colgroup>
98-
<col class="col-sm-2">
99-
<col class="col-sm-4">
100-
<col class="col-sm-3">
101-
<col class="col-sm-3">
102-
</colgroup>
103-
<thead>
104-
<tr>
105-
<th>Version</th>
106-
<th>Name</th>
107-
<th>Replicas</th>
108-
<th>Created</th>
109-
</tr>
110-
</thead>
111-
<tbody>
112-
<tr ng-repeat="replicaSet in replicaSetsForDeployment">
113-
<td data-title="Version">
114-
#{{replicaSet | annotation : 'deployment.kubernetes.io/revision'}}
115-
</td>
116-
<td data-title="Name">
117-
<a ng-href="{{replicaSet | navigateResourceURL}}">{{replicaSet.metadata.name}}</a>
118-
</td>
119-
<td data-title="Replicas">
120-
<span ng-if="replicaSet.status.replicas !== replicaSet.spec.replicas">{{replicaSet.status.replicas}}/</span>{{replicaSet.spec.replicas}} replica<span ng-if="replicaSet.spec.replicas != 1">s</span>
121-
</td>
122-
<td data-title="Created">
123-
<span am-time-ago="replicaSet.metadata.creationTimestamp"></span>
124-
</td>
125-
</tr>
126-
</tbody>
127-
</table>
95+
<div class="table-filter-extension">
96+
<div class="data-toolbar">
97+
<div class="data-toolbar-filter">
98+
<project-filter></project-filter>
99+
</div>
100+
</div>
128101
</div>
102+
<table class="table table-bordered table-hover table-mobile table-layout-fixed">
103+
<colgroup>
104+
<col class="col-sm-2">
105+
<col class="col-sm-4">
106+
<col class="col-sm-3">
107+
<col class="col-sm-3">
108+
</colgroup>
109+
<thead>
110+
<tr>
111+
<th>Version</th>
112+
<th>Name</th>
113+
<th>Replicas</th>
114+
<th>Created</th>
115+
</tr>
116+
</thead>
117+
<tbody ng-if="(replicaSetsForDeployment | size) == 0">
118+
<tr><td colspan="4"><em>{{emptyMessage}}</em></td></tr>
119+
</tbody>
120+
<tbody ng-if="(replicaSetsForDeployment | size) > 0">
121+
<tr ng-repeat="replicaSet in replicaSetsForDeployment">
122+
<td data-title="Version">
123+
#{{replicaSet | annotation : 'deployment.kubernetes.io/revision'}}
124+
</td>
125+
<td data-title="Name">
126+
<a ng-href="{{replicaSet | navigateResourceURL}}">{{replicaSet.metadata.name}}</a>
127+
</td>
128+
<td data-title="Replicas">
129+
<span ng-if="replicaSet.status.replicas !== replicaSet.spec.replicas">{{replicaSet.status.replicas}}/</span>{{replicaSet.spec.replicas}} replica<span ng-if="replicaSet.spec.replicas != 1">s</span>
130+
</td>
131+
<td data-title="Created">
132+
<span am-time-ago="replicaSet.metadata.creationTimestamp"></span>
133+
</td>
134+
</tr>
135+
</tbody>
136+
</table>
129137
</uib-tab>
130138
<uib-tab active="selectedTab.configuration">
131139
<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
@@ -5362,19 +5362,19 @@ a.deploymentConfigs = b.select(a.unfilteredDeploymentConfigs), a.replicationCont
53625362
d.unwatchAll(n);
53635363
});
53645364
}));
5365-
} ]), 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) {
5366-
var o = {};
5367-
a.projectName = c.project, a.name = c.deployment, a.forms = {}, a.alerts = {}, a.imagesByDockerReference = {}, a.breadcrumbs = [ {
5365+
} ]), 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) {
5366+
var p = {};
5367+
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 = [ {
53685368
title:"Deployments",
53695369
link:"project/" + c.project + "/browse/deployments"
53705370
}, {
53715371
title:c.deployment
5372-
} ], a.healthCheckURL = j.healthCheckURL(c.project, "Deployment", c.deployment, "extensions");
5373-
var p = !1, q = function(b, c) {
5374-
if (!p) {
5372+
} ], a.healthCheckURL = l.healthCheckURL(c.project, "Deployment", c.deployment, "extensions");
5373+
var q = !1, r = function(b, c) {
5374+
if (!q) {
53755375
if (!a.forms.deploymentEnvVars || a.forms.deploymentEnvVars.$pristine) return void (a.updatedDeployment = f.copyAndNormalize(b));
53765376
if (f.isEnvironmentEqual(b, c)) return void (a.updatedDeployment = f.mergeEdits(a.updatedDeployment, b));
5377-
p = !0, a.alerts["env-conflict"] = {
5377+
q = !0, a.alerts["env-conflict"] = {
53785378
type:"warning",
53795379
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.",
53805380
links:[ {
@@ -5385,31 +5385,37 @@ return a.clearEnvVarUpdates(), !0;
53855385
} ]
53865386
};
53875387
}
5388-
}, r = b("orderByDisplayName"), s = b("getErrorDetails"), t = function(b, c) {
5388+
}, s = b("orderByDisplayName"), t = b("getErrorDetails"), u = function(b, c) {
53895389
a.alerts["from-value-objects"] = {
53905390
type:"error",
53915391
message:b,
53925392
details:c
53935393
};
5394-
}, u = [];
5395-
m.get(c.project).then(_.spread(function(j, m) {
5396-
a.project = j, a.projectContext = m;
5397-
var v, w = {}, x = function() {
5398-
g.getHPAWarnings(a.deployment, a.autoscalers, w, j).then(function(b) {
5394+
}, v = [];
5395+
n.get(c.project).then(_.spread(function(l, n) {
5396+
function w() {
5397+
i.getLabelSelector().isEmpty() || !_.isEmpty(a.replicaSetsForDeployment) || _.isEmpty(a.unfilteredReplicaSetsForDeployment) ? delete a.alerts["filter-hiding-all"] :a.alerts["filter-hiding-all"] = {
5398+
type:"warning",
5399+
details:"The active filters are hiding all rollout history."
5400+
};
5401+
}
5402+
a.project = l, a.projectContext = n;
5403+
var x, y = {}, z = function() {
5404+
g.getHPAWarnings(a.deployment, a.autoscalers, y, l).then(function(b) {
53995405
a.hpaWarnings = b;
54005406
});
54015407
};
54025408
d.get({
54035409
group:"extensions",
54045410
resource:"deployments"
5405-
}, c.deployment, m, {
5411+
}, c.deployment, n, {
54065412
errorNotification:!1
54075413
}).then(function(g) {
5408-
a.loaded = !0, a.deployment = g, x(), a.saveEnvVars = function() {
5409-
f.compact(a.updatedDeployment), v = d.update({
5414+
a.loaded = !0, a.deployment = g, z(), a.saveEnvVars = function() {
5415+
f.compact(a.updatedDeployment), x = d.update({
54105416
group:"extensions",
54115417
resource:"deployments"
5412-
}, c.deployment, a.updatedDeployment, m), v.then(function() {
5418+
}, c.deployment, a.updatedDeployment, n), x.then(function() {
54135419
a.alerts.saveEnvSuccess = {
54145420
type:"success",
54155421
message:c.deployment + " was updated."
@@ -5421,63 +5427,68 @@ message:c.deployment + " was not updated.",
54215427
details:b("getErrorDetails")(d)
54225428
};
54235429
})["finally"](function() {
5424-
v = null;
5430+
x = null;
54255431
});
54265432
}, a.clearEnvVarUpdates = function() {
5427-
a.updatedDeployment = f.copyAndNormalize(a.deployment), a.forms.deploymentEnvVars.$setPristine(), p = !1;
5428-
}, u.push(d.watchObject({
5433+
a.updatedDeployment = f.copyAndNormalize(a.deployment), a.forms.deploymentEnvVars.$setPristine(), q = !1;
5434+
}, v.push(d.watchObject({
54295435
group:"extensions",
54305436
resource:"deployments"
5431-
}, c.deployment, m, function(b, c) {
5437+
}, c.deployment, n, function(b, c) {
54325438
"DELETED" === c && (a.alerts.deleted = {
54335439
type:"warning",
54345440
message:"This deployment has been deleted."
54355441
});
54365442
var d = a.deployment;
5437-
a.deployment = b, a.updatingPausedState = !1, x(), q(b, d), v ? v["finally"](function() {
5438-
q(b, d);
5439-
}) :q(b, d), h.fetchReferencedImageStreamImages([ b.spec.template ], a.imagesByDockerReference, o, m);
5440-
})), u.push(d.watch({
5443+
a.deployment = b, a.updatingPausedState = !1, z(), r(b, d), x ? x["finally"](function() {
5444+
r(b, d);
5445+
}) :r(b, d), h.fetchReferencedImageStreamImages([ b.spec.template ], a.imagesByDockerReference, p, n);
5446+
})), v.push(d.watch({
54415447
group:"extensions",
54425448
resource:"replicasets"
5443-
}, m, function(b) {
5449+
}, n, function(b) {
5450+
a.emptyMessage = "No deployments to show";
54445451
var c = b.by("metadata.name");
5445-
c = k.filterForController(c, g), a.inProgressDeployment = _.chain(c).filter("status.replicas").size() > 1, a.replicaSetsForDeployment = e.sortByRevision(c);
5452+
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);
54465453
}));
54475454
}, function(c) {
54485455
a.loaded = !0, a.alerts.load = {
54495456
type:"error",
54505457
message:404 === c.status ? "This deployment can not be found, it may have been deleted." :"The deployment details could not be loaded.",
54515458
details:b("getErrorDetails")(c)
54525459
};
5453-
}), d.list("limitranges", m).then(function(a) {
5454-
w = a.by("metadata.name"), x();
5460+
}), d.list("limitranges", n).then(function(a) {
5461+
y = a.by("metadata.name"), z();
54555462
});
5456-
var y = [], z = [];
5457-
a.valueFromObjects = [], d.list("configmaps", m, null, {
5463+
var A = [], B = [];
5464+
a.valueFromObjects = [], d.list("configmaps", n, null, {
54585465
errorNotification:!1
54595466
}).then(function(b) {
5460-
y = r(b.by("metadata.name")), a.valueFromObjects = y.concat(z);
5467+
A = s(b.by("metadata.name")), a.valueFromObjects = A.concat(B);
54615468
}, function(a) {
5462-
403 !== a.code && t("Could not load config maps", s(a));
5463-
}), d.list("secrets", m, null, {
5469+
403 !== a.code && u("Could not load config maps", t(a));
5470+
}), d.list("secrets", n, null, {
54645471
errorNotification:!1
54655472
}).then(function(b) {
5466-
z = r(b.by("metadata.name")), a.valueFromObjects = z.concat(y);
5473+
B = s(b.by("metadata.name")), a.valueFromObjects = B.concat(A);
54675474
}, function(a) {
5468-
403 !== a.code && t("Could not load secrets", s(a));
5469-
}), u.push(d.watch("imagestreams", m, function(b) {
5475+
403 !== a.code && u("Could not load secrets", t(a));
5476+
}), v.push(d.watch("imagestreams", n, function(b) {
54705477
var c = b.by("metadata.name");
5471-
h.buildDockerRefMapForImageStreams(c, o), a.deployment && h.fetchReferencedImageStreamImages([ a.deployment.spec.template ], a.imagesByDockerReference, o, m), l.log("imagestreams (subscribe)", a.imageStreams);
5472-
})), u.push(d.watch({
5478+
h.buildDockerRefMapForImageStreams(c, p), a.deployment && h.fetchReferencedImageStreamImages([ a.deployment.spec.template ], a.imagesByDockerReference, p, n), j.log("imagestreams (subscribe)", a.imageStreams);
5479+
})), v.push(d.watch({
54735480
group:"autoscaling",
54745481
resource:"horizontalpodautoscalers",
54755482
version:"v1"
5476-
}, m, function(b) {
5477-
a.autoscalers = g.filterHPA(b.by("metadata.name"), "Deployment", c.deployment), x();
5478-
})), u.push(d.watch("builds", m, function(b) {
5479-
a.builds = b.by("metadata.name"), l.log("builds (subscribe)", a.builds);
5480-
})), a.scale = function(c) {
5483+
}, n, function(b) {
5484+
a.autoscalers = g.filterHPA(b.by("metadata.name"), "Deployment", c.deployment), z();
5485+
})), v.push(d.watch("builds", n, function(b) {
5486+
a.builds = b.by("metadata.name"), j.log("builds (subscribe)", a.builds);
5487+
})), i.onActiveFiltersChanged(function(b) {
5488+
a.$evalAsync(function() {
5489+
a.replicaSetsForDeployment = b.select(a.unfilteredReplicaSetsForDeployment), w();
5490+
});
5491+
}), a.scale = function(c) {
54815492
var d = function(c) {
54825493
a.alerts = a.alerts || {}, a.alerts.scale = {
54835494
type:"error",
@@ -5487,7 +5498,7 @@ details:b("getErrorDetails")(c)
54875498
};
54885499
e.scale(a.deployment, c).then(_.noop, d);
54895500
}, a.setPaused = function(c) {
5490-
a.updatingPausedState = !0, e.setPaused(a.deployment, c, m).then(_.noop, function(d) {
5501+
a.updatingPausedState = !0, e.setPaused(a.deployment, c, n).then(_.noop, function(d) {
54915502
a.updatingPausedState = !1, a.alerts = a.alerts || {}, a.alerts.scale = {
54925503
type:"error",
54935504
message:"An error occurred " + (c ? "pausing" :"resuming") + " the deployment.",
@@ -5497,18 +5508,18 @@ details:b("getErrorDetails")(d)
54975508
}, a.removeVolume = function(b) {
54985509
var c;
54995510
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.");
5500-
var d = i.confirm({
5511+
var d = k.confirm({
55015512
message:"Remove volume " + b.name + "?",
55025513
details:c,
55035514
okButtonText:"Remove",
55045515
okButtonClass:"btn-danger",
55055516
cancelButtonText:"Cancel"
55065517
}), e = function() {
5507-
n.removeVolume(a.deployment, b, m);
5518+
o.removeVolume(a.deployment, b, n);
55085519
};
55095520
d.then(e);
55105521
}, a.$on("$destroy", function() {
5511-
d.unwatchAll(u);
5522+
d.unwatchAll(v);
55125523
});
55135524
}));
55145525
} ]), 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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,13 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
27192719
"<uib-tabset>\n" +
27202720
"<uib-tab active=\"selectedTab.history\">\n" +
27212721
"<uib-tab-heading>History</uib-tab-heading>\n" +
2722-
"<div ng-if=\"replicaSetsForDeployment | hashSize\">\n" +
2722+
"<div class=\"table-filter-extension\">\n" +
2723+
"<div class=\"data-toolbar\">\n" +
2724+
"<div class=\"data-toolbar-filter\">\n" +
2725+
"<project-filter></project-filter>\n" +
2726+
"</div>\n" +
2727+
"</div>\n" +
2728+
"</div>\n" +
27232729
"<table class=\"table table-bordered table-hover table-mobile table-layout-fixed\">\n" +
27242730
"<colgroup>\n" +
27252731
"<col class=\"col-sm-2\">\n" +
@@ -2735,7 +2741,10 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
27352741
"<th>Created</th>\n" +
27362742
"</tr>\n" +
27372743
"</thead>\n" +
2738-
"<tbody>\n" +
2744+
"<tbody ng-if=\"(replicaSetsForDeployment | size) == 0\">\n" +
2745+
"<tr><td colspan=\"4\"><em>{{emptyMessage}}</em></td></tr>\n" +
2746+
"</tbody>\n" +
2747+
"<tbody ng-if=\"(replicaSetsForDeployment | size) > 0\">\n" +
27392748
"<tr ng-repeat=\"replicaSet in replicaSetsForDeployment\">\n" +
27402749
"<td data-title=\"Version\">\n" +
27412750
"#{{replicaSet | annotation : 'deployment.kubernetes.io/revision'}}\n" +
@@ -2752,7 +2761,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
27522761
"</tr>\n" +
27532762
"</tbody>\n" +
27542763
"</table>\n" +
2755-
"</div>\n" +
27562764
"</uib-tab>\n" +
27572765
"<uib-tab active=\"selectedTab.configuration\">\n" +
27582766
"<uib-tab-heading>Configuration</uib-tab-heading>\n" +

0 commit comments

Comments
 (0)