Skip to content

Commit 2ca4643

Browse files
authored
Provide a list of server and cluster hosts for ingress rule dialog (#213)
* Provide a list of server and cluster hosts for ingress rule dialog * Use template for string assignment * Use template for string assignment
1 parent 5c67633 commit 2ca4643

File tree

4 files changed

+85
-12
lines changed

4 files changed

+85
-12
lines changed

electron/app/js/wdtPrepareModel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
66
'use strict';
@@ -291,6 +291,16 @@ function formatResultsData(jsonContent) {
291291
}
292292
domain['clusters'] = clustersResult;
293293

294+
const servers = jsonContent['servers'] || [];
295+
const serversResult = [];
296+
for (const [serverName] of Object.entries(servers)) {
297+
const serverResult = {
298+
serverName: serverName
299+
};
300+
serversResult.push(serverResult);
301+
}
302+
domain['servers'] = serversResult;
303+
294304
results['domain'] = domain;
295305
return results;
296306
}

webui/src/js/models/k8s-domain-definition.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ define(['knockout', 'utils/observable-properties', 'utils/common-utilities', 'ut
7575
];
7676
this.clusters = props.createListProperty(this.clusterKeys).persistByKey('uid');
7777

78+
this.serverKeys = [
79+
'uid', 'name'
80+
];
81+
this.servers = props.createListProperty(this.serverKeys).persistByKey('uid');
82+
7883
this.modelConfigMapName = props.createProperty('${1}-config-map', this.uid.observable);
7984
this.modelConfigMapName.addValidator(...validationHelper.getK8sNameValidators());
8085

@@ -219,6 +224,21 @@ define(['knockout', 'utils/observable-properties', 'utils/common-utilities', 'ut
219224
return remove;
220225
});
221226
}
227+
228+
if (domain && Array.isArray(domain.servers)) {
229+
domain.servers.forEach(server => this.setServerRow(server));
230+
// Remove any servers that are no longer in the model
231+
this.servers.observable.remove(server => {
232+
let remove = true;
233+
for (const prepareModelServer of domain.servers) {
234+
if (prepareModelServer.serverName === server.name) {
235+
remove = false;
236+
break;
237+
}
238+
}
239+
return remove;
240+
});
241+
}
222242
};
223243

224244
this.setClusterRow = (prepareModelCluster) => {
@@ -245,6 +265,24 @@ define(['knockout', 'utils/observable-properties', 'utils/common-utilities', 'ut
245265
}
246266
};
247267

268+
this.setServerRow = (prepareModelServer) => {
269+
let server;
270+
for (const row of this.servers.observable()) {
271+
if (row.name === prepareModelServer.serverName) {
272+
server = row;
273+
break;
274+
}
275+
}
276+
if (server) {
277+
this.servers.observable.replace(server, server);
278+
} else {
279+
this.servers.addNewItem({
280+
uid: utils.getShortUuid(),
281+
name: prepareModelServer.serverName
282+
});
283+
}
284+
};
285+
248286
this.handlePrepareModelSecrets = (secrets) => {
249287
if (secrets && secrets.length) {
250288
wktLogger.debug('handlePrepareModelSecrets() working on %d secrets', secrets.length);

webui/src/js/viewModels/vz-ingress-trait-rule-edit-dialog.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/**
22
* @license
3-
* Copyright (c) 2022, Oracle and/or its affiliates.
3+
* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
44
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
55
*/
66
'use strict';
77

8-
define(['accUtils', 'knockout', 'utils/i18n', 'utils/observable-properties', 'utils/validation-helper',
9-
'ojs/ojarraydataprovider', 'ojs/ojconverter-number', 'utils/common-utilities', 'utils/wkt-logger',
10-
'ojs/ojselectcombobox', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog', 'ojs/ojformlayout',
11-
'ojs/ojvalidationgroup'],
12-
function(accUtils, ko, i18n, props, validationHelper, ArrayDataProvider, ojConverterNumber, utils, wktLogger) {
8+
define(['accUtils', 'knockout', 'utils/i18n', 'models/wkt-project', 'utils/observable-properties',
9+
'utils/validation-helper', 'ojs/ojarraydataprovider', 'ojs/ojconverter-number', 'utils/common-utilities',
10+
'utils/wkt-logger', 'ojs/ojselectcombobox', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog',
11+
'ojs/ojformlayout', 'ojs/ojvalidationgroup'],
12+
function(accUtils, ko, i18n, project, props, validationHelper,
13+
ArrayDataProvider, ojConverterNumber, utils, wktLogger) {
14+
1315
function VerrazzanoIngressTraitRuleEditDialogModel(args) {
1416
const DIALOG_SELECTOR = '#vzIngressTraitEditRuleDialog';
1517

@@ -181,6 +183,28 @@ function(accUtils, ko, i18n, props, validationHelper, ArrayDataProvider, ojConve
181183
}
182184
];
183185

186+
this.destinationHostNames = ko.computed(() => {
187+
let options = [];
188+
const domainName = project.wdtModel.domainName();
189+
190+
const clusters = project.k8sDomain.clusters.observable();
191+
for (const cluster of clusters) {
192+
const clusterHostName = utils.toLegalK8sName(`${domainName}-cluster-${cluster.name}`);
193+
options.push( { id : cluster.uid, value: clusterHostName, text: clusterHostName});
194+
}
195+
196+
const servers = project.k8sDomain.servers.observable();
197+
for (const server of servers) {
198+
const serverHostName = utils.toLegalK8sName(`${domainName}-${server.name}`);
199+
options.push( { id : server.uid, value: serverHostName, text: serverHostName});
200+
}
201+
202+
options.sort(function(a, b) {
203+
return a.text.localeCompare(b.text);
204+
});
205+
return options;
206+
});
207+
184208
this.pathTypeOptions = [
185209
{ value: 'prefix', label: this.labelMapper('path-type-prefix-label') },
186210
{ value: 'exact', label: this.labelMapper('path-type-exact-label') },

webui/src/js/views/vz-ingress-trait-rule-edit-dialog.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright (c) 2022, Oracle and/or its affiliates.
2+
Copyright (c) 2022, 2023, Oracle and/or its affiliates.
33
Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
44
-->
55
<oj-dialog id="vzIngressTraitEditRuleDialog" class="wkt-add-to-archive-dialog" initial-visibility="hide">
@@ -76,10 +76,11 @@ <h6 class="wkt-subheading">
7676
<oj-bind-text value="[[labelMapper('destination-title')]]"></oj-bind-text>
7777
</h6>
7878
<oj-form-layout max-columns="2" direction="row">
79-
<oj-input-text label-hint="[[labelMapper('destination-host-label')]]"
80-
value="{{destinationHost.observable}}"
81-
help.instruction="[[labelMapper('destination-host-help')]]">
82-
</oj-input-text>
79+
<oj-combobox-one value="{{destinationHost.observable}}"
80+
label-hint="[[labelMapper('destination-host-label')]]"
81+
help.instruction="[[labelMapper('destination-host-help')]]"
82+
options="[[destinationHostNames]]">
83+
</oj-combobox-one>
8384
<oj-input-number label-hint="[[labelMapper('destination-port-label')]]"
8485
value="{{destinationPort}}"
8586
converter="[[portNumberConverter]]"

0 commit comments

Comments
 (0)