Skip to content

Provide a list of server and cluster hosts for ingress rule dialog #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion electron/app/js/wdtPrepareModel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
'use strict';
Expand Down Expand Up @@ -291,6 +291,16 @@ function formatResultsData(jsonContent) {
}
domain['clusters'] = clustersResult;

const servers = jsonContent['servers'] || [];
const serversResult = [];
for (const [serverName] of Object.entries(servers)) {
const serverResult = {
serverName: serverName
};
serversResult.push(serverResult);
}
domain['servers'] = serversResult;

results['domain'] = domain;
return results;
}
Expand Down
38 changes: 38 additions & 0 deletions webui/src/js/models/k8s-domain-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ define(['knockout', 'utils/observable-properties', 'utils/common-utilities', 'ut
];
this.clusters = props.createListProperty(this.clusterKeys).persistByKey('uid');

this.serverKeys = [
'uid', 'name'
];
this.servers = props.createListProperty(this.serverKeys).persistByKey('uid');

this.modelConfigMapName = props.createProperty('${1}-config-map', this.uid.observable);
this.modelConfigMapName.addValidator(...validationHelper.getK8sNameValidators());

Expand Down Expand Up @@ -219,6 +224,21 @@ define(['knockout', 'utils/observable-properties', 'utils/common-utilities', 'ut
return remove;
});
}

if (domain && Array.isArray(domain.servers)) {
domain.servers.forEach(server => this.setServerRow(server));
// Remove any servers that are no longer in the model
this.servers.observable.remove(server => {
let remove = true;
for (const prepareModelServer of domain.servers) {
if (prepareModelServer.serverName === server.name) {
remove = false;
break;
}
}
return remove;
});
}
};

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

this.setServerRow = (prepareModelServer) => {
let server;
for (const row of this.servers.observable()) {
if (row.name === prepareModelServer.serverName) {
server = row;
break;
}
}
if (server) {
this.servers.observable.replace(server, server);
} else {
this.servers.addNewItem({
uid: utils.getShortUuid(),
name: prepareModelServer.serverName
});
}
};

this.handlePrepareModelSecrets = (secrets) => {
if (secrets && secrets.length) {
wktLogger.debug('handlePrepareModelSecrets() working on %d secrets', secrets.length);
Expand Down
36 changes: 30 additions & 6 deletions webui/src/js/viewModels/vz-ingress-trait-rule-edit-dialog.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/**
* @license
* Copyright (c) 2022, Oracle and/or its affiliates.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
*/
'use strict';

define(['accUtils', 'knockout', 'utils/i18n', 'utils/observable-properties', 'utils/validation-helper',
'ojs/ojarraydataprovider', 'ojs/ojconverter-number', 'utils/common-utilities', 'utils/wkt-logger',
'ojs/ojselectcombobox', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog', 'ojs/ojformlayout',
'ojs/ojvalidationgroup'],
function(accUtils, ko, i18n, props, validationHelper, ArrayDataProvider, ojConverterNumber, utils, wktLogger) {
define(['accUtils', 'knockout', 'utils/i18n', 'models/wkt-project', 'utils/observable-properties',
'utils/validation-helper', 'ojs/ojarraydataprovider', 'ojs/ojconverter-number', 'utils/common-utilities',
'utils/wkt-logger', 'ojs/ojselectcombobox', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog',
'ojs/ojformlayout', 'ojs/ojvalidationgroup'],
function(accUtils, ko, i18n, project, props, validationHelper,
ArrayDataProvider, ojConverterNumber, utils, wktLogger) {

function VerrazzanoIngressTraitRuleEditDialogModel(args) {
const DIALOG_SELECTOR = '#vzIngressTraitEditRuleDialog';

Expand Down Expand Up @@ -181,6 +183,28 @@ function(accUtils, ko, i18n, props, validationHelper, ArrayDataProvider, ojConve
}
];

this.destinationHostNames = ko.computed(() => {
let options = [];
const domainName = project.wdtModel.domainName();

const clusters = project.k8sDomain.clusters.observable();
for (const cluster of clusters) {
const clusterHostName = utils.toLegalK8sName(`${domainName}-cluster-${cluster.name}`);
options.push( { id : cluster.uid, value: clusterHostName, text: clusterHostName});
}

const servers = project.k8sDomain.servers.observable();
for (const server of servers) {
const serverHostName = utils.toLegalK8sName(`${domainName}-${server.name}`);
options.push( { id : server.uid, value: serverHostName, text: serverHostName});
}

options.sort(function(a, b) {
return a.text.localeCompare(b.text);
});
return options;
});

this.pathTypeOptions = [
{ value: 'prefix', label: this.labelMapper('path-type-prefix-label') },
{ value: 'exact', label: this.labelMapper('path-type-exact-label') },
Expand Down
11 changes: 6 additions & 5 deletions webui/src/js/views/vz-ingress-trait-rule-edit-dialog.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2022, Oracle and/or its affiliates.
Copyright (c) 2022, 2023, Oracle and/or its affiliates.
Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
-->
<oj-dialog id="vzIngressTraitEditRuleDialog" class="wkt-add-to-archive-dialog" initial-visibility="hide">
Expand Down Expand Up @@ -76,10 +76,11 @@ <h6 class="wkt-subheading">
<oj-bind-text value="[[labelMapper('destination-title')]]"></oj-bind-text>
</h6>
<oj-form-layout max-columns="2" direction="row">
<oj-input-text label-hint="[[labelMapper('destination-host-label')]]"
value="{{destinationHost.observable}}"
help.instruction="[[labelMapper('destination-host-help')]]">
</oj-input-text>
<oj-combobox-one value="{{destinationHost.observable}}"
label-hint="[[labelMapper('destination-host-label')]]"
help.instruction="[[labelMapper('destination-host-help')]]"
options="[[destinationHostNames]]">
</oj-combobox-one>
<oj-input-number label-hint="[[labelMapper('destination-port-label')]]"
value="{{destinationPort}}"
converter="[[portNumberConverter]]"
Expand Down