Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 7611617

Browse files
authored
defaulting to the service name if no k8s backend name is passed. (#438)
* defaulting to the service name if no k8s backend name is passed. * adding explicit test case
1 parent e3eb3b2 commit 7611617

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

src/commands/hld/reconcile.test.ts

+45-6
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ describe("configureChartForRing", () => {
352352
let exec = jest.fn().mockReturnValue(Promise.resolve({}));
353353
const ringPath = "/path/to/ring";
354354
const ringName = "myringname";
355-
355+
const normalizedServiceName = "my-great-service";
356356
const serviceConfig: BedrockServiceConfig = {
357357
helm: {
358358
chart: {
@@ -365,11 +365,44 @@ describe("configureChartForRing", () => {
365365
k8sBackendPort: 80,
366366
};
367367

368-
const k8sSvcBackendAndName = [serviceConfig.k8sBackend, ringName].join("-");
369-
const expectedInvocation = `cd ${ringPath} && fab set --subcomponent "chart" serviceName="${k8sSvcBackendAndName}"`;
368+
it("should invoke the correct command for configuring a chart for a ring with the k8s service being configured from the config", async () => {
369+
await configureChartForRing(
370+
exec,
371+
ringPath,
372+
ringName,
373+
serviceConfig,
374+
normalizedServiceName
375+
);
376+
377+
const k8sSvcBackendAndName = [serviceConfig.k8sBackend, ringName].join("-");
378+
const expectedInvocation = `cd ${ringPath} && fab set --subcomponent "chart" serviceName="${k8sSvcBackendAndName}"`;
379+
380+
expect(exec).toBeCalled();
381+
expect(exec).toBeCalledWith(expectedInvocation);
382+
});
383+
384+
it("should invoke the correct command and calculate the k8s service name from the bedrock service name if there is no k8sbackend configured.", async () => {
385+
const serviceConfigNoK8sBackend: BedrockServiceConfig = {
386+
helm: {
387+
chart: {
388+
git: "foo",
389+
path: "bar",
390+
sha: "baz",
391+
},
392+
},
393+
k8sBackend: "",
394+
k8sBackendPort: 80,
395+
};
370396

371-
it("should invoke the correct command for configuring a chart for a ring", async () => {
372-
await configureChartForRing(exec, ringPath, ringName, serviceConfig);
397+
const k8sSvcBackendAndName = [normalizedServiceName, ringName].join("-");
398+
const expectedInvocation = `cd ${ringPath} && fab set --subcomponent "chart" serviceName="${k8sSvcBackendAndName}"`;
399+
await configureChartForRing(
400+
exec,
401+
ringPath,
402+
ringName,
403+
serviceConfigNoK8sBackend,
404+
normalizedServiceName
405+
);
373406

374407
expect(exec).toBeCalled();
375408
expect(exec).toBeCalledWith(expectedInvocation);
@@ -381,7 +414,13 @@ describe("configureChartForRing", () => {
381414
.mockImplementation(async () => Promise.reject(new Error()));
382415

383416
await expect(
384-
configureChartForRing(exec, ringPath, ringName, serviceConfig)
417+
configureChartForRing(
418+
exec,
419+
ringPath,
420+
ringName,
421+
serviceConfig,
422+
normalizedServiceName
423+
)
385424
).rejects.toThrow();
386425
});
387426
});

src/commands/hld/reconcile.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ export const reconcileHld = async (
276276
dependencies.exec,
277277
normalizedRingPathInHld,
278278
normalizedRingName,
279-
serviceConfig
279+
serviceConfig,
280+
normalizedSvcName
280281
);
281282

282283
// Service explicitly requests no ingress-routes to be generated.
@@ -588,10 +589,13 @@ export const configureChartForRing = async (
588589
execCmd: (commandToRun: string) => Promise<ExecResult>,
589590
normalizedRingPathInHld: string,
590591
normalizedRingName: string,
591-
serviceConfig: BedrockServiceConfig
592+
serviceConfig: BedrockServiceConfig,
593+
normalizedServiceName: string
592594
): Promise<ExecResult> => {
593595
// Configue the k8s backend svc here along with master
594-
const k8sBackendName = serviceConfig.k8sBackend || "";
596+
// If no specific k8s backend name is provided, use the bedrock service name.
597+
const k8sBackendName = serviceConfig.k8sBackend || normalizedServiceName;
598+
595599
const k8sSvcBackendAndName = [
596600
normalizedName(k8sBackendName),
597601
normalizedRingName,

0 commit comments

Comments
 (0)