pulumi / pulumi-kubernetesx

Kubernetes for Everyone
Apache License 2.0
135 stars 16 forks source link

Allow caller to set name of services with `createService` method #72

Closed Oyelowo closed 2 years ago

Oyelowo commented 2 years ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @pulumi/kubernetesx@v0.1.6 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@pulumi/kubernetesx/kx.d.ts b/node_modules/@pulumi/kubernetesx/kx.d.ts
index 2bbe265..61b52d9 100644
--- a/node_modules/@pulumi/kubernetesx/kx.d.ts
+++ b/node_modules/@pulumi/kubernetesx/kx.d.ts
@@ -35,6 +35,9 @@ export declare namespace types {
         ports?: pulumi.Input<pulumi.Input<k8s.types.input.core.v1.ServicePort>[] | PortMap>;
         type?: pulumi.Input<ServiceType | string>;
     };
+    type CreateServiceArgs = types.ServiceSpec & {
+        name?: string;
+    };
     type Service = Omit<k8s.types.input.core.v1.Service, "spec"> & {
         spec: pulumi.Input<ServiceSpec>;
     };
@@ -70,7 +73,7 @@ export declare class Deployment extends k8s.apps.v1.Deployment {
     private readonly name;
     private readonly opts?;
     constructor(name: string, args: types.Deployment, opts?: pulumi.CustomResourceOptions);
-    createService(args?: types.ServiceSpec): Service;
+    createService(args?: types.CreateServiceArgs): Service;
 }
 export declare class Service extends k8s.core.v1.Service {
     constructor(name: string, args: types.Service, opts?: pulumi.CustomResourceOptions);
diff --git a/node_modules/@pulumi/kubernetesx/kx.js b/node_modules/@pulumi/kubernetesx/kx.js
index 4aa2874..a43c9a7 100644
--- a/node_modules/@pulumi/kubernetesx/kx.js
+++ b/node_modules/@pulumi/kubernetesx/kx.js
@@ -186,8 +186,9 @@ class Deployment extends k8s.apps.v1.Deployment {
                 // TODO: probably need to unwrap args.type in case it's a computed value
                 type: args && args.type });
         });
-        return new Service(this.name, {
-            metadata: { namespace: this.metadata.namespace },
+        const name = args.name ?? this.name;
+        return new Service(name, {
+            metadata: { namespace: this.metadata.namespace, name },
             spec: serviceSpec,
         }, Object.assign(Object.assign({}, this.opts), { parent: this }));
     }

This issue body was partially generated by patch-package.

danielrbradley commented 2 years ago

Closing in favor of #73