Skip to content

Commit 62d8a0a

Browse files
authored
Correct legal k8s name function; use domain UID for rule hosts (#232)
1 parent 213e111 commit 62d8a0a

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

webui/src/js/utils/common-utilities.js

+5-4
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';
@@ -94,11 +94,12 @@ define([],
9494
toLegalK8sName(name) {
9595
if (this.isLegalK8sName(name)) return name;
9696

97-
let result = name.toLowerCase().replace(/[^-a-z0-9]/, '-');
97+
let result = name.toLowerCase().replaceAll(/[^a-z0-9-]/g, '-');
9898
while (result.startsWith('-')) result = result.slice(1);
99-
while (result.endsWith('-')) result = result.substring(0, result.length-1);
10099

101-
return result.substring(0, this.k8sMaxNameLength);
100+
result = result.substring(0, this.k8sMaxNameLength);
101+
while (result.endsWith('-')) result = result.slice(0, -1);
102+
return result;
102103
},
103104

104105
hashIt(str, seed = 0) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,17 @@ function(accUtils, ko, i18n, project, props, validationHelper,
187187

188188
this.destinationHostNames = ko.computed(() => {
189189
let options = [];
190-
const domainName = project.wdtModel.domainName();
190+
const domainUid = project.k8sDomain.uid.value;
191191

192192
const clusters = project.k8sDomain.clusters.observable();
193193
for (const cluster of clusters) {
194-
const clusterHostName = utils.toLegalK8sName(`${domainName}-cluster-${cluster.name}`);
194+
const clusterHostName = utils.toLegalK8sName(`${domainUid}-cluster-${cluster.name}`);
195195
options.push( { id : cluster.uid, value: clusterHostName, text: clusterHostName});
196196
}
197197

198198
const servers = project.k8sDomain.servers.observable();
199199
for (const server of servers) {
200-
const serverHostName = utils.toLegalK8sName(`${domainName}-${server.name}`);
200+
const serverHostName = utils.toLegalK8sName(`${domainUid}-${server.name}`);
201201
options.push( { id : server.uid, value: serverHostName, text: serverHostName});
202202
}
203203

webui/src/test/common-utilities-test.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
44
* Licensed under The Universal Permissive License (UPL), Version 1.0
55
* as shown at https://oss.oracle.com/licenses/upl/
66
* @ignore
@@ -34,50 +34,50 @@ describe('general utilities', function () {
3434
expect(utils.equals(1, 'a string')).to.equal(false);
3535
expect(utils.equals([1, 2, 3], {one: 'value'})).to.equal(false);
3636
});
37-
37+
3838
it('returns true when comparing equal scalars', function () {
3939
expect(utils.equals(undefined, undefined)).to.equal(true);
4040
expect(utils.equals(1, 8 - 7)).to.equal(true);
4141
expect(utils.equals(true, true)).to.equal(true);
4242
});
43-
43+
4444
it('returns false when comparing unequal scalars', function () {
4545
expect(utils.equals(true, false)).to.equal(false);
4646
expect(utils.equals('abcd', 'xyz')).to.equal(false);
4747
expect(utils.equals(1, 5)).to.equal(false);
4848
});
49-
49+
5050
it('returns false when comparing unequal objects', function () {
5151
expect(utils.equals({first: 1, second: 'both'}, {first: 1, second: 'neither'})).to.equal(false);
5252
expect(utils.equals({first: 1, second: 'both'}, {second: 'both', first: 1, third: null})).to.equal(false);
5353
expect(utils.equals({first: {nest: 1}, second: 'both'}, {second: 'both', first: [1]})).to.equal(false);
5454
});
55-
55+
5656
it('returns true when comparing equal objects', function () {
5757
expect(utils.equals({first: 1, second: 'both'}, {first: 1, second: 'both'})).to.equal(true);
5858
expect(utils.equals({first: 1, second: 'both'}, {second: 'both', first: 1})).to.equal(true);
5959
expect(utils.equals({first: {nest: 1}, second: 'both'}, {second: 'both', first: {nest: 1}})).to.equal(true);
6060
});
61-
61+
6262
it('returns true when comparing unequal arrays', function () {
6363
expect(utils.equals([1, 2, 3], [3, 1, 2])).to.equal(false);
6464
expect(utils.equals([{age: 12, height: 50}], [{age: 12, height: 60}])).to.equal(false);
6565
});
66-
66+
6767
it('returns true when comparing equal arrays', function () {
6868
expect(utils.equals([1, 2, 3], [1, 2, 3])).to.equal(true);
6969
expect(utils.equals([{age: 12, height: 50}], [{age: 12, height: 50}])).to.equal(true);
7070
});
7171
});
72-
72+
7373
// Kubernetes uses a modified version of the DNS-1123 standard.
7474
describe('Kubernetes names', function() {
7575
it ('recognizes legal Kubernetes names', function() {
7676
expect(utils.isLegalK8sName('aa')).to.be.true;
7777
expect(utils.isLegalK8sName('aa-bb-cc')).to.be.true;
7878
expect(utils.isLegalK8sName('aa12-b3')).to.be.true;
7979
});
80-
80+
8181
it ('recognizes illegal Kubernetes names', function() {
8282
expect(utils.isLegalK8sName(7)).to.be.false;
8383
expect(utils.isLegalK8sName('Aa')).to.be.false;
@@ -97,12 +97,13 @@ describe('general utilities', function () {
9797
it ('converts illegal to legal names', function() {
9898
expect(utils.toLegalK8sName('AA')).to.equal('aa');
9999
expect(utils.toLegalK8sName('aa_bb-cc')).to.equal('aa-bb-cc');
100+
expect(utils.toLegalK8sName('aa_bb_cc')).to.equal('aa-bb-cc');
100101
expect(utils.toLegalK8sName('aa12.b3')).to.equal('aa12-b3');
101102
expect(utils.toLegalK8sName('aa12$b3')).to.equal('aa12-b3');
102103
expect(utils.toLegalK8sName('--aa')).to.equal('aa');
103104
expect(utils.toLegalK8sName('aa--')).to.equal('aa');
104105
expect(utils.toLegalK8sName('aa-bb-cc-dd-ee-ff-gg-hh-ii-jj-kk-ll-mm-nn-oo-pp-qq-rr-ss-tt-uu-vv-ww-xx-yy-zz'))
105-
.to.equal('aa-bb-cc-dd-ee-ff-gg-hh-ii-jj-kk-ll-mm-nn-oo-pp-qq-rr-ss-tt-uu-');
106+
.to.equal('aa-bb-cc-dd-ee-ff-gg-hh-ii-jj-kk-ll-mm-nn-oo-pp-qq-rr-ss-tt-uu');
106107
});
107108
});
108109
});

0 commit comments

Comments
 (0)