Skip to content

Commit f419eb0

Browse files
committed
Allow users to type in ports for health checks
1 parent 7a4bd46 commit f419eb0

File tree

4 files changed

+119
-61
lines changed

4 files changed

+119
-61
lines changed

app/scripts/directives/editProbe.js

+46-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,31 @@ angular.module('openshiftConsole')
1313
scope.id = _.uniqueId('edit-probe-');
1414
scope.probe = scope.probe || {};
1515

16+
scope.types = [{
17+
id: 'httpGet',
18+
label: 'HTTP'
19+
}, {
20+
id: 'exec',
21+
label: 'Container Command'
22+
}, {
23+
id: 'tcpSocket',
24+
label: 'TCP Socket'
25+
}];
26+
1627
// Map of previous probes by type so switching to a different type and
1728
// back remembers the previous values.
1829
scope.previousProbes = {};
1930

20-
// Only allow selecting TCP ports for HTTP and TCP socket checks.
31+
// Show only TCP ports for HTTP and TCP socket checks.
2132
scope.tcpPorts = _.filter(scope.exposedPorts, { protocol: "TCP" });
33+
var initialValue = _.get(scope, 'probe.httpGet.port') || _.get(scope, 'probe.exec.port');
34+
if (initialValue && !_.some(scope.tcpPorts, { containerPort: initialValue })) {
35+
scope.tcpPorts = [{
36+
containerPort: initialValue,
37+
protocol: 'TCP'
38+
}].concat(scope.tcpPorts);
39+
}
40+
scope.portOptions = scope.tcpPorts;
2241

2342
var updateSelectedType = function(newType, oldType) {
2443
scope.probe = scope.probe || {};
@@ -52,25 +71,46 @@ angular.module('openshiftConsole')
5271
};
5372

5473
// Initialize type from existing data.
74+
var type;
5575
if (scope.probe.httpGet) {
56-
scope.type = 'httpGet';
76+
type = 'httpGet';
5777
} else if (scope.probe.exec) {
58-
scope.type = 'exec';
78+
type = 'exec';
5979
} else if (scope.probe.tcpSocket) {
60-
scope.type = 'tcpSocket';
80+
type = 'tcpSocket';
6181
} else {
6282
// Set defaults for new probe.
63-
scope.type = 'httpGet';
83+
type = 'httpGet';
6484
updateSelectedType('httpGet');
6585
}
6686

67-
scope.$watch('type', function(newType, oldType) {
87+
_.set(scope, 'selected.type', type);
88+
89+
scope.$watch('selected.type', function(newType, oldType) {
6890
if (newType === oldType) {
6991
return;
7092
}
7193

7294
updateSelectedType(newType, oldType);
7395
});
96+
97+
// Allow the user to type in a new value.
98+
scope.refreshPorts = function(search) {
99+
if (!/^\d+$/.test(search)) {
100+
return;
101+
}
102+
103+
var options = scope.tcpPorts;
104+
search = parseInt(search, 10);
105+
if (search && !_.some(options, { containerPort: search })) {
106+
options = [{
107+
containerPort: search,
108+
protocol: 'TCP'
109+
}].concat(options);
110+
}
111+
112+
scope.portOptions = _.uniq(options);
113+
};
74114
}
75115
};
76116
});

app/views/directives/_edit-probe.html

