From 9fb7c6542d9e8d6926d46824ab3c9f0a954bcbbb Mon Sep 17 00:00:00 2001 From: Shinebayar Gansukh <3091558+shinebayar-g@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:39:29 -0800 Subject: [PATCH] feat(core): add `name` getter as alias to `metadata.name` --- examples/src/main.ts | 5 ++++- packages/core/src/ApiObject.ts | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/src/main.ts b/examples/src/main.ts index 43b61b3..4e393b3 100644 --- a/examples/src/main.ts +++ b/examples/src/main.ts @@ -1,5 +1,6 @@ import { Helm, K8sApp } from '@k8skonf/core'; import { Deploymentv1 } from '@k8skonf/core/Deploymentv1'; +import { log } from 'node:console'; const app = new K8sApp('my-k8s-app', 'filePerResource'); @@ -29,7 +30,7 @@ chart.resources.forEach((resource) => { console.log(resource.apiVersion); }); -new Deploymentv1(app, 'my-nginx-deployment', { +const d = new Deploymentv1(app, 'my-nginx-deployment', { spec: { selector: { matchLabels: { @@ -60,4 +61,6 @@ new Deploymentv1(app, 'my-nginx-deployment', { }, }); +log('name is:', d.name); + app.save(); diff --git a/packages/core/src/ApiObject.ts b/packages/core/src/ApiObject.ts index 1dae11f..962dde8 100644 --- a/packages/core/src/ApiObject.ts +++ b/packages/core/src/ApiObject.ts @@ -17,6 +17,10 @@ export abstract class ApiObject { abstract readonly metadata: ObjectMetav1; abstract readonly apiVersion: string; abstract readonly kind: string; + + get name() { + return this.metadata.name; + } } /**