forked from pulumi/pulumi-kubernetes-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
52 lines (44 loc) · 1.65 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
// Copyright 2021, Pulumi Corporation. All rights reserved.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import * as kx from "@pulumi/kubernetesx";
import * as operator from "./operator";
// By default, uses $HOME/.kube/config when no kubeconfig is set.
const provider = new k8s.Provider("k8s");
// Create the Pulumi Kubernetes Operator.
// Uses a custom ComponentResource class based on Typescript code in https://git.io/JJ6yj
const name = "pulumi-k8s-operator"
const pulumiOperator = new operator.PulumiKubernetesOperator(name, {
namespace: "default",
provider,
});
// Get the Pulumi API token.
const config = new pulumi.Config();
const pulumiAccessToken = config.requireSecret("pulumiAccessToken");
const stackName = config.require("stackName");
const stackProjectRepo = config.require("stackProjectRepo");
const stackCommit = config.require("stackCommit");
// Create the API token as a Kubernetes Secret.
const apiAccessToken = new kx.Secret("accesstoken", {
stringData: { accessToken: pulumiAccessToken},
});
// Create a Blue/Green app deployment in-cluster.
const appStack = new k8s.apiextensions.CustomResource("app-stack", {
apiVersion: 'pulumi.com/v1',
kind: 'Stack',
spec: {
envRefs: {
PULUMI_ACCESS_TOKEN: {
type: "Secret",
secret: {
name: apiAccessToken.metadata.name,
key: "accessToken",
},
},
},
stack: stackName,
projectRepo: stackProjectRepo,
commit: stackCommit,
destroyOnFinalize: true,
}
}, {dependsOn: pulumiOperator.deployment});