|
1 | 1 | // Copyright 2016-2019, Pulumi Corporation. All rights reserved.
|
2 |
| - |
| 2 | +import * as command from "@pulumi/command"; |
| 3 | +import * as k8s from "@pulumi/kubernetes"; |
3 | 4 | import * as pulumi from "@pulumi/pulumi";
|
4 | 5 | import * as jenkins from "./jenkins";
|
5 | 6 |
|
6 | 7 | // Minikube does not implement services of type `LoadBalancer`; require the user to specify if we're
|
7 | 8 | // running on minikube, and if so, create only services of type ClusterIP.
|
8 | 9 | const config = new pulumi.Config();
|
| 10 | +let metalLB: command.local.Command | undefined = undefined; |
| 11 | +let checkMetalLB: command.local.Command | undefined = undefined; |
| 12 | +let metalLBConfig: k8s.core.v1.ConfigMap | undefined = undefined; |
| 13 | + |
9 | 14 | if (config.require("isMinikube") === "true") {
|
10 |
| - throw new Error("This example does not yet support minikube"); |
11 |
| -} |
| 15 | + if (config.require("enableMetalLB") === "true") { |
| 16 | + // Enable MetalLB in Minikube with wait |
| 17 | + metalLB = new command.local.Command("MetalLB", { |
| 18 | + create: `minikube addons enable metallb && minikube addons list | grep metallb | grep -q enabled`, |
| 19 | + delete: `minikube addons disable metallb`, |
| 20 | + }, { |
| 21 | + deleteBeforeReplace: true, |
| 22 | + }); |
| 23 | + } |
| 24 | + checkMetalLB = new command.local.Command("MetalLB", { |
| 25 | + create: `minikube addons list --output json`, |
| 26 | + }, { deleteBeforeReplace: true, dependsOn: metalLB ? [metalLB] : [] }); |
| 27 | + pulumi.jsonParse(checkMetalLB.stdout).apply(json => { |
| 28 | + if (json["metallb"]["Status"] !== "enabled") { |
| 29 | + throw new Error("This example requires MetalLB to be enabled in minikube, you can enable it by running `minikube addons enable metallb`"); |
| 30 | + } |
| 31 | + }); |
12 | 32 |
|
13 |
| -const instance = new jenkins.Instance({ |
14 |
| - name: pulumi.getStack(), |
15 |
| - credentials: { |
16 |
| - username: config.require("username"), |
17 |
| - password: config.require("password"), |
| 33 | + metalLBConfig = new k8s.core.v1.ConfigMap("metallbConfig", { |
| 34 | + metadata: { |
| 35 | + namespace: "metallb-system", |
| 36 | + name: "config", |
| 37 | + annotations: { |
| 38 | + "pulumi.com/patchForce": "true", |
| 39 | + }, |
18 | 40 | },
|
19 |
| - resources: { |
20 |
| - memory: "512Mi", |
21 |
| - cpu: "100m", |
| 41 | + data: { |
| 42 | + config: ` |
| 43 | + address-pools: |
| 44 | + - name: default |
| 45 | + protocol: layer2 |
| 46 | + addresses: |
| 47 | + - 192.168.49.240-192.168.49.250 |
| 48 | + `, |
22 | 49 | },
|
23 |
| -}); |
| 50 | + }, { deleteBeforeReplace: true, dependsOn: [checkMetalLB] }); |
| 51 | +} |
| 52 | + |
| 53 | +const instance = new jenkins.Instance({ |
| 54 | + name: pulumi.getStack(), |
| 55 | + credentials: { |
| 56 | + username: config.require("username"), |
| 57 | + password: config.require("password"), |
| 58 | + }, |
| 59 | + resources: { |
| 60 | + memory: "512Mi", |
| 61 | + cpu: "100m", |
| 62 | + }, |
| 63 | +}, { dependsOn: metalLBConfig ? [metalLBConfig] : [] }); |
| 64 | + |
24 | 65 | export const externalIp = instance.externalIp;
|
0 commit comments