Skip to content

Commit f6709f6

Browse files
author
OpenShift Bot
authored
Merge pull request #1088 from benjaminapetersen/petsets-statefulsets
Merged by openshift-bot
2 parents 2cb38e1 + 075d122 commit f6709f6

14 files changed

+813
-0
lines changed

app/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ <h1>JavaScript Required</h1>
232232
<script src="scripts/controllers/deployment.js"></script>
233233
<script src="scripts/controllers/deploymentConfig.js"></script>
234234
<script src="scripts/controllers/replicaSet.js"></script>
235+
<script src="scripts/controllers/statefulSets.js"></script>
236+
<script src="scripts/controllers/statefulSet.js"></script>
235237
<script src="scripts/controllers/services.js"></script>
236238
<script src="scripts/controllers/service.js"></script>
237239
<script src="scripts/controllers/secrets.js"></script>

app/scripts/app.js

+10
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ angular
174174
templateUrl: 'views/edit/deployment-config.html',
175175
controller: 'EditDeploymentConfigController'
176176
})
177+
.when('/project/:project/browse/stateful-sets/', {
178+
templateUrl: 'views/browse/stateful-sets.html',
179+
controller: 'StatefulSetsController',
180+
reloadOnSearch: false
181+
})
182+
.when('/project/:project/browse/stateful-sets/:statefulset', {
183+
templateUrl: 'views/browse/stateful-set.html',
184+
controller: 'StatefulSetController',
185+
reloadOnSearch: false
186+
})
177187
.when('/project/:project/browse/rs/:replicaSet', {
178188
templateUrl: 'views/browse/replica-set.html',
179189
resolve: {

app/scripts/constants.js

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ window.OPENSHIFT_CONSTANTS = {
4545
"config-maps": "dev_guide/configmaps.html",
4646
"secrets": "dev_guide/secrets.html",
4747
"deployments": "dev_guide/deployments/how_deployments_work.html",
48+
//"stateful-sets": "", // TODO: docs are in progress
4849
"pods": "architecture/core_concepts/pods_and_services.html#pods",
4950
"services": "architecture/core_concepts/pods_and_services.html#services",
5051
"routes": "architecture/core_concepts/routes.html",
@@ -119,6 +120,13 @@ window.OPENSHIFT_CONSTANTS = {
119120
"/browse/rc/"
120121
]
121122
},
123+
{
124+
label: "Stateful Sets",
125+
href: "/browse/stateful-sets",
126+
prefixes: [
127+
"/browse/stateful-sets/"
128+
]
129+
},
122130
{
123131
label: "Pods",
124132
href: "/browse/pods",
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
'use strict';
2+
3+
angular
4+
.module('openshiftConsole')
5+
.controller('StatefulSetController', function(
6+
$filter,
7+
$scope,
8+
$routeParams,
9+
AlertMessageService,
10+
BreadcrumbsService,
11+
DataService,
12+
ProjectsService) {
13+
14+
$scope.projectName = $routeParams.project;
15+
$scope.statefulSetName = $routeParams.statefulset;
16+
$scope.forms = {};
17+
$scope.alerts = {};
18+
$scope.breadcrumbs = BreadcrumbsService.getBreadcrumbs({
19+
name: $scope.statefulSetName,
20+
kind: 'statefulSet',
21+
namespace: $routeParams.project
22+
});
23+
$scope.emptyMessage = "Loading...";
24+
25+
var altTextForValueFrom = $filter('altTextForValueFrom');
26+
var updateEnvVars = function(statefulSet) {
27+
_.each(statefulSet.spec.template.spec.containers, function(container) {
28+
_.each(container.env, altTextForValueFrom);
29+
});
30+
return statefulSet;
31+
};
32+
33+
AlertMessageService.getAlerts().forEach(function(alert) {
34+
$scope.alerts[alert.name] = alert.data;
35+
});
36+
AlertMessageService.clearAlerts();
37+
38+
var watches = [];
39+
var projectContext;
40+
41+
var updatePods = function(pods, selector) {
42+
if (!pods || !selector) {
43+
return;
44+
}
45+
return selector.select(pods);
46+
};
47+
48+
var resourceGroupVersion = {
49+
resource: 'statefulsets',
50+
group: 'apps',
51+
version: 'v1beta1'
52+
};
53+
54+
ProjectsService
55+
.get($routeParams.project)
56+
.then(_.spread(function(project, context) {
57+
projectContext = context;
58+
59+
DataService
60+
.get(resourceGroupVersion, $scope.statefulSetName, context)
61+
.then(function(statefulSet) {
62+
63+
angular.extend($scope, {
64+
statefulSet: updateEnvVars(statefulSet),
65+
project: project,
66+
projectContext: context,
67+
loaded: true,
68+
// TODO: support scaling(?). currently no scale subresource.
69+
isScalable: function() {
70+
return false;
71+
},
72+
scale: function() {}
73+
});
74+
75+
watches.push(DataService.watchObject(resourceGroupVersion, $scope.statefulSetName, context, function(statefulSet) {
76+
angular.extend($scope, {
77+
resourceGroupVersion: resourceGroupVersion,
78+
statefulSet: updateEnvVars(statefulSet)
79+
});
80+
}));
81+
82+
var pods;
83+
var selector;
84+
$scope.$watch('statefulSet.spec.selector', function() {
85+
selector = new LabelSelector($scope.statefulSet.spec.selector);
86+
$scope.podsForStatefulSet = updatePods(pods, selector);
87+
}, true);
88+
89+
watches.push(DataService.watch('pods', context, function(podData) {
90+
pods = podData.by('metadata.name');
91+
$scope.podsForStatefulSet = updatePods(pods, selector);
92+
}));
93+
94+
});
95+
}));
96+
97+
$scope.$on('$destroy', function(){
98+
DataService.unwatchAll(watches);
99+
});
100+
101+
});
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
angular.module('openshiftConsole')
4+
.controller('StatefulSetsController', function($scope, $routeParams, AlertMessageService, DataService, ProjectsService) {
5+
$scope.projectName = $routeParams.project;
6+
$scope.alerts = $scope.alerts || {};
7+
$scope.emptyMessage = "Loading...";
8+
9+
// get and clear any alerts
10+
AlertMessageService.getAlerts().forEach(function(alert) {
11+
$scope.alerts[alert.name] = alert.data;
12+
});
13+
AlertMessageService.clearAlerts();
14+
15+
var watches = [];
16+
ProjectsService
17+
.get($routeParams.project)
18+
.then(_.spread(function(project, context) {
19+
$scope.project = project;
20+
21+
watches.push(DataService.watch({
22+
resource: 'statefulsets',
23+
group: 'apps',
24+
version: 'v1beta1'
25+
}, context, function(statefulSets) {
26+
angular.extend($scope, {
27+
loaded: true,
28+
statefulSets: statefulSets.by('metadata.name')
29+
});
30+
}));
31+
32+
$scope.$on('$destroy', function(){
33+
DataService.unwatchAll(watches);
34+
});
35+
36+
}));
37+
});

app/scripts/directives/resources.js

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ angular.module('openshiftConsole')
127127
templateUrl: 'views/_volumes.html'
128128
};
129129
})
130+
.directive('volumeClaimTemplates', function() {
131+
return {
132+
restrict: 'E',
133+
scope: {
134+
templates: '=',
135+
},
136+
templateUrl: 'views/_volume-claim-templates.html'
137+
};
138+
})
130139
.directive('environment', function() {
131140
return {
132141
restrict: 'E',

app/scripts/filters/canI.js

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ angular
6464
],
6565
'projects': [
6666
{group: '', resource: 'projects', verbs: ['delete', 'update']}
67+
],
68+
'statefulsets': [
69+
{group: 'apps', resource: 'statefulsets', verbs: ['update', 'delete']}
6770
]
6871
};
6972
return function(resource) {

app/scripts/services/navigate.js

+4
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ angular.module("openshiftConsole")
196196
.segmentCoded(name.substring(0, ind))
197197
.segmentCoded(name.substring(ind + 1));
198198
break;
199+
case "StatefulSet":
200+
url.segment("stateful-sets")
201+
.segmentCoded(name);
202+
break;
199203
case "PersistentVolumeClaim":
200204
case "Pod":
201205
case "Route":

app/styles/_components.less

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@
153153
margin-bottom: 10px;
154154
}
155155

156+
// TODO: also using this style for a volume claim template.
157+
// consider a slightly more generic name that isn't limited to 'pod'
156158
.pod-template-block {
157159
+ .pod-template-block {
158160
margin-top: 15px;
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<div class="pod-template-block">
2+
<div
3+
ng-repeat="template in templates"
4+
class="pod-template">
5+
<div class="component-label">Storage claim: {{template.metadata.name}}</div>
6+
7+
<div row class="pod-template-image icon-row">
8+
<div>
9+
<span class="fa fa-lock" aria-hidden="true"></span>
10+
</div>
11+
<div flex class="word-break">
12+
<span class="pod-template-key">Access Modes:</span>
13+
<span ng-repeat="mode in template.spec.accessModes">
14+
{{mode | sentenceCase }}<span ng-if="!$last">, </span>
15+
</span>
16+
</div>
17+
</div>
18+
19+
<div row class="pod-template-image icon-row">
20+
<div>
21+
<span class="fa fa-database" aria-hidden="true"></span>
22+
</div>
23+
<div flex class="word-break">
24+
<span class="pod-template-key">Capacity:</span>
25+
<span>
26+
{{template.spec.resources.requests.storage}}
27+
</span>
28+
</div>
29+
</div>
30+
31+
<div
32+
row class="pod-template-image icon-row"
33+
ng-if="template.spec.selector.matchLabels">
34+
<div>
35+
<span class="fa fa-tag" aria-hidden="true"></span>
36+
</div>
37+
<div flex class="word-break">
38+
<span class="pod-template-key">Selector:</span>
39+
<span ng-repeat="(key, value) in template.spec.selector.matchLabels">
40+
{{key}}={{value}}<span ng-if="!$last">, </span>
41+
</span>
42+
</div>
43+
</div>
44+
45+
</div>
46+
</div>

0 commit comments

Comments
 (0)