Skip to content

Commit 75e3af8

Browse files
Eliminate support for editing env vars, env vars are readonly on petsets
1 parent ccff2e5 commit 75e3af8

File tree

5 files changed

+229
-86
lines changed

5 files changed

+229
-86
lines changed

Diff for: app/scripts/controllers/petSet.js

+17-56
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ angular
1111
AlertMessageService,
1212
BreadcrumbsService,
1313
DataService,
14-
ProjectsService,
15-
keyValueEditorUtils) {
14+
ProjectsService) {
1615

1716
$scope.projectName = $routeParams.project;
1817
$scope.petSetName = $routeParams.petset;
1918
$scope.forms = {};
2019
$scope.alerts = {};
21-
// TODO: prob have to wire this up somehow
20+
// TODO: update getBreadcrumbs, currently returns:
21+
// Pet Sets > hello-petset
22+
// But the link for `Pet Sets` isn't valid. Where do we want these to live?
2223
$scope.breadcrumbs = BreadcrumbsService.getBreadcrumbs({
23-
name: $routeParams.petSet,
24+
name: $routeParams.petset,
2425
kind: 'PetSet',
2526
namespace: $routeParams.project
2627
});
@@ -34,45 +35,6 @@ angular
3435
var watches = [];
3536
var requestContext;
3637

37-
var copyPetSet = function(petSet) {
38-
var copied = angular.copy(petSet);
39-
_.each(copied.spec.template.spec.containers, function(container) {
40-
container.env = container.env || [];
41-
// check valueFrom attribs and set an alt text for display if present
42-
_.each(container.env, function(env) {
43-
$filter('altTextForValueFrom')(env);
44-
});
45-
});
46-
return copied;
47-
};
48-
49-
var clearEnvVarUpdates = function() {
50-
$scope.updatedPetSet = copyPetSet($scope.petSet);
51-
$scope.forms.petSetEnvVars.$setPristine();
52-
};
53-
// TODO: updates to petset spec for fields other than 'replicas' are forbidden
54-
var saveEnvVars = function() {
55-
_.each($scope.updatedPetSet.spec.template.spec.containers, function(container) {
56-
container.env = keyValueEditorUtils.compactEntries(angular.copy(container.env));
57-
});
58-
DataService
59-
.update('petsets', $routeParams.petset, angular.copy($scope.updatedPetSet), requestContext)
60-
.then(function resolve() {
61-
$scope.alerts['savePetSetEnvVarsError'] = {
62-
type: "success",
63-
// TODO: improve success alert
64-
message: $scope.petSetName + " was updated."
65-
};
66-
$scope.forms.dcEnvVars.$setPristine();
67-
}, function reject(e) {
68-
$scope.alerts['savePetSetEnvVarsError'] = {
69-
type: "error",
70-
message: $scope.petSetName + " was not updated.",
71-
details: "Reason: " + $filter('getErrorDetails')(e)
72-
};
73-
});
74-
};
75-
7638
var updatePods = function(pods, selector) {
7739
if (!pods || !selector) {
7840
return;
@@ -82,26 +44,25 @@ angular
8244
});
8345
};
8446

