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
Show all changes
27 commits
Select commit Hold shift + click to select a range
b4a5c8f
bedrock.yaml refactor & service create spec update
evanlouie Mar 30, 2020
919f23a
bedrock.yaml refactor & service create spec update
evanlouie Mar 30, 2020
8a0bcf6
First pass to get display name for service from bedrock.yaml
samiyaakhtar Apr 3, 2020
9f9a26f
Adding basic unit tests
samiyaakhtar Apr 3, 2020
ab72e09
Merge branch 'master' into 1117-bedrock-svc-refactor
samiyaakhtar Apr 3, 2020
f32f58c
Fixing generated yaml file
samiyaakhtar Apr 4, 2020
a39d0ca
Merge branch '1117-bedrock-svc-refactor' of https://github.com/Cataly…
samiyaakhtar Apr 6, 2020
1376a50
Merge branch '1117-bedrock-svc-refactor' into 1173
samiyaakhtar Apr 6, 2020
7238fb8
Removing the changes that will come after spk release is ready
samiyaakhtar Apr 6, 2020
2db61ce
Updating files
samiyaakhtar Apr 6, 2020
cc66c52
Mering from master
samiyaakhtar Apr 7, 2020
7b8346c
Command should be run from bedrock/yaml directory and move under
samiyaakhtar Apr 7, 2020
2a65a57
Minor changes
samiyaakhtar Apr 7, 2020
64e4bcc
Use error chain
samiyaakhtar Apr 7, 2020
0a95bff
Merge branch 'master' into 1173_1
samiyaakhtar Apr 7, 2020
c319ce7
More feedback
samiyaakhtar Apr 7, 2020
94c1430
Merge branch 'master' into 1173_1
samiyaakhtar Apr 7, 2020
5792cd3
Improve doc
samiyaakhtar Apr 7, 2020
1295d4b
Merge branch 'master' into 1173_1
samiyaakhtar Apr 7, 2020
2b6eb45
Improve unit test
samiyaakhtar Apr 7, 2020
9f0caf0
Merge branch 'master' into 1173_1
samiyaakhtar Apr 8, 2020
4881044
Merge branch 'master' into 1173_1
samiyaakhtar Apr 8, 2020
253ae29
Separated out negative tests
samiyaakhtar Apr 8, 2020
445024e
Merge branch 'master' into 1173_1
samiyaakhtar Apr 8, 2020
5c3d1de
Merge branch 'master' into 1173_1
yradsmikham Apr 8, 2020
919e59d
Merge branch 'master' into 1173_1
samiyaakhtar Apr 8, 2020
b780411
Merge branch 'master' into 1173_1
samiyaakhtar Apr 9, 2020
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
13 changes: 13 additions & 0 deletions docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,19 @@
],
"markdown": "## Description\n\nAdd a new service into this initialized spk project repository.\n\n## Example\n\n```bash\nspk service create my-service . \\\n --display-name $app_name \\\n --helm-config-path $path_to_chart_in_repo \\\n --helm-config-git $helm_repo_url \\ # Needs to start with https and not contain user name\n --helm-config-branch master \\\n --helm-chart-access-token-variable $ENV_VAR_NAME\n```\n\n## Note\n\n- `--helm-chart-*` and `--helm-config-*` settings are mutually-exclusive. **You\n may only use one.**\n - If the git repository referenced in `--helm-config-git` is a private\n repository, you can specify an environment variable in your\n HLD-to-Materialized pipeline containing your a PAT to authenticate with via\n the `--helm-chart-access-token-variable` option.\n- `--middlewares`, `--k8s-backend-port`, `--path-prefix`,\n `--path-prefix-major-version`, and `--k8s-backend` are all used to configure\n the generated Traefik2 IngressRoutes. i.e.\n\n ```sh\n spk service create my-example-documents-service path/to/my/service \\\n --middlewares middleware \\\n --k8s-backend-port 3001 \\\n --k8s-backend docs-service \\\n --path-prefix documents \\\n --path-prefix-major-version v2\n ```\n\n will result in an IngressRoute that looks like:\n\n ```yaml\n apiVersion: traefik.containo.us/v1alpha1\n kind: IngressRoute\n metadata:\n name: my-example-documents-service-master\n spec:\n routes:\n - kind: Rule\n match: \"PathPrefix(`/v2/documents`) && Headers(`Ring`, `master`)\"\n middlewares:\n - name: my-example-documents-service-master\n - name: middlewareA\n services:\n - name: docs-service\n port: 3001\n ```\n"
},
"service get-display-name": {
"command": "get-display-name",
"alias": "gdn",
"description": "Gets display name for a service",
"options": [
{
"arg": "-p, --path <path>",
"description": "Path to the service folder for which display name is to be extracted",
"required": true
}
],
"markdown": "## Description\n\nGets display name of a service based on the provided path by extracting this\ninformation from bedrock.yaml. This command tries to locate bedrock.yaml in the\ncurrent directory.\n\nIf bedrock.yaml is not found in current directory, the command will fail to\nextract display name.\n\nIf the specified path is not found in any services listed in bedrock.yaml, the\ndisplay name will not be extracted. Make sure that specified path matches the\npath in bedrock.yaml exactly.\n"
},
"service install-build-pipeline": {
"command": "install-build-pipeline <service-name>",
"alias": "p",
Expand Down
12 changes: 12 additions & 0 deletions src/commands/service/get-display-name.decorator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"command": "get-display-name",
"alias": "gdn",
"description": "Gets display name for a service",
"options": [
{
"arg": "-p, --path <path>",
"description": "Path to the service folder for which display name is to be extracted",
"required": true
}
]
}
12 changes: 12 additions & 0 deletions src/commands/service/get-display-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Description

