From 8a916dffb560776082271c1ae71991a92f719207 Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:42:29 -0700 Subject: [PATCH 1/2] defaulting to the service name if no k8s backend name is passed. --- src/commands/hld/reconcile.test.ts | 18 +++++++++++++++--- src/commands/hld/reconcile.ts | 10 +++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/commands/hld/reconcile.test.ts b/src/commands/hld/reconcile.test.ts index e159eb5f6..2497fe10a 100644 --- a/src/commands/hld/reconcile.test.ts +++ b/src/commands/hld/reconcile.test.ts @@ -352,7 +352,7 @@ describe("configureChartForRing", () => { let exec = jest.fn().mockReturnValue(Promise.resolve({})); const ringPath = "/path/to/ring"; const ringName = "myringname"; - + const normalizedServiceName = "my-great-service"; const serviceConfig: BedrockServiceConfig = { helm: { chart: { @@ -369,7 +369,13 @@ describe("configureChartForRing", () => { const expectedInvocation = `cd ${ringPath} && fab set --subcomponent "chart" serviceName="${k8sSvcBackendAndName}"`; it("should invoke the correct command for configuring a chart for a ring", async () => { - await configureChartForRing(exec, ringPath, ringName, serviceConfig); + await configureChartForRing( + exec, + ringPath, + ringName, + serviceConfig, + normalizedServiceName + ); expect(exec).toBeCalled(); expect(exec).toBeCalledWith(expectedInvocation); @@ -381,7 +387,13 @@ describe("configureChartForRing", () => { .mockImplementation(async () => Promise.reject(new Error())); await expect( - configureChartForRing(exec, ringPath, ringName, serviceConfig) + configureChartForRing( + exec, + ringPath, + ringName, + serviceConfig, + normalizedServiceName + ) ).rejects.toThrow(); }); }); diff --git a/src/commands/hld/reconcile.ts b/src/commands/hld/reconcile.ts index 7169d7395..dd5c46449 100644 --- a/src/commands/hld/reconcile.ts +++ b/src/commands/hld/reconcile.ts @@ -276,7 +276,8 @@ export const reconcileHld = async ( dependencies.exec, normalizedRingPathInHld, normalizedRingName, - serviceConfig + serviceConfig, + normalizedSvcName ); // Service explicitly requests no ingress-routes to be generated. @@ -588,10 +589,13 @@ export const configureChartForRing = async ( execCmd: (commandToRun: string) => Promise, normalizedRingPathInHld: string, normalizedRingName: string, - serviceConfig: BedrockServiceConfig + serviceConfig: BedrockServiceConfig, + normalizedServiceName: string ): Promise => { // Configue the k8s backend svc here along with master - const k8sBackendName = serviceConfig.k8sBackend || ""; + // If no specific k8s backend name is provided, use the bedrock service name. + const k8sBackendName = serviceConfig.k8sBackend || normalizedServiceName; + const k8sSvcBackendAndName = [ normalizedName(k8sBackendName), normalizedRingName, From d5ba2465d44222fbac28448a4dbcbbfc2faec20c Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Mon, 23 Mar 2020 19:29:45 -0700 Subject: [PATCH 2/2] adding explicit test case --- src/commands/hld/reconcile.test.ts | 35 ++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/commands/hld/reconcile.test.ts b/src/commands/hld/reconcile.test.ts index 2497fe10a..4d50ca2cd 100644 --- a/src/commands/hld/reconcile.test.ts +++ b/src/commands/hld/reconcile.test.ts @@ -365,10 +365,7 @@ describe("configureChartForRing", () => { k8sBackendPort: 80, }; - const k8sSvcBackendAndName = [serviceConfig.k8sBackend, ringName].join("-"); - const expectedInvocation = `cd ${ringPath} && fab set --subcomponent "chart" serviceName="${k8sSvcBackendAndName}"`; - - it("should invoke the correct command for configuring a chart for a ring", async () => { + it("should invoke the correct command for configuring a chart for a ring with the k8s service being configured from the config", async () => { await configureChartForRing( exec, ringPath, @@ -377,6 +374,36 @@ describe("configureChartForRing", () => { normalizedServiceName ); + const k8sSvcBackendAndName = [serviceConfig.k8sBackend, ringName].join("-"); + const expectedInvocation = `cd ${ringPath} && fab set --subcomponent "chart" serviceName="${k8sSvcBackendAndName}"`; + + expect(exec).toBeCalled(); + expect(exec).toBeCalledWith(expectedInvocation); + }); + + it("should invoke the correct command and calculate the k8s service name from the bedrock service name if there is no k8sbackend configured.", async () => { + const serviceConfigNoK8sBackend: BedrockServiceConfig = { + helm: { + chart: { + git: "foo", + path: "bar", + sha: "baz", + }, + }, + k8sBackend: "", + k8sBackendPort: 80, + }; + + const k8sSvcBackendAndName = [normalizedServiceName, ringName].join("-"); + const expectedInvocation = `cd ${ringPath} && fab set --subcomponent "chart" serviceName="${k8sSvcBackendAndName}"`; + await configureChartForRing( + exec, + ringPath, + ringName, + serviceConfigNoK8sBackend, + normalizedServiceName + ); + expect(exec).toBeCalled(); expect(exec).toBeCalledWith(expectedInvocation); });