+24-32
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
<ng-form name="form">
22
<div class="form-group">
3-
<label ng-attr-for="{{id}}-type" class="required">Type</label>
4-
<select
5-
ng-model="type"
6-
ng-attr-id="{{id}}-type"
7-
required
8-
class="form-control">
9-
<option value="httpGet">HTTP</option>
10-
<option value="exec">Container Command</option>
11-
<option value="tcpSocket">TCP Socket</option>
12-
</select>
3+
<label class="required">Type</label>
4+
<ui-select ng-model="selected.type" required search-enabled="false">
5+
<ui-select-match>{{$select.selected.label}}</ui-select-match>
6+
<ui-select-choices repeat="item.id as item in types">{{item.label}}</ui-select-choices>
7+
</ui-select>
138
</div>
14-
<fieldset ng-if="type === 'httpGet'">
9+
<fieldset ng-if="selected.type === 'httpGet'">
1510
<div class="form-group">
1611
<label ng-attr-for="{{id}}-path">Path</label>
1712
<div>
@@ -27,33 +22,30 @@
2722
</div>
2823
</div>
2924
<div class="form-group">
30-
<label ng-attr-for="{{id}}-http-port" class="required">Port</label>
31-
<select
32-
id="{{id}}-http-port"
33-
ng-model="probe.httpGet.port"
34-
ng-options="port.containerPort as port.containerPort for port in tcpPorts"
35-
required
36-
class="form-control">
37-
</select>
38-
<div ng-if="!tcpPorts.length" class="has-error">
39-
<span class="help-block">Container has no TCP ports.</span>
40-
</div>
25+
<label class="required">Port</label>
26+
<ui-select ng-model="probe.httpGet.port" required>
27+
<ui-select-match>{{$select.selected.containerPort}}</ui-select-match>
28+
<ui-select-choices
29+
repeat="port.containerPort as port in portOptions"
30+
refresh="refreshPorts($select.search, $select.selected)"
31+
refresh-delay="200">{{port.containerPort}}</ui-select-choices>
32+
</ui-select>
4133
</div>
4234
</fieldset>
43-
<fieldset ng-if="type === 'exec'">
35+
<fieldset ng-if="selected.type === 'exec'">
4436
<label class="required">Command</label>
4537
<edit-command args="probe.exec.command" is-required="true"></edit-command>
4638
</fieldset>
47-
<fieldset ng-if="type === 'tcpSocket'">
39+
<fieldset ng-if="selected.type === 'tcpSocket'">
4840
<div class="form-group">
49-
<label ng-attr-for="{{id}}-tcp-port" class="required">Port</label>
50-
<select
51-
id="{{id}}-tcp-port"
52-
ng-model="probe.tcpSocket.port"
53-
ng-options="port.containerPort as port.containerPort for port in tcpPorts"
54-
required
55-
class="form-control">
56-
</select>
41+
<label class="required">Port</label>
42+
<ui-select ng-model="probe.tcpSocket.port" required>
43+
<ui-select-match>{{$select.selected.containerPort}}</ui-select-match>
44+
<ui-select-choices
45+
repeat="port.containerPort as port in portOptions"
46+
refresh="refreshPorts($select.search, $select.selected)"
47+
refresh-delay="200">{{port.containerPort}}</ui-select-choices>
48+
</ui-select>
5749
</div>
5850
</fieldset>
5951
<div class="form-group">

dist/scripts/scripts.js