Gets display name of a service based on the provided path by extracting this
information from bedrock.yaml. This command tries to locate bedrock.yaml in the
current directory.

If bedrock.yaml is not found in current directory, the command will fail to
extract display name.

If the specified path is not found in any services listed in bedrock.yaml, the
display name will not be extracted. Make sure that specified path matches the
path in bedrock.yaml exactly.
47 changes: 47 additions & 0 deletions src/commands/service/get-display-name.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { disableVerboseLogging, enableVerboseLogging } from "../../logger";
import { execute } from "./get-display-name";
import * as fs from "fs";
import { createTestBedrockYaml } from "../../test/mockFactory";
import { BedrockFile } from "../../types";
import * as bedrockYaml from "../../lib/bedrockYaml";

beforeAll(() => {
enableVerboseLogging();
});

afterAll(() => {
disableVerboseLogging();
});

describe("get display name", () => {
it("positive test", async () => {
Comment thread
mtarng marked this conversation as resolved.
const exitFn = jest.fn();
const defaultBedrockFileObject = createTestBedrockYaml(
false
) as BedrockFile;
jest.spyOn(fs, "existsSync").mockReturnValue(true);
jest.spyOn(bedrockYaml, "read").mockReturnValue(defaultBedrockFileObject);
jest.spyOn(process, "cwd").mockReturnValue("bedrock.yaml/");
const consoleSpy = jest.spyOn(console, "log");
execute({ path: "./packages/service1" }, exitFn);
expect(consoleSpy).toHaveBeenCalledWith("service1");
expect(exitFn).toBeCalledTimes(1);
expect(exitFn).toBeCalledWith(0);
});
it("negative test", async () => {
const exitFn = jest.fn();
execute({ path: "" }, exitFn);
expect(exitFn).toBeCalledTimes(1);
execute({ path: undefined }, exitFn);
expect(exitFn).toBeCalledWith(1);
const defaultBedrockFileObject = createTestBedrockYaml(
false
) as BedrockFile;
jest.spyOn(fs, "existsSync").mockReturnValue(true);
jest.spyOn(bedrockYaml, "read").mockReturnValue(defaultBedrockFileObject);
jest.spyOn(process, "cwd").mockReturnValue("bedrock.yaml/");
execute({ path: "./packages/service" }, exitFn); // should not exist
expect(exitFn).toBeCalledTimes(3);
expect(exitFn).toBeCalledWith(1);
});
});
75 changes: 75 additions & 0 deletions src/commands/service/get-display-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import commander from "commander";
import { read as readBedrockYaml } from "../../lib/bedrockYaml";
import { build as buildCmd, exit as exitCmd } from "../../lib/commandBuilder";
import { logger } from "../../logger";
import decorator from "./get-display-name.decorator.json";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";

