Skip to content

Commit 2f3b018

Browse files
committed
Label Filter for Kubernetes Deployment History Tab
Implementation of label filter for Kubernetes deployment history tab
1 parent 23ed4cc commit 2f3b018

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
@@ -5355,19 +5355,19 @@ a.deploymentConfigs = b.select(a.unfilteredDeploymentConfigs), a.replicationCont
53555355
d.unwatchAll(n);
53565356
});
53575357
}));
5358-
} ]), 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) {
5359-
var o = {};
5360-
a.projectName = c.project, a.name = c.deployment, a.forms = {}, a.alerts = {}, a.imagesByDockerReference = {}, a.breadcrumbs = [ {
5358+
} ]), 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) {
5359+
var p = {};
5360+
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 = [ {
53615361
title:"Deployments",
53625362
link:"project/" + c.project + "/browse/deployments"
53635363
}, {
53645364
title:c.deployment
5365-
} ], a.healthCheckURL = j.healthCheckURL(c.project, "Deployment", c.deployment, "extensions");
5366-
var p = !1, q = function(b, c) {
5367-
if (!p) {
5365+
} ], a.healthCheckURL = l.healthCheckURL(c.project, "Deployment", c.deployment, "extensions");
5366+
var q = !1, r = function(b, c) {
5367+
if (!q) {
53685368
if (!a.forms.deploymentEnvVars || a.forms.deploymentEnvVars.$pristine) return void (a.updatedDeployment = f.copyAndNormalize(b));
53695369
if (f.isEnvironmentEqual(b, c)) return void (a.updatedDeployment = f.mergeEdits(a.updatedDeployment, b));
5370-
p = !0, a.alerts["env-conflict"] = {
5370+
q = !0, a.alerts["env-conflict"] = {
53715371
type:"warning",
53725372
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.",
53735373
links:[ {
@@ -5378,31 +5378,37 @@ return a.clearEnvVarUpdates(), !0;
53785378
} ]
53795379
};
53805380
}
5381-
}, r = b("orderByDisplayName"), s = b("getErrorDetails"), t = function(b, c) {
5381+
}, s = b("orderByDisplayName"), t = b("getErrorDetails"), u = function(b, c) {
53825382
a.alerts["from-value-objects"] = {
53835383
type:"error",
53845384
message:b,
53855385
details:c
53865386
};
5387-
}, u = [];
5388-
m.get(c.project).then(_.spread(function(j, m) {
5389-
a.project = j, a.projectContext = m;
5390-
var v, w = {}, x = function() {
5391-
g.getHPAWarnings(a.deployment, a.autoscalers, w, j).then(function(b) {
5387+
}, v = [];
5388+
n.get(c.project).then(_.spread(function(l, n) {
5389+
function w() {
5390+
i.getLabelSelector().isEmpty() || !_.isEmpty(a.replicaSetsForDeployment) || _.isEmpty(a.unfilteredReplicaSetsForDeployment) ? delete a.alerts["filter-hiding-all"] :a.alerts["filter-hiding-all"] = {
5391+
type:"warning",
5392+
details:"The active filters are hiding all rollout history."
5393+
};
5394+
}
5395+
a.project = l, a.projectContext = n;
5396+
var x, y = {}, z = function() {
5397+
g.getHPAWarnings(a.deployment, a.autoscalers, y, l).then(function(b) {
53925398
a.hpaWarnings = b;
53935399
});
53945400
};
53955401
d.get({
53965402
group:"extensions",
53975403
resource:"deployments"
5398-
}, c.deployment, m, {
5404+
}, c.deployment, n, {
53995405
errorNotification:!1
54005406
}).then(function(g) {
5401-
a.loaded = !0, a.deployment = g, x(), a.saveEnvVars = function() {
5402-
f.compact(a.updatedDeployment), v = d.update({
5407+
a.loaded = !0, a.deployment = g, z(), a.saveEnvVars = function() {
5408+
f.compact(a.updatedDeployment), x = d.update({
54035409
group:"extensions",
54045410
resource:"deployments"
5405-
}, c.deployment, a.updatedDeployment, m), v.then(function() {
5411+
}, c.deployment, a.updatedDeployment, n), x.then(function() {
54065412
a.alerts.saveEnvSuccess = {
54075413
type:"success",
54085414
message:c.deployment + " was updated."
@@ -5414,63 +5420,68 @@ message:c.deployment + " was not updated.",
54145420
details:b("getErrorDetails")(d)
54155421
};
54165422
})["finally"](function() {
5417-
v = null;
5423+
x = null;
54185424
});
54195425
}, a.clearEnvVarUpdates = function() {
5420-
a.updatedDeployment = f.copyAndNormalize(a.deployment), a.forms.deploymentEnvVars.$setPristine(), p = !1;
5421-
}, u.push(d.watchObject({
5426+
a.updatedDeployment = f.copyAndNormalize(a.deployment), a.forms.deploymentEnvVars.$setPristine(), q = !1;
5427+
}, v.push(d.watchObject({
54225428
group:"extensions",
54235429
resource:"deployments"
5424-
}, c.deployment, m, function(b, c) {
5430+
}, c.deployment, n, function(b, c) {
54255431
"DELETED" === c && (a.alerts.deleted = {
54265432
type:"warning",
54275433
message:"This deployment has been deleted."
54285434
});
54295435
var d = a.deployment;
5430-
a.deployment = b, a.updatingPausedState = !1, x(), q(b, d), v ? v["finally"](function() {
5431-
q(b, d);
5432-
}) :q(b, d), h.fetchReferencedImageStreamImages([ b.spec.template ], a.imagesByDockerReference, o, m);
5433-
})), u.push(d.watch({
5436+
a.deployment = b, a.updatingPausedState = !1, z(), r(b, d), x ? x["finally"](function() {
5437+
r(b, d);
5438+
}) :r(b, d), h.fetchReferencedImageStreamImages([ b.spec.template ], a.imagesByDockerReference, p, n);
5439+
})), v.push(d.watch({
54345440
group:"extensions",
54355441
resource:"replicasets"
5436-
}, m, function(b) {
5442+
}, n, function(b) {
5443+
a.emptyMessage = "No deployments to show";
54375444
var c = b.by("metadata.name");
5438-
c = k.filterForController(c, g), a.inProgressDeployment = _.chain(c).filter("status.replicas").size() > 1, a.replicaSetsForDeployment = e.sortByRevision(c);
5445+
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);
54395446
}));
54405447
}, function(c) {
54415448
a.loaded = !0, a.alerts.load = {
54425449
type:"error",
54435450
message:404 === c.status ? "This deployment can not be found, it may have been deleted." :"The deployment details could not be loaded.",
54445451
details:b("getErrorDetails")(c)
54455452
};
5446-
}), d.list("limitranges", m).then(function(a) {
5447-
w = a.by("metadata.name"), x();
5453+
}), d.list("limitranges", n).then(function(a) {
5454+
y = a.by("metadata.name"), z();
54485455
});
5449-
var y = [], z = [];
5450-
a.valueFromObjects = [], d.list("configmaps", m, null, {
5456+
var A = [], B = [];
5457+
a.valueFromObjects = [], d.list("configmaps", n, null, {
54515458
errorNotification:!1
54525459
}).then(function(b) {
5453-
y = r(b.by("metadata.name")), a.valueFromObjects = y.concat(z);
5460+
A = s(b.by("metadata.name")), a.valueFromObjects = A.concat(B);
54545461
}, function(a) {
5455-
403 !== a.code && t("Could not load config maps", s(a));
5456-
}), d.list("secrets", m, null, {
5462+
403 !== a.code && u("Could not load config maps", t(a));
5463+
}), d.list("secrets", n, null, {
54575464
errorNotification:!1
54585465
}).then(function(b) {
5459-
z = r(b.by("metadata.name")), a.valueFromObjects = z.concat(y);
5466+
B = s(b.by("metadata.name")), a.valueFromObjects = B.concat(A);
54605467
}, function(a) {
5461-
403 !== a.code && t("Could not load secrets", s(a));
5462-
}), u.push(d.watch("imagestreams", m, function(b) {
5468+
403 !== a.code && u("Could not load secrets", t(a));
5469+
}), v.push(d.watch("imagestreams", n, function(b) {
54635470
var c = b.by("metadata.name");
5464-
h.buildDockerRefMapForImageStreams(c, o), a.deployment && h.fetchReferencedImageStreamImages([ a.deployment.spec.template ], a.imagesByDockerReference, o, m), l.log("imagestreams (subscribe)", a.imageStreams);
5465-
})), u.push(d.watch({
5471+
h.buildDockerRefMapForImageStreams(c, p), a.deployment && h.fetchReferencedImageStreamImages([ a.deployment.spec.template ], a.imagesByDockerReference, p, n), j.log("imagestreams (subscribe)", a.imageStreams);
5472+
})), v.push(d.watch({
54665473
group:"autoscaling",
54675474
resource:"horizontalpodautoscalers",
54685475
version:"v1"
5469-
}, m, function(b) {
5470-
a.autoscalers = g.filterHPA(b.by("metadata.name"), "Deployment", c.deployment), x();
5471-
})), u.push(d.watch("builds", m, function(b) {
5472-
a.builds = b.by("metadata.name"), l.log("builds (subscribe)", a.builds);
5473-
})), a.scale = function(c) {
5476+
}, n, function(b) {
5477+
a.autoscalers = g.filterHPA(b.by("metadata.name"), "Deployment", c.deployment), z();
5478+
})), v.push(d.watch("builds", n, function(b) {
5479+
a.builds = b.by("metadata.name"), j.log("builds (subscribe)", a.builds);
5480+
})), i.onActiveFiltersChanged(function(b) {
5481+
a.$evalAsync(function() {
5482+
a.replicaSetsForDeployment = b.select(a.unfilteredReplicaSetsForDeployment), w();
5483+
});
5484+
}), a.scale = function(c) {
54745485
var d = function(c) {
54755486
a.alerts = a.alerts || {}, a.alerts.scale = {
54765487
type:"error",
@@ -5480,7 +5491,7 @@ details:b("getErrorDetails")(c)
54805491
};
54815492
e.scale(a.deployment, c).then(_.noop, d);
54825493
}, a.setPaused = function(c) {
5483-
a.updatingPausedState = !0, e.setPaused(a.deployment, c, m).then(_.noop, function(d) {
5494+
a.updatingPausedState = !0, e.setPaused(a.deployment, c, n).then(_.noop, function(d) {
54845495
a.updatingPausedState = !1, a.alerts = a.alerts || {}, a.alerts.scale = {
54855496
type:"error",
54865497
message:"An error occurred " + (c ? "pausing" :"resuming") + " the deployment.",
@@ -5490,18 +5501,18 @@ details:b("getErrorDetails")(d)
54905501
}, a.removeVolume = function(b) {
54915502
var c;
54925503
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.");
5493-
var d = i.confirm({
5504+
var d = k.confirm({
54945505
message:"Remove volume " + b.name + "?",
54955506
details:c,
54965507
okButtonText:"Remove",
54975508
okButtonClass:"btn-danger",
54985509
cancelButtonText:"Cancel"
54995510
}), e = function() {
5500-
n.removeVolume(a.deployment, b, m);
5511+
o.removeVolume(a.deployment, b, n);
55015512
};
55025513
d.then(e);
55035514
}, a.$on("$destroy", function() {
5504-
d.unwatchAll(u);
5515+
d.unwatchAll(v);
55055516
});
55065517
}));
55075518
} ]), 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)