47+
var resourceGroupVersion = {
48+
resource: 'petsets',
49+
group: 'apps',
50+
version: 'v1alpha1'
51+
};
52+
8553
ProjectsService
8654
.get($routeParams.project)
8755
.then(_.spread(function(project, context) {
8856
requestContext = context;
8957

90-
watches.push(DataService.watchObject({
91-
resource: 'petsets',
92-
group: 'apps',
93-
version: 'v1alpha1'
94-
}, $routeParams.petset, context, function(petSet) {
95-
console.log('petSet', petSet, petSet.by && petSet.by('metadata.name'));
58+
watches.push(DataService.watchObject(resourceGroupVersion, $routeParams.petset, context, function(petSet) {
9659
angular.extend($scope, {
60+
resourceGroupVersion: resourceGroupVersion,
9761
petSet: petSet,
98-
updatedPetSet: copyPetSet(petSet),
9962
loaded: true,
100-
clearEnvVarUpdates: clearEnvVarUpdates,
101-
saveEnvVars: saveEnvVars,
102-
// TODO: support scaling?
103-
scale: function() {},
104-
isScalable: function() { return true; }
63+
// TODO: support scaling
64+
// scale: function() {},
65+
// isScalable: function() { return true; }
10566
});
10667
var pods;
10768
var selector;
@@ -112,14 +73,14 @@ angular
11273
// TODO: this is leaky. every time the outer watch updates,
11374
// we are creating a new watch on pods:
11475
// - console.log('# of watches?', watches.length); // steadily increments
76+
// we have this in a lot of places...
11577
watches.push(DataService.watch('pods', context, function(podData) {
11678
pods = podData.by('metadata.name');
11779
$scope.podsForPetSet = updatePods(pods, selector);
11880
}));
11981
}));
12082
}));
12183

122-
12384
$scope.$on('$destroy', function(){
12485
DataService.unwatchAll(watches);
12586
});

Diff for: app/scripts/filters/canI.js

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ angular
7272
]
7373
};
7474
return function(resource) {
75+
console.log('canIDoAny', resource);
7576
return _.some(resourceRulesMap[resource], function(rule) {
7677
return _.some(rule.verbs, function(verb) {
7778
return canIFilter({resource: rule.resource, group: rule.group}, verb);

Diff for: app/views/browse/pet-set.html

+23-28
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
<div class="container-fluid">
88
<breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
99
<alerts alerts="alerts"></alerts>
10-
<div ng-if="!loaded" class="mar-top-md">Loading...</div>
11-
<div ng-if="petSet">
10+
<div>
1211
<h1>
1312
{{petSet.metadata.name}}
14-
15-
<!-- ng-hide="!('petsets' | canIDoAny)"> TODO: why hidden? -->
1613
<div
1714
class="pull-right dropdown"
18-
ng-if="petSet">
15+
ng-if="petSet"
16+
ng-show="resourceGroupVersion.resource | canIDoAny">
1917
<button
2018
type="button"
2119
class="dropdown-toggle btn btn-default actions-dropdown-btn hidden-xs"
@@ -31,12 +29,12 @@ <h1>
3129
</a>
3230
<ul class="dropdown-menu actions action-button">
3331
<!-- TODO: kinda works, but cant seem to edit. neat. -->
34-
<li ng-if="{ group: 'apps', resource: 'petsets' } | canI : 'update'">
32+
<li ng-if="resourceGroupVersion | canI : 'update'">
3533
<a ng-href="{{petSet | editYamlURL}}" role="button">Edit YAML</a>
3634
</li>
37-
<li ng-if="{ group: 'apps', resource: 'petsets' } | canI : 'delete'">
38-
<!-- TODO: Warn about replicas -->
39-
<!-- TODO: hpa-list attrib? -->
35+
<li ng-if="resourceGroupVersion | canI : 'delete'">
36+
<!-- TODO: Warn about replicas? deleting petsets doesn't delete the pods -->
37+
<!-- TODO: hpa-list attrib? figure out autoscaling -->
4038
<delete-link
4139
kind="PetSet"
4240
group="apps"
@@ -61,7 +59,8 @@ <h1>
6159

6260
<div class="middle-content" persist-tab-state>
6361
<div class="container-fluid">
64-
<div class="row">
62+
<div ng-if="!loaded">Loading...</div>
63+
<div class="row" ng-if="loaded">
6564
<div class="col-md-12">
6665
<uib-tabset>
6766
<uib-tab active="selectedTab.details">
@@ -99,9 +98,7 @@ <h3>Template</h3>
9998
detailed="true">
10099
</pod-template>
101100

102-
103101
<h3>Pods</h3>
104-
<!-- TODO: look @ how this is done for replicaSets -->
105102
<pods-table pods="podsForPetSet"></pods-table>
106103

107104
<annotations annotations="petSet.metadata.annotations"></annotations>
@@ -113,34 +110,31 @@ <h3>Pods</h3>
113110
<uib-tab-heading>Environment</uib-tab-heading>
114111
<div class="resource-environment">
115112
<ng-form name="forms.petSetEnvVars">
116-
<div ng-repeat="container in updatedPetSet.spec.template.spec.containers">
113+
<div ng-repeat="container in petSet.spec.template.spec.containers">
117114
<h3>Container {{container.name}} Environment Variables</h3>
115+
<p>
116+
Environment variables for PetSets are readonly.
117+
<span ng-if="!(container.env.length)">
118+
There are no environment variables for this container.
119+
</span>
120+
</p>
118121
<!-- TODO: add the canI filter -->
119122
<key-value-editor
120123
entries="container.env"
121124
key-placeholder="Name"
122125
value-placeholder="Value"
123-
key-validator="[A-Za-z_][A-Za-z0-9_]*"
124-
key-validator-error="Please enter a valid key"
125-
key-validator-error-tooltip="A valid environment variable name is an alphanumeric (a-z and 0-9) string beginning with a letter that may contain underscores."
126-
add-row-link="Add environment variable"
126+
is-readonly
127+
cannot-add
128+
cannot-delete
129+
cannot-sort
127130
show-header></key-value-editor>
128-
<!-- TODO: canI filter! -->
129-
<button
130-
class="btn btn-default"
131-
ng-click="saveEnvVars()"
132-
ng-disabled="forms.petSetEnvVars.$pristine || forms.petSetEnvVars.$invalid">Save</button>
133-
<a
134-
ng-if="!forms.petSetEnvVars.$pristine"
135-
href=""
136-
ng-click="clearEnvVarUpdates()"
137-
class="mar-left-sm"
138-
style="vertical-align: -2px;">Clear changes</a>
131+
139132
</div>
140133
</ng-form>
141134
</div>
142135
</uib-tab>
143136

137+
<!-- TODO: impl these tabs
144138
<uib-tab active="selectedTab.metrics">
145139
<uib-tab-heading>Metrics</uib-tab-heading>
146140
<div class="resource-metrics">
@@ -161,6 +155,7 @@ <h3>Container {{container.name}} Environment Variables</h3>
161155
Events
162156
</div>
163157
</uib-tab>
158+
-->
164159

165160
</uib-tabset>
166161
</div>

Diff for: dist/scripts/scripts.js

+55-2
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ reloadOnSearch:!1
362362
}).when("/project/:project/edit/dc/:deploymentconfig", {
363363
templateUrl:"views/edit/deployment-config.html",
364364
controller:"EditDeploymentConfigController"
365+
}).when("/project/:project/browse/petsets/:petset", {
366+
templateUrl:"views/browse/pet-set.html",
367+
controller:"PetSetController",
368+
reloadOnSearch:!1
365369
}).when("/project/:project/browse/rs/:replicaSet", {
366370
templateUrl:"views/browse/replica-set.html",
367371
resolve:{
@@ -2238,6 +2242,10 @@ var m = h.indexOf(":");
22382242
i.segment("images").segmentCoded(h.substring(0, m)).segmentCoded(h.substring(m + 1));
22392243
break;
22402244

2245+
case "PetSet":
2246+
i.segment("petsets").segmentCoded(h);
2247+
break;
2248+
22412249
case "PersistentVolumeClaim":
22422250
case "Pod":
22432251
case "Route":
@@ -5834,7 +5842,13 @@ type:"warning",
58345842
details:"The active filters are hiding all deployments."
58355843
}) :void delete a.alerts.deployments;
58365844
}
5837-
a.project = c, o.push(e.watch("replicationcontrollers", d, function(c, d, e) {
5845+
a.project = c, o.push(e.watch({
5846+
resource:"petsets",
5847+
group:"apps",
5848+
version:"v1alpha1"
5849+
}, d, function(b) {
5850+
console.log("petsets?", b.by("metadata.name")), a.petsets = b.by("metadata.name");
5851+
})), o.push(e.watch("replicationcontrollers", d, function(c, d, e) {
58385852
a.replicationControllers = c.by("metadata.name");
58395853
var j, k;
58405854
if (e && (j = m(e, "deploymentConfig"), k = e.metadata.name), a.replicationControllersByDC = f.associateDeploymentsToDeploymentConfig(a.replicationControllers, a.deploymentConfigs, !0), a.replicationControllersByDC[""] && (a.unfilteredReplicationControllers = a.replicationControllersByDC[""], g.addLabelSuggestionsFromResources(a.unfilteredReplicationControllers, a.labelSuggestions), g.setLabelSuggestions(a.labelSuggestions), a.replicationControllersByDC[""] = g.getLabelSelector().select(a.replicationControllersByDC[""])), h(), d) {
@@ -6406,6 +6420,40 @@ e.then(g);
64066420
g.unwatchAll(w);
64076421
});
64086422
}));
6423+
} ]), angular.module("openshiftConsole").controller("PetSetController", [ "$filter", "$scope", "$routeParams", "AlertMessageService", "BreadcrumbsService", "DataService", "ProjectsService", function(a, b, c, d, e, f, g) {
6424+
b.projectName = c.project, b.petSetName = c.petset, b.forms = {}, b.alerts = {}, b.breadcrumbs = e.getBreadcrumbs({
6425+
name:c.petset,
6426+
kind:"PetSet",
6427+
namespace:c.project
6428+
}), b.emptyMessage = "Loading...", d.getAlerts().forEach(function(a) {
6429+
b.alerts[a.name] = a.data;
6430+
}), d.clearAlerts();
6431+
var h, i = [], j = function(a, b) {
6432+
if (a && b) return _.filter(a, function(a) {
6433+
return b.matches(a);
6434+
});
6435+
}, k = {
6436+
resource:"petsets",
6437+
group:"apps",
6438+
version:"v1alpha1"
6439+
};
6440+
g.get(c.project).then(_.spread(function(a, d) {
6441+
h = d, i.push(f.watchObject(k, c.petset, d, function(a) {
6442+
angular.extend(b, {
6443+
resourceGroupVersion:k,
6444+
petSet:a,
6445+
loaded:!0
6446+
});
6447+
var c, e;
6448+
b.$watch("petSet.spec.selector", function() {
6449+
e = new LabelSelector(b.petSet.spec.selector), b.podsForPetSet = j(c, e);
6450+
}, !0), i.push(f.watch("pods", d, function(a) {
6451+
c = a.by("metadata.name"), b.podsForPetSet = j(c, e);
6452+
}));
6453+
}));
6454+
})), b.$on("$destroy", function() {
6455+
f.unwatchAll(i);
6456+
});
64096457
} ]), angular.module("openshiftConsole").controller("ServicesController", [ "$routeParams", "$scope", "AlertMessageService", "DataService", "ProjectsService", "$filter", "LabelFilter", "Logger", function(a, b, c, d, e, f, g, h) {
64106458
b.projectName = a.project, b.services = {}, b.unfilteredServices = {}, b.routesByService = {}, b.routes = {}, b.labelSuggestions = {}, b.alerts = b.alerts || {}, b.emptyMessage = "Loading...", b.emptyMessageRoutes = "Loading...", c.getAlerts().forEach(function(a) {
64116459
b.alerts[a.name] = a.data;
@@ -14158,10 +14206,15 @@ projects:[ {
1415814206
group:"",
1415914207
resource:"projects",
1416014208
verbs:[ "delete", "update" ]
14209+
} ],
14210+
petsets:[ {
14211+
group:"apps",
14212+
resource:"petsets",
14213+
verbs:[ "create", "update", "delete" ]
1416114214
} ]
1416214215
};
1416314216
return function(c) {
14164-
return _.some(b[c], function(b) {
14217+
return console.log("canIDoAny", c), _.some(b[c], function(b) {
1416514218
return _.some(b.verbs, function(c) {
1416614219
return a({
1416714220
resource:b.resource,

0 commit comments

Comments
 (0)