export interface CommandOptions {
path: string | undefined;
}

/**
* Executes the command, can all exit function with 0 or 1
* when command completed successfully or failed respectively.
*
* @param opts validated option values
* @param exitFn exit function
*/
export const execute = async (
opts: CommandOptions,
exitFn: (status: number) => Promise<void>
): Promise<void> => {
// The assumption is that this command should be ran from the directory where bedrock.yaml exists
try {
if (!opts.path) {
throw buildError(
errorStatusCode.VALIDATION_ERR,
"service-get-display-name-path-missing-param-err"
);
}
const bedrockFile = readBedrockYaml(process.cwd());
Comment thread
samiyaakhtar marked this conversation as resolved.
if (!bedrockFile) {
throw buildError(
errorStatusCode.FILE_IO_ERR,
"service-get-display-name-bedrock-yaml-missing-err"
);
}

const serviceIndex = Object.keys(bedrockFile.services).find(
(index) => opts.path === bedrockFile.services[+index].path
);

if (serviceIndex) {
console.log(bedrockFile.services[+serviceIndex].displayName);
Comment thread
mtarng marked this conversation as resolved.
await exitFn(0);
}

throw buildError(errorStatusCode.ENV_SETTING_ERR, {
errorKey: "service-get-display-name-err",
values: [opts.path],
});
} catch (err) {
logError(
buildError(
errorStatusCode.VALIDATION_ERR,
"service-get-display-name-generic-err",
err
)
);
await exitFn(1);
}
};

/**
* Adds the get-display-name command to the commander command object
* @param command Commander command object to decorate
*/
export const commandDecorator = (command: commander.Command): void => {
buildCmd(command, decorator).action(async (opts: CommandOptions) => {
await execute(opts, async (status: number) => {
await exitCmd(logger, process.exit, status);
});
});
};
7 changes: 6 additions & 1 deletion src/commands/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Command } from "../command";

const subfolders = ["create", "create-revision", "pipeline"];
const subfolders = [
"create",
"create-revision",
"pipeline",
"get-display-name",
];

export const commandDecorator = Command(
"service",
Expand Down
4 changes: 4 additions & 0 deletions src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
"introspect-dashboard-cmd-launch-pre-req-err": "Requirements to launch dashboard were not met.",
"introspect-dashboard-cmd-launch-err": "Could not launch dashboard docker container.",

"service-get-display-name-path-missing-param-err": "Value for path parameter was missing. This is required for running get-display-command. Provide it.",
"service-get-display-name-bedrock-yaml-missing-err": "Could not find bedrock.yaml in current directory. Make sure to run this from a directory that contains bedrock.yaml.",
"service-get-display-name-err": "Could not find a service for path {0}. Make sure that the specified path is valid.",
"service-get-display-name-generic-err": "Error occurred while getting display name.",
"az-cli-login-err": "Could not login through azure cli.",
"az-cli-create-sp-err": "Could not create service principal with azure cli",

Expand Down
3 changes: 3 additions & 0 deletions src/test/mockFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,19 @@ export const createTestBedrockYaml = (
path: "./",
helm: service1HelmConfig,
k8sBackendPort: 80,
displayName: "root",
},
{
path: "./packages/service1",
helm: service2HelmConfig,
k8sBackendPort: 80,
displayName: "service1",
},
{
path: "./zookeeper",
helm: zookeeperHelmConfig,
k8sBackendPort: 80,
displayName: "zookeeper",
},
],
variableGroups: [],
Expand Down