Created
May 4, 2019 16:50
-
-
Save gobengo/590a88e3b951fa3f66c8d8e963bf34a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as pulumi from "@pulumi/pulumi"; | |
import * as k8s from "@pulumi/kubernetes"; | |
let config = new pulumi.Config(); | |
const k8sNamespacePrefix = config.require('k8sNamespacePrefix') | |
// https://github.com/pulumi/pulumi-kubernetes/issues/217#issuecomment-459105809 | |
const addNamespaceTransformation = (namespaceName: string) => (o: any) => { | |
if (o !== undefined) { | |
if (o.metadata !== undefined) { | |
o.metadata.namespace = namespaceName; | |
} else { | |
o.metadata = {namespace: namespaceName} | |
} | |
} | |
} | |
export const storageClass = new k8s.storage.v1.StorageClass(`${k8sNamespacePrefix}-gp2-zone-a`, { | |
provisioner: "kubernetes.io/aws-ebs", | |
volumeBindingMode: "Immediate", | |
parameters: { | |
type: "gp2", | |
}, | |
allowedTopologies: [{ | |
matchLabelExpressions: [{ | |
key: "failure-domain.beta.kubernetes.io/zone", | |
values: [ | |
"us-west-2a", | |
], | |
}] | |
}] | |
}) | |
export const wordpresses: any[] = [] | |
const numNamespaces = 1 | |
for (const namespaceIndex of (new Array(numNamespaces).fill(0).map((_, index) => index))) { | |
const namespaceName = `${k8sNamespacePrefix}-wptest-${namespaceIndex}` | |
const namespace = new k8s.core.v1.Namespace(namespaceName, { | |
metadata: { | |
name: namespaceName | |
} | |
}) | |
const wordpressChart = new k8s.helm.v2.Chart(`${namespaceName}-wordpress`, { | |
namespace: pulumi.output(namespace).apply(namespace => namespace.metadata.name), | |
repo: "stable", | |
version: "5.9.0", | |
chart: "wordpress", | |
values: { | |
service: { | |
type: "ClusterIP", | |
}, | |
persistence: { | |
storageClass: pulumi.output(storageClass).apply(sc => sc.metadata.name), | |
}, | |
mariadb: { | |
master: { | |
persistence: { | |
storageClass: pulumi.output(storageClass).apply(sc => sc.metadata.name), | |
} | |
} | |
} | |
}, | |
transformations: [ | |
addNamespaceTransformation(namespaceName), | |
removePodsWithHooksTransformation() | |
] | |
}); | |
wordpresses.push({ namespace, chart: wordpressChart }) | |
} | |
function removePodsWithHooksTransformation() { | |
return (o: any) => { | |
if ( ! o) return | |
if (o.metadata && o.metadata.annotations && o.metadata.annotations['helm.sh/hook']) { | |
console.log('skipping helm hook', o.metadata) | |
// transforms in nodejs expects you to mutate input object, not return a new one :/ | |
// https://github.com/pulumi/pulumi-kubernetes/blob/4b01b5114df3045cecefd2ff3e2f2ed64430e3dd/sdk/nodejs/yaml/yaml.ts#L2214 | |
for (const key in o) { | |
delete o[key] | |
} | |
Object.assign(o, { | |
kind: "List", | |
apiVersion: "v1", | |
metadata: {}, | |
items: [], | |
}) | |
return | |
} | |
return o | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment