-
Notifications
You must be signed in to change notification settings - Fork 267
/
nginx-minikube.ts
84 lines (77 loc) · 2.86 KB
/
nginx-minikube.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
/*
* Copyright (C) 2018-2023 Garden Technologies, Inc. <info@garden.io>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import type { Log } from "../../../logger/log-entry.js"
import type { DeployState } from "../../../types/service.js"
import { exec } from "../../../util/util.js"
import type { KubernetesPluginContext } from "../config.js"
import { KubeApi } from "../api.js"
import { checkResourceStatus, waitForResources } from "../status/status.js"
import { GardenIngressComponent } from "./ingress-controller-base.js"
export class MinikubeGardenIngressController extends GardenIngressComponent {
override async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const provider = ctx.provider
const status = await this.getStatus(ctx, log)
if (status === "ready") {
return
}
log.info("Enabling minikube ingress controller addon")
await exec("minikube", ["addons", "enable", "ingress"])
await waitForResources({
// setting the action name to providers is necessary to display the logs in provider-section
actionName: "providers",
namespace: "ingress-nginx",
ctx,
provider,
resources: [nginxKindMainResource],
log,
timeoutSec: 60,
})
}
override async getStatus(ctx: KubernetesPluginContext, log: Log): Promise<DeployState> {
// The minikube addons don't implement healthchecks, so we have to check the status of the addon and the deployment
const provider = ctx.provider
const api = await KubeApi.factory(log, ctx, provider)
const result = await exec("minikube", ["addons", "list", "-o=json"])
const minikubeAddons = JSON.parse(result.stdout) as MinikubeAddons
const addonEnabled = minikubeAddons.ingress.Status === "enabled"
if (!addonEnabled) {
log.debug("Status of minikube ingress controller addon: missing")
return "missing"
}
//check if ingress controller deployment is ready
const deploymentStatus = await checkResourceStatus({
api,
namespace: "ingress-nginx",
manifest: nginxKindMainResource,
log,
})
log.debug(`Status of minikube ingress controller addon: ${deploymentStatus.state}`)
return deploymentStatus.state
}
override async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await this.getStatus(ctx, log)
if (status === "missing") {
return
}
log.info("Disabling minikube ingress controller addon")
await exec("minikube", ["addons", "disable", "ingress"])
}
}
interface MinikubeAddons {
[key: string]: {
Profile: string
Status: string
}
}
const nginxKindMainResource = {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "ingress-nginx-controller",
},
}