Skip to content

Commit

Permalink
feat: add addWaitForPostgres and use in hasura component
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon committed Jul 28, 2020
1 parent 4481bfe commit f8181ff
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/azure-pg/index.ts
Expand Up @@ -12,7 +12,7 @@ import { createDbJob } from "./create-db.job";
//const { createDbJob } = createDb(params);
//const { createSecret: secret } = createSecret(params);

const getDefaultPgParams = () => {
export const getDefaultPgParams = () => {
ok(process.env.CI_PROJECT_NAME);
const sha = process.env.CI_COMMIT_SHORT_SHA;
const projectName = process.env.CI_PROJECT_NAME;
Expand All @@ -25,6 +25,7 @@ const getDefaultPgParams = () => {
user: `user_${sha}`,
};
};

//@ts-expect-error
export const create = ({ env, config }) => {
const defaultParams = getDefaultPgParams();
Expand Down
6 changes: 5 additions & 1 deletion src/components/hasura/index.ts
@@ -1,7 +1,9 @@
import { Environment } from "@kosko/env";
import { ok } from "assert";
import { Deployment } from "kubernetes-models/apps/v1/Deployment";

import { addPostgresUserSecret } from "../../utils/addPostgresUserSecret";
import { addWaitForPostgres } from "../../utils/addWaitForPostgres";
import { create as createApp } from "../app";

type CreateResult = unknown[];
Expand Down Expand Up @@ -58,8 +60,10 @@ export const create = (
const deployment = manifests.find(
//@ts-expect-error
(manifest) => manifest.kind === "Deployment"
);
) as Deployment;

addPostgresUserSecret(deployment);
addWaitForPostgres(deployment);

//
return manifests;
Expand Down
18 changes: 18 additions & 0 deletions src/utils/addWaitForPostgres.ts
@@ -0,0 +1,18 @@
import { Deployment } from "kubernetes-models/apps/v1/Deployment";

import { getDefaultPgParams } from "../components/azure-pg";
import { waitForPostgres } from "./waitForPostgres";

export const addWaitForPostgres = (deployment: Deployment): Deployment => {
const defaultParams = getDefaultPgParams();

const initContainer = waitForPostgres({
secretRefName: defaultParams.name,
});

if (deployment.spec && deployment.spec.template.spec) {
deployment.spec.template.spec.initContainers = [initContainer];
}

return deployment;
};
34 changes: 34 additions & 0 deletions src/utils/waitForPostgres.ts
@@ -0,0 +1,34 @@
/* eslint-disable sort-keys */
/* eslint-disable sort-keys-fix/sort-keys-fix */
import { IIoK8sApiCoreV1Container } from "kubernetes-models/_definitions/IoK8sApiCoreV1Container";

interface WaitForPostgresParams {
secretRefName: string;
}

export const waitForPostgres = ({
secretRefName = "azure-pg-user",
}: WaitForPostgresParams): IIoK8sApiCoreV1Container => {
return {
name: "wait-for-postgres",
image: `registry.gitlab.factory.social.gouv.fr/socialgouv/docker/wait_for_postgres:1.49.0`,
imagePullPolicy: "Always",
resources: {
requests: {
cpu: "5m",
memory: "16Mi",
},
limits: {
cpu: "20m",
memory: "32Mi",
},
},
envFrom: [
{
secretRef: {
name: secretRefName,
},
},
],
};
};
11 changes: 11 additions & 0 deletions templates/simple/components/hasura.ts
@@ -0,0 +1,11 @@
/* eslint-disable sort-keys */
/* eslint-disable sort-keys-fix/sort-keys-fix */
import env from "@kosko/env";
import { create } from "@socialgouv/kosko-charts/components/hasura";

const manifests = create({
env,
config: {},
});

export default manifests;

0 comments on commit f8181ff

Please sign in to comment.