-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
90 lines (81 loc) · 3.18 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as pulumi from "@pulumi/pulumi";
import * as kubernetes from "@pulumi/kubernetes";
import {Secret} from "@pulumi/kubernetes/core/v1";
import {CustomResource} from "@pulumi/kubernetes/apiextensions";
import {createStackL1Prod} from "./stacks/prod/l1";
import {createStackL2Prod} from "./stacks/prod/l2";
import {createStackL1Dev} from "./stacks/dev/l1";
import {createStackL2Dev} from "./stacks/dev/l2";
import {throws} from "node:assert";
const stack = pulumi.getStack()
const defaultCRDVersion = "v1.16.0";
const defaultOperatorVersion = "v1.16.0";
const image = stack === "hetzner" ? "pulumi/pulumi-kubernetes-operator:v2.0.0-beta.3" : "pulumi/pulumi-kubernetes-operator:v1.16.0"
const config = new pulumi.Config();
const deployNamespace = config.get("namespace") || 'default';
const deployNamespaceList = config.getObject<string[]>("namespaces") || [deployNamespace];
const crdVersion = config.get("crd-version") || defaultCRDVersion;
const operatorVersion = config.get("operator-version") || defaultOperatorVersion;
// Get the Pulumi API token.
const pulumiAccessToken = config.requireSecret("pulumiAccessToken")
const tagL1 = process.env.versionTag
const tagL2 = process.env.versionTag
if (stack == "hetzner" && (tagL1 == undefined || tagL2 == undefined))
throw Error("tag not set")
const stackCRD = new kubernetes.yaml.ConfigFile("stackcrd", {
file: `https://raw.githubusercontent.com/pulumi/pulumi-kubernetes-operator/${crdVersion}/deploy/crds/pulumi.com_stacks.yaml`
});
const programCRD = new kubernetes.yaml.ConfigFile("programcrd", {
file: `https://raw.githubusercontent.com/pulumi/pulumi-kubernetes-operator/${crdVersion}/deploy/crds/pulumi.com_programs.yaml`
});
const deploymentOptions = {dependsOn: [stackCRD, programCRD]};
const operatorClusterRole = new kubernetes.rbac.v1.ClusterRole(`operator-cluster-role`, {
rules: [
{
apiGroups: ["*"],
resources: ["*"],
verbs: ["*"],
},
// Add other rules as needed
],
});
const ns = deployNamespaceList[0]
const operatorServiceAccount = new kubernetes.core.v1.ServiceAccount(`operator-service-account-${ns}`, {
metadata: {
"namespace": ns,
},
});
// Bind the ClusterRole to the service account
const operatorClusterRoleBinding = new kubernetes.rbac.v1.ClusterRoleBinding(`operator-cluster-role-binding`, {
metadata: {
name: `operator-cluster-role-binding`,
},
subjects: [{
kind: "ServiceAccount",
name: operatorServiceAccount.metadata.name,
namespace: ns, // Specify the namespace of the ServiceAccount
}],
roleRef: {
kind: "ClusterRole",
name: operatorClusterRole.metadata.name,
apiGroup: "rbac.authorization.k8s.io",
},
});
// Create the API token as a Kubernetes Secret.
const accessToken = new Secret("operator-accesstoken", {
metadata: {
name: "pulumi-operator-secret",
namespace: ns
},
stringData: {accessToken: pulumiAccessToken},
});
// Create an NGINX deployment in-cluster.
if (stack == "hetzner") {
createStackL1Prod(ns, accessToken,tagL1)
createStackL2Prod(ns, accessToken, tagL2)
} else if (stack == "openstack") {
createStackL1Dev(ns, accessToken)
createStackL2Dev(ns, accessToken)
} else {
throw Error(`Wrong stack, no definition for stack ${stack}`)
}