diff --git a/examples/typescript/cdk8s-plus-elasticsearch-query/__snapshots__/main.test.ts.snap b/examples/typescript/cdk8s-plus-elasticsearch-query/__snapshots__/main.test.ts.snap index d71854c4d3..84bffa74c0 100644 --- a/examples/typescript/cdk8s-plus-elasticsearch-query/__snapshots__/main.test.ts.snap +++ b/examples/typescript/cdk8s-plus-elasticsearch-query/__snapshots__/main.test.ts.snap @@ -46,7 +46,7 @@ Array [ "apiVersion": "apps/v1", "kind": "Deployment", "metadata": Object { - "name": "test-chart-deployment-c5d38cbe", + "name": "test-chart-deployment-e606f14e", }, "spec": Object { "replicas": 1, @@ -99,7 +99,7 @@ Array [ "volumeMounts": Array [ Object { "mountPath": "/root", - "name": "configmap-test-chart-config-configmap-233db8e7", + "name": "configmap-test-chart-config-c3f7d3c0", }, ], "workingDir": "/root", @@ -108,9 +108,9 @@ Array [ "volumes": Array [ Object { "configMap": Object { - "name": "test-chart-config-configmap-233db8e7", + "name": "test-chart-config-c3f7d3c0", }, - "name": "configmap-test-chart-config-configmap-233db8e7", + "name": "configmap-test-chart-config-c3f7d3c0", }, ], }, @@ -121,7 +121,7 @@ Array [ "apiVersion": "v1", "kind": "Service", "metadata": Object { - "name": "test-chart-deployment-service-pod-28e7837f", + "name": "test-chart-deployment-service-7f4c5401", }, "spec": Object { "externalIPs": Array [], @@ -210,7 +210,7 @@ function doSearch(uri, callback) { }, "kind": "ConfigMap", "metadata": Object { - "name": "test-chart-config-configmap-233db8e7", + "name": "test-chart-config-c3f7d3c0", }, }, ] diff --git a/packages/cdk8s-plus-17/src/config-map.ts b/packages/cdk8s-plus-17/src/config-map.ts index 5f625af263..d7e843a2ab 100644 --- a/packages/cdk8s-plus-17/src/config-map.ts +++ b/packages/cdk8s-plus-17/src/config-map.ts @@ -67,7 +67,7 @@ export class ConfigMap extends Resource implements IConfigMap { public constructor(scope: Construct, id: string, props: ConfigMapProps = { }) { super(scope, id, { metadata: props.metadata }); - this.apiObject = new k8s.KubeConfigMap(this, 'ConfigMap', { + this.apiObject = new k8s.KubeConfigMap(this, 'Resource', { metadata: props.metadata, // we need lazy here because we filter empty diff --git a/packages/cdk8s-plus-17/src/deployment.ts b/packages/cdk8s-plus-17/src/deployment.ts index a1c2845ec4..bcf0b94a00 100644 --- a/packages/cdk8s-plus-17/src/deployment.ts +++ b/packages/cdk8s-plus-17/src/deployment.ts @@ -113,7 +113,7 @@ export class Deployment extends Resource implements IPodTemplate { constructor(scope: Construct, id: string, props: DeploymentProps = {}) { super(scope, id, { metadata: props.metadata }); - this.apiObject = new k8s.KubeDeployment(this, 'Deployment', { + this.apiObject = new k8s.KubeDeployment(this, 'Resource', { metadata: props.metadata, spec: Lazy.any({ produce: () => this._toKube() }), }); diff --git a/packages/cdk8s-plus-17/src/ingress-v1beta1.ts b/packages/cdk8s-plus-17/src/ingress-v1beta1.ts index 9ade00eb6b..a4c9013bd1 100644 --- a/packages/cdk8s-plus-17/src/ingress-v1beta1.ts +++ b/packages/cdk8s-plus-17/src/ingress-v1beta1.ts @@ -48,7 +48,7 @@ export class IngressV1Beta1 extends Resource { constructor(scope: Construct, id: string, props: IngressV1Beta1Props = {}) { super(scope, id, { metadata: props.metadata }); - this.apiObject = new k8s.KubeIngressV1Beta1(this, 'Ingress', { + this.apiObject = new k8s.KubeIngressV1Beta1(this, 'Resource', { metadata: props.metadata, spec: { backend: Lazy.any({ produce: () => this._defaultBackend?._toKube() }), diff --git a/packages/cdk8s-plus-17/src/job.ts b/packages/cdk8s-plus-17/src/job.ts index 9c194c0b06..89fb9c8768 100644 --- a/packages/cdk8s-plus-17/src/job.ts +++ b/packages/cdk8s-plus-17/src/job.ts @@ -53,7 +53,7 @@ export class Job extends Resource implements IPodTemplate { constructor(scope: Construct, id: string, props: JobProps = {}) { super(scope, id, { metadata: props.metadata }); - this.apiObject = new k8s.KubeJob(this, 'Default', { + this.apiObject = new k8s.KubeJob(this, 'Resource', { metadata: props.metadata, spec: Lazy.any({ produce: () => this._toKube() }), }); diff --git a/packages/cdk8s-plus-17/src/pod.ts b/packages/cdk8s-plus-17/src/pod.ts index 4a16629260..4a844d9c65 100644 --- a/packages/cdk8s-plus-17/src/pod.ts +++ b/packages/cdk8s-plus-17/src/pod.ts @@ -252,7 +252,7 @@ export class Pod extends Resource implements IPodSpec { constructor(scope: Construct, id: string, props: PodProps = {}) { super(scope, id, { metadata: props.metadata }); - this.apiObject = new k8s.KubePod(this, 'Pod', { + this.apiObject = new k8s.KubePod(this, 'Resource', { metadata: props.metadata, spec: Lazy.any({ produce: () => this._spec._toPodSpec() }), }); diff --git a/packages/cdk8s-plus-17/src/secret.ts b/packages/cdk8s-plus-17/src/secret.ts index a652850ca5..75ac1f4067 100644 --- a/packages/cdk8s-plus-17/src/secret.ts +++ b/packages/cdk8s-plus-17/src/secret.ts @@ -62,7 +62,7 @@ export class Secret extends Resource implements ISecret { this.stringData = props.stringData ?? {}; - this.apiObject = new k8s.KubeSecret(this, 'Secret', { + this.apiObject = new k8s.KubeSecret(this, 'Resource', { metadata: props.metadata, stringData: this.stringData, }); diff --git a/packages/cdk8s-plus-17/src/service.ts b/packages/cdk8s-plus-17/src/service.ts index c9bddf936b..c6a45fa352 100644 --- a/packages/cdk8s-plus-17/src/service.ts +++ b/packages/cdk8s-plus-17/src/service.ts @@ -131,7 +131,7 @@ export class Service extends Resource { constructor(scope: Construct, id: string, props: ServiceProps = {}) { super(scope, id, { metadata: props.metadata }); - this.apiObject = new k8s.KubeService(this, 'Pod', { + this.apiObject = new k8s.KubeService(this, 'Resource', { metadata: props.metadata, spec: cdk8s.Lazy.any({ produce: () => this._toKube() }), }); diff --git a/packages/cdk8s-plus-17/test/__snapshots__/config-map.test.ts.snap b/packages/cdk8s-plus-17/test/__snapshots__/config-map.test.ts.snap index a4095e9e25..b96f6ce442 100644 --- a/packages/cdk8s-plus-17/test/__snapshots__/config-map.test.ts.snap +++ b/packages/cdk8s-plus-17/test/__snapshots__/config-map.test.ts.snap @@ -9,7 +9,7 @@ Array [ }, "kind": "ConfigMap", "metadata": Object { - "name": "test-my-config-map-configmap-d0fa5644", + "name": "test-my-config-map-91419662", }, }, ] @@ -25,7 +25,7 @@ Array [ }, "kind": "ConfigMap", "metadata": Object { - "name": "test-my-config-map-configmap-d0fa5644", + "name": "test-my-config-map-91419662", }, }, ] @@ -41,7 +41,7 @@ Array [ }, "kind": "ConfigMap", "metadata": Object { - "name": "test-my-config-map-configmap-d0fa5644", + "name": "test-my-config-map-91419662", }, }, ] @@ -56,7 +56,7 @@ Array [ }, "kind": "ConfigMap", "metadata": Object { - "name": "test-my-config-map-configmap-d0fa5644", + "name": "test-my-config-map-91419662", }, }, ] @@ -72,7 +72,7 @@ Array [ }, "kind": "ConfigMap", "metadata": Object { - "name": "test-my-config-map-configmap-d0fa5644", + "name": "test-my-config-map-91419662", }, }, ] diff --git a/packages/cdk8s-plus-17/test/config-map.test.ts b/packages/cdk8s-plus-17/test/config-map.test.ts index 381356d492..8b04ae0e66 100644 --- a/packages/cdk8s-plus-17/test/config-map.test.ts +++ b/packages/cdk8s-plus-17/test/config-map.test.ts @@ -1,6 +1,17 @@ -import { Testing } from 'cdk8s'; +import { Testing, ApiObject } from 'cdk8s'; +import { Node } from 'constructs'; import { ConfigMap } from '../src'; +test('defaultChild', () => { + + const chart = Testing.chart(); + + const defaultChild = Node.of(new ConfigMap(chart, 'ConfigMap')).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('ConfigMap'); + +}); + test('minimal', () => { // GIVEN const chart = Testing.chart(); @@ -14,7 +25,7 @@ test('minimal', () => { apiVersion: 'v1', kind: 'ConfigMap', metadata: { - name: 'test-my-config-map-configmap-d0fa5644', + name: 'test-my-config-map-91419662', }, }, ]); @@ -42,7 +53,7 @@ test('with data', () => { key2: 'bar', }, metadata: { - name: 'test-my-config-map-configmap-d0fa5644', + name: 'test-my-config-map-91419662', }, }, ]); @@ -70,7 +81,7 @@ test('with binaryData', () => { key2: 'bar', }, metadata: { - name: 'test-my-config-map-configmap-d0fa5644', + name: 'test-my-config-map-91419662', }, }, ]); @@ -104,7 +115,7 @@ test('with binaryData and data', () => { key2: 'bar', }, metadata: { - name: 'test-my-config-map-configmap-d0fa5644', + name: 'test-my-config-map-91419662', }, }, ]); @@ -163,7 +174,7 @@ test('addData()/addBinaryDataq() can be used to add data', () => { }, kind: 'ConfigMap', metadata: { - name: 'test-my-config-map-configmap-d0fa5644', + name: 'test-my-config-map-91419662', }, }, ]); diff --git a/packages/cdk8s-plus-17/test/deployment.test.ts b/packages/cdk8s-plus-17/test/deployment.test.ts index 7a9f6a03f9..377b648c46 100644 --- a/packages/cdk8s-plus-17/test/deployment.test.ts +++ b/packages/cdk8s-plus-17/test/deployment.test.ts @@ -1,6 +1,17 @@ -import { Testing } from 'cdk8s'; +import { Testing, ApiObject } from 'cdk8s'; +import { Node } from 'constructs'; import * as kplus from '../src'; +test('defaultChild', () => { + + const chart = Testing.chart(); + + const defaultChild = Node.of(new kplus.Deployment(chart, 'Deployment')).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('Deployment'); + +}); + test('A label selector is automatically allocated', () => { const chart = Testing.chart(); diff --git a/packages/cdk8s-plus-17/test/ingress-v1beta1.test.ts b/packages/cdk8s-plus-17/test/ingress-v1beta1.test.ts index 6443e9edd3..f70a5ab575 100644 --- a/packages/cdk8s-plus-17/test/ingress-v1beta1.test.ts +++ b/packages/cdk8s-plus-17/test/ingress-v1beta1.test.ts @@ -1,6 +1,17 @@ -import { Testing } from 'cdk8s'; +import { Testing, ApiObject } from 'cdk8s'; +import { Node } from 'constructs'; import { IngressV1Beta1Backend, Service, IngressV1Beta1 } from '../src'; +test('defaultChild', () => { + + const chart = Testing.chart(); + + const defaultChild = Node.of(new IngressV1Beta1(chart, 'Ingress')).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('Ingress'); + +}); + describe('IngressBackend', () => { describe('fromService', () => { test('if the service exposes a port, it will be used by the ingress', () => { @@ -13,7 +24,7 @@ describe('IngressBackend', () => { // THEN expect(IngressV1Beta1Backend.fromService(service)._toKube()).toEqual({ - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 8899, }); }); @@ -50,7 +61,7 @@ describe('IngressBackend', () => { // THEN expect(IngressV1Beta1Backend.fromService(service, { port: 6011 })._toKube()).toEqual({ - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 6011, }); }); @@ -67,7 +78,7 @@ describe('IngressBackend', () => { // THEN expect(IngressV1Beta1Backend.fromService(service, { port: 8899 })._toKube()).toEqual({ - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 8899, }); }); @@ -119,10 +130,10 @@ describe('Ingress', () => { { apiVersion: 'networking.k8s.io/v1beta1', kind: 'Ingress', - metadata: { name: 'test-my-ingress-ingress-56b6a667' }, + metadata: { name: 'test-my-ingress-e859c4c6' }, spec: { backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, @@ -144,10 +155,10 @@ describe('Ingress', () => { { apiVersion: 'networking.k8s.io/v1beta1', kind: 'Ingress', - metadata: { name: 'test-my-ingress-ingress-56b6a667' }, + metadata: { name: 'test-my-ingress-e859c4c6' }, spec: { backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, @@ -171,7 +182,7 @@ describe('Ingress', () => { { apiVersion: 'networking.k8s.io/v1beta1', kind: 'Ingress', - metadata: { name: 'test-my-ingress-ingress-56b6a667' }, + metadata: { name: 'test-my-ingress-e859c4c6' }, spec: { rules: [{ host: 'my.host', @@ -179,7 +190,7 @@ describe('Ingress', () => { paths: [ { backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, @@ -208,7 +219,7 @@ describe('Ingress', () => { { apiVersion: 'networking.k8s.io/v1beta1', kind: 'Ingress', - metadata: { name: 'test-my-ingress-ingress-56b6a667' }, + metadata: { name: 'test-my-ingress-e859c4c6' }, spec: { rules: [ { @@ -218,14 +229,14 @@ describe('Ingress', () => { { path: '/bar', backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, { path: '/foo', backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, @@ -238,14 +249,14 @@ describe('Ingress', () => { paths: [ { backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, { path: '/', backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, @@ -273,7 +284,7 @@ describe('Ingress', () => { { apiVersion: 'networking.k8s.io/v1beta1', kind: 'Ingress', - metadata: { name: 'test-my-ingress-ingress-56b6a667' }, + metadata: { name: 'test-my-ingress-e859c4c6' }, spec: { rules: [ { @@ -282,14 +293,14 @@ describe('Ingress', () => { { path: '/foo', backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, { path: '/foo/bar', backend: { - serviceName: 'test-my-service-pod-1c817a88', + serviceName: 'test-my-service-72ba846b', servicePort: 80, }, }, @@ -320,13 +331,13 @@ describe('Ingress', () => { }); // THEN - const expectedBackend = { serviceName: 'test-my-service-pod-1c817a88', servicePort: 4000 }; + const expectedBackend = { serviceName: 'test-my-service-72ba846b', servicePort: 4000 }; expect(Testing.synth(chart).filter(x => x.kind === 'Ingress')).toEqual([ { apiVersion: 'networking.k8s.io/v1beta1', kind: 'Ingress', metadata: { - name: 'test-my-ingress-ingress-56b6a667', + name: 'test-my-ingress-e859c4c6', }, spec: { backend: expectedBackend, diff --git a/packages/cdk8s-plus-17/test/job.test.ts b/packages/cdk8s-plus-17/test/job.test.ts index f0a5b02267..a56c6057fe 100644 --- a/packages/cdk8s-plus-17/test/job.test.ts +++ b/packages/cdk8s-plus-17/test/job.test.ts @@ -1,6 +1,17 @@ -import { Testing, Duration } from 'cdk8s'; +import { Testing, Duration, ApiObject } from 'cdk8s'; +import { Node } from 'constructs'; import * as kplus from '../src'; +test('defaultChild', () => { + + const chart = Testing.chart(); + + const defaultChild = Node.of(new kplus.Job(chart, 'Job')).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('Job'); + +}); + test('Applies default restart policy to pod spec', () => { const chart = Testing.chart(); diff --git a/packages/cdk8s-plus-17/test/pod.test.ts b/packages/cdk8s-plus-17/test/pod.test.ts index 4a26666730..94c5c94891 100644 --- a/packages/cdk8s-plus-17/test/pod.test.ts +++ b/packages/cdk8s-plus-17/test/pod.test.ts @@ -1,6 +1,17 @@ -import { Testing } from 'cdk8s'; +import { Testing, ApiObject } from 'cdk8s'; +import { Node } from 'constructs'; import * as kplus from '../src'; +test('defaultChild', () => { + + const chart = Testing.chart(); + + const defaultChild = Node.of(new kplus.Pod(chart, 'Pod')).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('Pod'); + +}); + test('Can add container post instantiation', () => { const chart = Testing.chart(); diff --git a/packages/cdk8s-plus-17/test/secret.test.ts b/packages/cdk8s-plus-17/test/secret.test.ts index e50c141b81..602f64e719 100644 --- a/packages/cdk8s-plus-17/test/secret.test.ts +++ b/packages/cdk8s-plus-17/test/secret.test.ts @@ -1,6 +1,16 @@ -import { Testing } from 'cdk8s'; +import { Testing, ApiObject } from 'cdk8s'; +import { Node } from 'constructs'; import * as kplus from '../src'; +test('defaultChild', () => { + const chart = Testing.chart(); + + const defaultChild = Node.of(new kplus.Secret(chart, 'Secret')).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('Secret'); + +}); + test('Can be imported from secret name', () => { const secret = kplus.Secret.fromSecretName('secret'); @@ -19,7 +29,7 @@ test('Can add data to new secrets', () => { "apiVersion": "v1", "kind": "Secret", "metadata": Object { - "name": "test-secret-081177f7", + "name": "test-secret-17f996fa", }, "stringData": Object { "key": "value", diff --git a/packages/cdk8s-plus-17/test/service-account.test.ts b/packages/cdk8s-plus-17/test/service-account.test.ts index 417b49f7f1..8d74ad8f45 100644 --- a/packages/cdk8s-plus-17/test/service-account.test.ts +++ b/packages/cdk8s-plus-17/test/service-account.test.ts @@ -1,6 +1,16 @@ -import { Testing } from 'cdk8s'; +import { Testing, ApiObject } from 'cdk8s'; +import { Node } from 'constructs'; import * as kplus from '../src'; +test('defaultChild', () => { + const chart = Testing.chart(); + + const defaultChild = Node.of(new kplus.ServiceAccount(chart, 'ServiceAccount')).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('ServiceAccount'); + +}); + test('minimal definition', () => { // GIVEN const chart = Testing.chart(); @@ -15,7 +25,7 @@ test('minimal definition', () => { "apiVersion": "v1", "kind": "ServiceAccount", "metadata": Object { - "name": "test-my-service-account-resource-a5be5a3b", + "name": "test-my-service-account-a5be5a3b", }, }, ] diff --git a/packages/cdk8s-plus-17/test/service.test.ts b/packages/cdk8s-plus-17/test/service.test.ts index e70b9e8301..2e4821587e 100644 --- a/packages/cdk8s-plus-17/test/service.test.ts +++ b/packages/cdk8s-plus-17/test/service.test.ts @@ -1,6 +1,17 @@ -import { Testing } from 'cdk8s'; +import { Testing, ApiObject } from 'cdk8s'; +import { Node } from 'constructs'; import * as kplus from '../src'; +test('defaultChild', () => { + + const chart = Testing.chart(); + + const defaultChild = Node.of(new kplus.Service(chart, 'Service')).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('Service'); + +}); + test('Must be configured with at least one port', () => { const chart = Testing.chart(); diff --git a/packages/cdk8s-plus-17/test/volume.test.ts b/packages/cdk8s-plus-17/test/volume.test.ts index 588ef542ca..e2072f14dc 100644 --- a/packages/cdk8s-plus-17/test/volume.test.ts +++ b/packages/cdk8s-plus-17/test/volume.test.ts @@ -16,10 +16,10 @@ describe('fromConfigMap', () => { "configMap": Object { "defaultMode": undefined, "items": undefined, - "name": "test-my-config-map-configmap-d0fa5644", + "name": "test-my-config-map-91419662", "optional": undefined, }, - "name": "configmap-test-my-config-map-configmap-d0fa5644", + "name": "configmap-test-my-config-map-91419662", } `); }); @@ -37,7 +37,7 @@ describe('fromConfigMap', () => { // THEN expect(vol._toKube().name).toBe('filesystem'); expect(vol._toKube().configMap?.name).toBe( - 'test-my-config-map-configmap-d0fa5644', + 'test-my-config-map-91419662', ); }); diff --git a/packages/cdk8s/src/names.ts b/packages/cdk8s/src/names.ts index fb22b0464d..dd46a0473d 100644 --- a/packages/cdk8s/src/names.ts +++ b/packages/cdk8s/src/names.ts @@ -53,16 +53,7 @@ export class Names { components.push(calcHash(path, HASH_LEN)); - return components - .reverse() - .filter(omitDuplicates) - .join('/') - .slice(0, maxLen) - .split('/') - .reverse() - .filter(x => x) - .join('-') - .split('-').filter(x => x).join('-'); // remove empty components between `-`s. + return toHumanForm(components, '-', maxLen); } /** @@ -115,18 +106,7 @@ export class Names { components.push(calcHash(path, HASH_LEN)); - const result = components - .reverse() - .filter(omitDuplicates) - .join('/') - .slice(0, maxLen) - .split('/') - .reverse() - .filter(x => x) - .join(delim) - .split(delim) - .filter(x => x) - .join(delim); + const result = toHumanForm(components, delim, maxLen); // slicing might let '-', '_', '.' be in the start of the result. return result.replace(/^[^0-9a-zA-Z]+/, ''); @@ -142,6 +122,26 @@ function omitDuplicates(value: string, index: number, components: string[]) { return value !== components[index-1]; } +function omitDefaultChild(value: string, _: number, __: string[]) { + return value.toLowerCase() !== 'resource' && value.toLowerCase() !== 'default'; +} + +function toHumanForm(components: string[], delim: string, maxLen: number) { + return components.reverse() + .filter(omitDuplicates) + .join('/') + .slice(0, maxLen) + .split('/') + .reverse() + .filter(x => x) + .join(delim) + .split(delim) + .filter(x => x) + .filter(omitDefaultChild) + .join(delim); + +} + function normalizeToDnsName(c: string, maxLen: number) { return c .toLocaleLowerCase() // lower case diff --git a/packages/cdk8s/test/__snapshots__/api-object.test.ts.snap b/packages/cdk8s/test/__snapshots__/api-object.test.ts.snap index 476c277486..b703f1670d 100644 --- a/packages/cdk8s/test/__snapshots__/api-object.test.ts.snap +++ b/packages/cdk8s/test/__snapshots__/api-object.test.ts.snap @@ -9,7 +9,7 @@ Array [ }, "kind": "ResourceType", "metadata": Object { - "name": "test-resource-3953b2d0", + "name": "test-3953b2d0", }, }, ] @@ -21,7 +21,7 @@ Array [ "apiVersion": "v1", "kind": "ResourceType", "metadata": Object { - "name": "test-resource-3953b2d0", + "name": "test-3953b2d0", }, "spec": Object { "prop1": "hello", @@ -51,7 +51,7 @@ Array [ "apiVersion": "v1", "kind": "MyResource", "metadata": Object { - "name": "test-my-resource-2998ce93", + "name": "test-my-2998ce93", }, }, ] @@ -63,7 +63,7 @@ Array [ "apiVersion": "v1", "kind": "MyResource", "metadata": Object { - "name": "test-my-resource-2998ce93", + "name": "test-my-2998ce93", }, "spec": Object { "firstProperty": "hello", @@ -82,14 +82,14 @@ Array [ "apiVersion": "v1", "kind": "MyResource", "metadata": Object { - "name": "test-my-resource-2998ce93", + "name": "test-my-2998ce93", }, }, Object { "apiVersion": "v1", "kind": "MyResource", "metadata": Object { - "name": "test-scope-my-resource-eddbdbb2", + "name": "test-scope-my-eddbdbb2", }, }, ] diff --git a/packages/cdk8s/test/names.test.ts b/packages/cdk8s/test/names.test.ts index e6acf6d746..915e05ef56 100644 --- a/packages/cdk8s/test/names.test.ts +++ b/packages/cdk8s/test/names.test.ts @@ -2,6 +2,14 @@ import { Names } from '../src/names'; describe('toDnsLabel', () => { const toDnsName = Names.toDnsLabel; + test('ignores default children', () => { + expect(toDnsName('hello/default/foo/world/default')).toEqual('hello-foo-world-5d193db9'); + expect(toDnsName('hello/resource/foo/world/resource')).toEqual('hello-foo-world-f5dd971f'); + expect(toDnsName('hello/resource/foo/world/default')).toEqual('hello-foo-world-2f1cee85'); + expect(toDnsName('hello/Resource/foo/world/Default')).toEqual('hello-foo-world-857189b5'); + expect(toDnsName('hello/default/foo/world/resource')).toEqual('hello-foo-world-e89fdfae'); + expect(toDnsName('resource/default')).toEqual('40b6bcd9'); + }); test('normalize to dns_name', () => { expect(toDnsName(' ')).toEqual('36a9e7f1'); @@ -69,6 +77,15 @@ describe('toDnsLabel', () => { describe('toLabel', () => { const toLabelValue = Names.toLabelValue; + test('ignores default children', () => { + expect(toLabelValue('hello/default/foo/world/default')).toEqual('hello-foo-world-5d193db9'); + expect(toLabelValue('hello/resource/foo/world/resource')).toEqual('hello-foo-world-f5dd971f'); + expect(toLabelValue('hello/resource/foo/world/default')).toEqual('hello-foo-world-2f1cee85'); + expect(toLabelValue('hello/Resource/foo/world/Default')).toEqual('hello-foo-world-857189b5'); + expect(toLabelValue('hello/default/foo/world/resource')).toEqual('hello-foo-world-e89fdfae'); + expect(toLabelValue('resource/default')).toEqual('40b6bcd9'); + }); + test('normalize to dns_name', () => { expect(toLabelValue(' ')).toEqual('36a9e7f1'); expect(toLabelValue('')).toEqual(''); // Empty label is allowed for a label value