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
51 changes: 45 additions & 6 deletions src/commands/hld/reconcile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -365,11 +365,44 @@ 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 with the k8s service being configured from the config", async () => {
await configureChartForRing(
exec,
ringPath,
ringName,
serviceConfig,
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,
};

it("should invoke the correct command for configuring a chart for a ring", async () => {
await configureChartForRing(exec, ringPath, ringName, serviceConfig);
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);
Expand All @@ -381,7 +414,13 @@ describe("configureChartForRing", () => {
.mockImplementation(async () => Promise.reject(new Error()));

await expect(
configureChartForRing(exec, ringPath, ringName, serviceConfig)
configureChartForRing(
exec,
ringPath,
ringName,
serviceConfig,
normalizedServiceName
)
).rejects.toThrow();
});
});
Expand Down
10 changes: 7 additions & 3 deletions src/commands/hld/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ export const reconcileHld = async (
dependencies.exec,
normalizedRingPathInHld,
normalizedRingName,
serviceConfig
serviceConfig,
normalizedSvcName
);

// Service explicitly requests no ingress-routes to be generated.
Expand Down Expand Up @@ -588,10 +589,13 @@ export const configureChartForRing = async (
execCmd: (commandToRun: string) => Promise<ExecResult>,
normalizedRingPathInHld: string,
normalizedRingName: string,
serviceConfig: BedrockServiceConfig
serviceConfig: BedrockServiceConfig,
normalizedServiceName: string
): Promise<ExecResult> => {
// 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,
Expand Down