feat: organize all services into separate stacks by dependency
This commit is contained in:
42
k8s-operators/barman.ts
Normal file
42
k8s-operators/barman.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { Construct } from "constructs";
|
||||
import { NullProvider } from "@cdktf/provider-null/lib/provider";
|
||||
import { Resource } from "@cdktf/provider-null/lib/resource";
|
||||
|
||||
export interface BarmanCloudPluginInstallOptions {
|
||||
/** URL to the CloudNativePG barman-cloud plugin manifest */
|
||||
url: string;
|
||||
}
|
||||
|
||||
export class BarmanCloudPluginInstall extends Construct {
|
||||
constructor(
|
||||
scope: Construct,
|
||||
id: string,
|
||||
opts: BarmanCloudPluginInstallOptions,
|
||||
) {
|
||||
super(scope, id);
|
||||
|
||||
const { url } = opts;
|
||||
|
||||
const applyCmd = ["kubectl", "apply", "-f", url].join(" ");
|
||||
const deleteCmd = ["kubectl", "delete", "-f", url].join(" ");
|
||||
|
||||
new Resource(this, "barman-install", {
|
||||
provider: new NullProvider(this, "barman"),
|
||||
provisioners: [
|
||||
{
|
||||
type: "local-exec",
|
||||
when: "create",
|
||||
command: applyCmd,
|
||||
},
|
||||
{
|
||||
type: "local-exec",
|
||||
when: "destroy",
|
||||
command: deleteCmd,
|
||||
},
|
||||
],
|
||||
triggers: {
|
||||
url,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
72
k8s-operators/index.ts
Normal file
72
k8s-operators/index.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import { HelmProvider } from "@cdktf/provider-helm/lib/provider";
|
||||
import { Release } from "@cdktf/provider-helm/lib/release";
|
||||
import { TerraformStack } from "cdktf";
|
||||
import { Construct } from "constructs";
|
||||
import { BarmanCloudPluginInstall } from "./barman";
|
||||
import { Prometheus } from "./prometheus";
|
||||
|
||||
export class K8SOperators extends TerraformStack {
|
||||
constructor(scope: Construct, id: string) {
|
||||
super(scope, id);
|
||||
|
||||
const helm = new HelmProvider(this, "helm", {
|
||||
kubernetes: {
|
||||
configPath: "~/.kube/config",
|
||||
},
|
||||
});
|
||||
|
||||
new Prometheus(this, "prometheus", {
|
||||
provider: helm,
|
||||
namespace: "monitoring",
|
||||
name: "prometheus-operator",
|
||||
version: "75.10.0",
|
||||
});
|
||||
|
||||
new Release(this, "onepassword-operator", {
|
||||
provider: helm,
|
||||
name: "onepassword-operator",
|
||||
chart: "connect",
|
||||
repository: "https://1password.github.io/connect-helm-charts/",
|
||||
namespace: "1password",
|
||||
createNamespace: true,
|
||||
set: [
|
||||
{
|
||||
name: "operator.create",
|
||||
value: "true",
|
||||
},
|
||||
],
|
||||
setSensitive: [
|
||||
{
|
||||
name: "operator.token.value",
|
||||
value: process.env.OP_CONNECT_TOKEN!,
|
||||
},
|
||||
{
|
||||
name: "connect.credentials_base64",
|
||||
value: btoa(
|
||||
fs.readFileSync(
|
||||
path.join(__dirname, "1password-credentials.json"),
|
||||
"utf-8",
|
||||
),
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const cnpg = new Release(this, "cnpg-operator", {
|
||||
provider: helm,
|
||||
repository: "https://cloudnative-pg.github.io/charts",
|
||||
chart: "cloudnative-pg",
|
||||
name: "postgres-system",
|
||||
namespace: "cnpg-system",
|
||||
createNamespace: true,
|
||||
});
|
||||
|
||||
const barman = new BarmanCloudPluginInstall(this, "barman-cloud-plugin", {
|
||||
url: "https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v0.9.0/manifest.yaml",
|
||||
});
|
||||
|
||||
barman.node.addDependency(cnpg);
|
||||
}
|
||||
}
|
||||
29
k8s-operators/prometheus/index.ts
Normal file
29
k8s-operators/prometheus/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import * as fs from "fs";
|
||||
import { HelmProvider } from "@cdktf/provider-helm/lib/provider";
|
||||
import { Release } from "@cdktf/provider-helm/lib/release";
|
||||
import { Construct } from "constructs";
|
||||
|
||||
type PrometheusOptions = {
|
||||
provider: HelmProvider;
|
||||
name: string;
|
||||
namespace: string;
|
||||
version: string;
|
||||
};
|
||||
|
||||
export class Prometheus extends Construct {
|
||||
constructor(scope: Construct, id: string, options: PrometheusOptions) {
|
||||
super(scope, id);
|
||||
|
||||
new Release(this, id, {
|
||||
...options,
|
||||
repository: "https://prometheus-community.github.io/helm-charts",
|
||||
chart: "kube-prometheus-stack",
|
||||
createNamespace: true,
|
||||
values: [
|
||||
fs.readFileSync("helm/values/prometheus.values.yaml", {
|
||||
encoding: "utf8",
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user