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

Commit d33f555

Browse files
bnookalamtarng
authored andcommitted
Use display name for creating service components and ingress routes (#205)
1 parent eedb87c commit d33f555

File tree

2 files changed

+90
-7
lines changed

2 files changed

+90
-7
lines changed

src/commands/hld/reconcile.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,78 @@ describe("reconcile tests", () => {
356356
expect(dependencies.createMiddlewareForRing).not.toHaveBeenCalled();
357357
expect(dependencies.createIngressRouteForRing).not.toHaveBeenCalled();
358358
});
359+
360+
it("does not create service components if the service path is `.`, and a display name does not exist", async () => {
361+
bedrockYaml.services = {
362+
".": {
363+
disableRouteScaffold: false,
364+
helm: {
365+
chart: {
366+
git,
367+
path,
368+
sha
369+
}
370+
},
371+
k8sServicePort: 80
372+
}
373+
};
374+
375+
await reconcileHld(dependencies, bedrockYaml, "service", "./path/to/hld");
376+
377+
expect(dependencies.createServiceComponent).not.toHaveBeenCalled();
378+
});
379+
380+
it("does create service components if the service path is `.` and a display name does exist", async () => {
381+
const displayName = "fabrikam";
382+
383+
bedrockYaml.services = {
384+
".": {
385+
disableRouteScaffold: false,
386+
displayName,
387+
helm: {
388+
chart: {
389+
git,
390+
path,
391+
sha
392+
}
393+
},
394+
k8sServicePort: 80
395+
}
396+
};
397+
398+
await reconcileHld(dependencies, bedrockYaml, "service", "./path/to/hld");
399+
expect(dependencies.createServiceComponent).toHaveBeenCalled();
400+
401+
// Second argument of first invocation of createServiceComponent is the service name
402+
expect(
403+
(dependencies.createServiceComponent as jest.Mock).mock.calls[0][2]
404+
).toBe(displayName);
405+
});
406+
407+
it("uses display name over the service path for creating service components", async () => {
408+
const displayName = "fabrikam";
409+
410+
bedrockYaml.services = {
411+
"/my/service/path": {
412+
disableRouteScaffold: false,
413+
displayName,
414+
helm: {
415+
chart: {
416+
git,
417+
path,
418+
sha
419+
}
420+
},
421+
k8sServicePort: 80
422+
}
423+
};
424+
425+
await reconcileHld(dependencies, bedrockYaml, "service", "./path/to/hld");
426+
expect(dependencies.createServiceComponent).toHaveBeenCalled();
427+
428+
// Second argument of first invocation of createServiceComponent is the service name
429+
expect(
430+
(dependencies.createServiceComponent as jest.Mock).mock.calls[0][2]
431+
).toBe(displayName);
432+
});
359433
});

src/commands/hld/reconcile.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,24 @@ export const reconcileHld = async (
151151
for (const [serviceRelPath, serviceConfig] of Object.entries(
152152
managedServices
153153
)) {
154-
const pathBase = path.basename(serviceRelPath);
155-
const serviceName = pathBase;
156-
logger.info(`Reconciling service: ${pathBase}`);
154+
const serviceName =
155+
serviceConfig.displayName || path.basename(serviceRelPath);
156+
157+
// No name, cannot generate proper routes and middlewares
158+
if (serviceName === "." || !serviceName) {
159+
logger.warn(
160+
"Service displayName not provided or service path is `.` - not reconciling service"
161+
);
162+
continue;
163+
}
164+
165+
logger.info(`Reconciling service: ${serviceName}`);
157166

158167
// Utilizes fab add, which is idempotent.
159168
await dependencies.createServiceComponent(
160169
dependencies.exec,
161170
absRepositoryInHldPath,
162-
pathBase
171+
serviceName
163172
);
164173

165174
// No rings
@@ -168,7 +177,7 @@ export const reconcileHld = async (
168177
}
169178

170179
// Create ring components.
171-
const svcPathInHld = path.join(absRepositoryInHldPath, pathBase);
180+
const svcPathInHld = path.join(absRepositoryInHldPath, serviceName);
172181

173182
// Will only loop over _existing_ rings in bedrock.yaml - does not cover the deletion case, ie: i remove a ring from bedrock.yaml
174183
for (const ring of Object.keys(managedRings)) {
@@ -326,12 +335,12 @@ export const createRepositoryComponent = async (
326335
export const createServiceComponent = async (
327336
execCmd: (commandToRun: string) => Promise<void>,
328337
absRepositoryInHldPath: string,
329-
pathBase: string
338+
serviceName: string
330339
) => {
331340
// Fab add is idempotent.
332341
// mkdir -p does not fail if ${pathBase} does not exist.
333342
await execCmd(
334-
`cd ${absRepositoryInHldPath} && mkdir -p ${pathBase} config && fab add ${pathBase} --path ./${pathBase} --method local --type component && touch ./config/common.yaml`
343+
`cd ${absRepositoryInHldPath} && mkdir -p ${serviceName} config && fab add ${serviceName} --path ./${serviceName} --method local --type component && touch ./config/common.yaml`
335344
);
336345
};
337346

0 commit comments

Comments
 (0)