Skip to content

Commit

Permalink
feat: allow custom args for Mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzegorz Rajchman authored and mrliptontea committed Sep 9, 2022
1 parent 07c7ee1 commit a2fa174
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/mongo/mongo-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface MongoProps {
*/
readonly storageEngine?: "wiredTiger" | "inMemory" | "mmapv1";

/**
* Override the default arguments (storageEngine) to the container.
*/
readonly customArgs?: string[];

/**
* Storage for the mongo pod
* @default Quantity.fromString("20Gi")
Expand Down
22 changes: 16 additions & 6 deletions lib/mongo/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class Mongo extends Construct {
const app = props.selectorLabels?.app ?? chart.labels.app;
const release = props.release ?? "3.2.8";
const port = 27017;
const storageEngine = props.storageEngine ?? "mmapv1";
const labels = {
...chart.labels,
release: release,
Expand All @@ -44,11 +43,7 @@ export class Mongo extends Construct {
...selectorLabels,
};

const args = ["--storageEngine", storageEngine];

if (storageEngine === "mmapv1") {
args.push("--smallfiles");
}
const args = this.getCommandArgs(props);

this.service = new KubeService(this, id, {
metadata: {
Expand Down Expand Up @@ -150,4 +145,19 @@ export class Mongo extends Construct {
public getDnsName(replica = 0): string {
return `${this.statefulSet.name}-${replica}.${this.service.name}`;
}

private getCommandArgs(props: MongoProps): string[] {
if (props.customArgs) {
return props.customArgs;
}

const storageEngine = props.storageEngine ?? "mmapv1";
const args = ["--storageEngine", storageEngine];

if (storageEngine === "mmapv1") {
args.push("--smallfiles");
}

return args;
}
}
17 changes: 16 additions & 1 deletion test/mongo/mongo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("Mongo", () => {
instance: "test",
};

const allProps: Required<MongoProps> = {
const allProps: Required<Omit<MongoProps, "customArgs">> = {
...requiredProps,
selectorLabels,
storageEngine: "wiredTiger",
Expand Down Expand Up @@ -158,6 +158,21 @@ describe("Mongo", () => {
});
});

describe("customArgs", () => {
test("It accepts custom arg that override the default", () => {
const results = synthMongo({
...requiredProps,
customArgs: ["--smallfiles", "--quotaFiles", "8"],
});
const mongo = results.find((obj) => obj.kind === "StatefulSet");
expect(mongo).toHaveProperty("spec.template.spec.containers[0].args", [
"--smallfiles",
"--quotaFiles",
"8",
]);
});
});

describe("getDnsName", () => {
test("Builds a DNS name for the first Pod", () => {
const chart = makeChart();
Expand Down

0 comments on commit a2fa174

Please sign in to comment.