Repository: awslabs/cdk8s
Pull request #389 (2020-11-18 14:15:24)

fix(plus-17): L2 default child
All L1 children are now called `Resource` to mark them as the default child of the L2.

BREAKING CHANGE: All L2 resource names will undergo a name change (e.g `test-chart-config-configmap-233db8e7` -> `test-chart-config-c3f7d3c0`)

Resolves https://github.com/awslabs/cdk8s/issues/373

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*


mergify[bot]: Your pull request will be updated and merged automatically (do not update manually).
mergify[bot]: Your pull request will be updated and merged automatically (do not update manually).

Patch:
diff --git a/packages/cdk8s-plus-17/src/config-map.ts b/packages/cdk8s-plus-17/src/config-map.ts
index 5f625af26..d7e843a2a 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 a1c2845ec..bcf0b94a0 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 9ade00eb6..a4c9013bd 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 9c194c0b0..89fb9c876 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 4a1662926..4a844d9c6 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 a652850ca..75ac1f406 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 c9bddf936..c6a45fa35 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/src/names.ts b/packages/cdk8s/src/names.ts
index fb22b0464..dd46a0473 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


Test patch:
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 d71854c4d..84bffa74c 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/test/__snapshots__/config-map.test.ts.snap b/packages/cdk8s-plus-17/test/__snapshots__/config-map.test.ts.snap
index a4095e9e2..b96f6ce44 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 381356d49..8b04ae0e6 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 7a9f6a03f..377b648c4 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 6443e9edd..f70a5ab57 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 f0a5b0226..a56c6057f 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 4a2666673..94c5c9489 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 e50c141b8..602f64e71 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 417b49f7f..8d74ad8f4 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 e70b9e830..2e4821587 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 588ef542c..e2072f14d 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/test/__snapshots__/api-object.test.ts.snap b/packages/cdk8s/test/__snapshots__/api-object.test.ts.snap
index 476c27748..b703f1670 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 e6acf6d74..915e05ef5 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