-
Notifications
You must be signed in to change notification settings - Fork 267
/
nginx-microk8s.ts
64 lines (59 loc) · 2.43 KB
/
nginx-microk8s.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
/*
* 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 { exec } from "../../../util/util.js"
import type { KubernetesPluginContext } from "../config.js"
import { type DeployState } from "../../../types/service.js"
import { configureMicrok8sAddons } from "../local/microk8s.js"
import { waitForResources } from "../status/status.js"
import { GardenIngressComponent } from "./ingress-controller-base.js"
export class Microk8sGardenIngressController 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 microk8s ingress controller addon")
await configureMicrok8sAddons(log, ["ingress"])
const nginxMainResource = {
apiVersion: "apps/v1",
kind: "DaemonSet",
metadata: {
name: "nginx-ingress-microk8s-controller",
},
}
await waitForResources({
// setting the action name to providers is necessary to display the logs in provider-section
actionName: "providers",
namespace: "ingress",
ctx,
provider,
resources: [nginxMainResource],
log,
timeoutSec: 60,
})
}
override async getStatus(_ctx: KubernetesPluginContext, log: Log): Promise<DeployState> {
// The microk8s addons implement healthchecks and auto-corrects the addon status
// in case the deployment becomes unhealthy so we can just check if the addon is enabled
const statusCommandResult = await exec("microk8s", ["status", "--format", "short"])
const status = statusCommandResult.stdout
const addonEnabled = status.includes("core/ingress: enabled")
log.debug(`Status of microk8s ingress controller addon: ${addonEnabled ? "enabled" : "disabled"}`)
return addonEnabled ? "ready" : "missing"
}
override async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await this.getStatus(ctx, log)
if (status === "missing") {
return
}
log.info("Disabling microk8s ingress controller addon")
await exec("microk8s", ["disable", "ingress"])
}
}