+31-5
Original file line numberDiff line numberDiff line change
@@ -11547,10 +11547,26 @@ exposedPorts:"="
1154711547
},
1154811548
templateUrl:"views/directives/_edit-probe.html",
1154911549
link:function(a) {
11550-
a.id = _.uniqueId("edit-probe-"), a.probe = a.probe || {}, a.previousProbes = {}, a.tcpPorts = _.filter(a.exposedPorts, {
11550+
a.id = _.uniqueId("edit-probe-"), a.probe = a.probe || {}, a.types = [ {
11551+
id:"httpGet",
11552+
label:"HTTP"
11553+
}, {
11554+
id:"exec",
11555+
label:"Container Command"
11556+
}, {
11557+
id:"tcpSocket",
11558+
label:"TCP Socket"
11559+
} ], a.previousProbes = {}, a.tcpPorts = _.filter(a.exposedPorts, {
1155111560
protocol:"TCP"
1155211561
});
11553-
var b = function(b, c) {
11562+
var b = _.get(a, "probe.httpGet.port") || _.get(a, "probe.exec.port");
11563+
b && !_.some(a.tcpPorts, {
11564+
containerPort:b
11565+
}) && (a.tcpPorts = [ {
11566+
containerPort:b,
11567+
protocol:"TCP"
11568+
} ].concat(a.tcpPorts)), a.portOptions = a.tcpPorts;
11569+
var c, d = function(b, c) {
1155411570
if (a.probe = a.probe || {}, a.previousProbes[c] = a.probe[c], delete a.probe[c], a.probe[b] = a.previousProbes[b], !a.probe[b]) switch (b) {
1155511571
case "httpGet":
1155611572
case "tcpSocket":
@@ -11568,9 +11584,19 @@ command:[]
1156811584
};
1156911585
}
1157011586
};
11571-
a.probe.httpGet ? a.type = "httpGet" :a.probe.exec ? a.type = "exec" :a.probe.tcpSocket ? a.type = "tcpSocket" :(a.type = "httpGet", b("httpGet")), a.$watch("type", function(a, c) {
11572-
a !== c && b(a, c);
11573-
});
11587+
a.probe.httpGet ? c = "httpGet" :a.probe.exec ? c = "exec" :a.probe.tcpSocket ? c = "tcpSocket" :(c = "httpGet", d("httpGet")), _.set(a, "selected.type", c), a.$watch("selected.type", function(a, b) {
11588+
a !== b && d(a, b);
11589+
}), a.refreshPorts = function(b) {
11590+
if (/^\d+$/.test(b)) {
11591+
var c = a.tcpPorts;
11592+
b = parseInt(b, 10), b && !_.some(c, {
11593+
containerPort:b
11594+
}) && (c = [ {
11595+
containerPort:b,
11596+
protocol:"TCP"
11597+
} ].concat(c)), a.portOptions = _.uniq(c);
11598+
}
11599+
};
1157411600
}
1157511601
};
1157611602
}), angular.module("openshiftConsole").directive("editCommand", [ "$filter", function(a) {

dist/scripts/templates.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -4926,38 +4926,38 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
49264926
$templateCache.put('views/directives/_edit-probe.html',
49274927
"<ng-form name=\"form\">\n" +
49284928
"<div class=\"form-group\">\n" +
4929-
"<label ng-attr-for=\"{{id}}-type\" class=\"required\">Type</label>\n" +
4930-
"<select ng-model=\"type\" ng-attr-id=\"{{id}}-type\" required class=\"form-control\">\n" +
4931-
"<option value=\"httpGet\">HTTP</option>\n" +
4932-
"<option value=\"exec\">Container Command</option>\n" +
4933-
"<option value=\"tcpSocket\">TCP Socket</option>\n" +
4934-
"</select>\n" +
4929+
"<label class=\"required\">Type</label>\n" +
4930+
"<ui-select ng-model=\"selected.type\" required search-enabled=\"false\">\n" +
4931+
"<ui-select-match>{{$select.selected.label}}</ui-select-match>\n" +
4932+
"<ui-select-choices repeat=\"item.id as item in types\">{{item.label}}</ui-select-choices>\n" +
4933+
"</ui-select>\n" +
49354934
"</div>\n" +
4936-
"<fieldset ng-if=\"type === 'httpGet'\">\n" +
4935+
"<fieldset ng-if=\"selected.type === 'httpGet'\">\n" +
49374936
"<div class=\"form-group\">\n" +
49384937
"<label ng-attr-for=\"{{id}}-path\">Path</label>\n" +
49394938
"<div>\n" +
49404939
"<input ng-attr-id=\"{{id}}-path\" ng-model=\"probe.httpGet.path\" type=\"text\" placeholder=\"/\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" class=\"form-control\">\n" +
49414940
"</div>\n" +
49424941
"</div>\n" +
49434942
"<div class=\"form-group\">\n" +
4944-
"<label ng-attr-for=\"{{id}}-http-port\" class=\"required\">Port</label>\n" +
4945-
"<select id=\"{{id}}-http-port\" ng-model=\"probe.httpGet.port\" ng-options=\"port.containerPort as port.containerPort for port in tcpPorts\" required class=\"form-control\">\n" +
4946-
"</select>\n" +
4947-
"<div ng-if=\"!tcpPorts.length\" class=\"has-error\">\n" +
4948-
"<span class=\"help-block\">Container has no TCP ports.</span>\n" +
4949-
"</div>\n" +
4943+
"<label class=\"required\">Port</label>\n" +
4944+
"<ui-select ng-model=\"probe.httpGet.port\" required>\n" +
4945+
"<ui-select-match>{{$select.selected.containerPort}}</ui-select-match>\n" +
4946+
"<ui-select-choices repeat=\"port.containerPort as port in portOptions\" refresh=\"refreshPorts($select.search, $select.selected)\" refresh-delay=\"200\">{{port.containerPort}}</ui-select-choices>\n" +
4947+
"</ui-select>\n" +
49504948
"</div>\n" +
49514949
"</fieldset>\n" +
4952-
"<fieldset ng-if=\"type === 'exec'\">\n" +
4950+
"<fieldset ng-if=\"selected.type === 'exec'\">\n" +
49534951
"<label class=\"required\">Command</label>\n" +
49544952
"<edit-command args=\"probe.exec.command\" is-required=\"true\"></edit-command>\n" +
49554953
"</fieldset>\n" +
4956-
"<fieldset ng-if=\"type === 'tcpSocket'\">\n" +
4954+
"<fieldset ng-if=\"selected.type === 'tcpSocket'\">\n" +
49574955
"<div class=\"form-group\">\n" +
4958-
"<label ng-attr-for=\"{{id}}-tcp-port\" class=\"required\">Port</label>\n" +
4959-
"<select id=\"{{id}}-tcp-port\" ng-model=\"probe.tcpSocket.port\" ng-options=\"port.containerPort as port.containerPort for port in tcpPorts\" required class=\"form-control\">\n" +
4960-
"</select>\n" +
4956+
"<label class=\"required\">Port</label>\n" +
4957+
"<ui-select ng-model=\"probe.tcpSocket.port\" required>\n" +
4958+
"<ui-select-match>{{$select.selected.containerPort}}</ui-select-match>\n" +
4959+
"<ui-select-choices repeat=\"port.containerPort as port in portOptions\" refresh=\"refreshPorts($select.search, $select.selected)\" refresh-delay=\"200\">{{port.containerPort}}</ui-select-choices>\n" +
4960+
"</ui-select>\n" +
49614961
"</div>\n" +
49624962
"</fieldset>\n" +
49634963
"<div class=\"form-group\">\n" +

0 commit comments

Comments
 (0)