Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/commands/hld/reconcile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,78 @@ describe("reconcile tests", () => {
expect(dependencies.createMiddlewareForRing).not.toHaveBeenCalled();
expect(dependencies.createIngressRouteForRing).not.toHaveBeenCalled();
});

it("does not create service components if the service path is `.`, and a display name does not exist", async () => {
bedrockYaml.services = {
".": {
disableRouteScaffold: false,
helm: {
chart: {
git,
path,
sha
}
},
k8sServicePort: 80
}
};

await reconcileHld(dependencies, bedrockYaml, "service", "./path/to/hld");

expect(dependencies.createServiceComponent).not.toHaveBeenCalled();
});

it("does create service components if the service path is `.` and a display name does exist", async () => {
const displayName = "fabrikam";

bedrockYaml.services = {
".": {
disableRouteScaffold: false,
displayName,
helm: {
chart: {
git,
path,
sha
}
},
k8sServicePort: 80
}
};

await reconcileHld(dependencies, bedrockYaml, "service", "./path/to/hld");
expect(dependencies.createServiceComponent).toHaveBeenCalled();

// Second argument of first invocation of createServiceComponent is the service name
expect(
(dependencies.createServiceComponent as jest.Mock).mock.calls[0][2]
).toBe(displayName);
});

it("uses display name over the service path for creating service components", async () => {
const displayName = "fabrikam";

bedrockYaml.services = {
"/my/service/path": {
disableRouteScaffold: false,
displayName,
helm: {
chart: {
git,
path,
sha
}
},
k8sServicePort: 80
}
};

await reconcileHld(dependencies, bedrockYaml, "service", "./path/to/hld");
expect(dependencies.createServiceComponent).toHaveBeenCalled();

// Second argument of first invocation of createServiceComponent is the service name
expect(
(dependencies.createServiceComponent as jest.Mock).mock.calls[0][2]
).toBe(displayName);
});
});
23 changes: 16 additions & 7 deletions src/commands/hld/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,24 @@ export const reconcileHld = async (
for (const [serviceRelPath, serviceConfig] of Object.entries(
managedServices
)) {
const pathBase = path.basename(serviceRelPath);
const serviceName = pathBase;
logger.info(`Reconciling service: ${pathBase}`);
const serviceName =
serviceConfig.displayName || path.basename(serviceRelPath);

// No name, cannot generate proper routes and middlewares
if (serviceName === "." || !serviceName) {
logger.warn(
"Service displayName not provided or service path is `.` - not reconciling service"
);
continue;
}

logger.info(`Reconciling service: ${serviceName}`);

// Utilizes fab add, which is idempotent.
await dependencies.createServiceComponent(
dependencies.exec,
absRepositoryInHldPath,
pathBase
serviceName
);

// No rings
Expand All @@ -168,7 +177,7 @@ export const reconcileHld = async (
}

// Create ring components.
const svcPathInHld = path.join(absRepositoryInHldPath, pathBase);
const svcPathInHld = path.join(absRepositoryInHldPath, serviceName);

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

Expand Down