-
Notifications
You must be signed in to change notification settings - Fork 267
/
nginx-kind.ts
82 lines (68 loc) · 2.76 KB
/
nginx-kind.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
/*
* 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 { KubernetesPluginContext } from "../config.js"
import { KubeApi } from "../api.js"
import { checkResourceStatus, waitForResources } from "../status/status.js"
import { apply, deleteResources } from "../kubectl.js"
import type { DeployState } from "../../../types/service.js"
import { kindNginxGetManifests } from "./nginx-kind-manifests.js"
import { GardenIngressComponent } from "./ingress-controller-base.js"
const nginxKindMainResource = {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "ingress-nginx-controller",
},
}
export class KindGardenIngressController extends GardenIngressComponent {
override async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await this.getStatus(ctx, log)
if (status === "ready") {
return
}
const provider = ctx.provider
const config = provider.config
const namespace = config.gardenSystemNamespace
const api = await KubeApi.factory(log, ctx, provider)
const manifests = kindNginxGetManifests(namespace)
log.info("Installing ingress controller for kind cluster")
await apply({ log, ctx, api, provider, manifests, namespace })
await waitForResources({
// setting the action name to providers is necessary to display the logs in provider-section
actionName: "providers",
namespace,
ctx,
provider,
resources: [nginxKindMainResource],
log,
timeoutSec: 60,
})
}
override async getStatus(ctx: KubernetesPluginContext, log: Log): Promise<DeployState> {
const provider = ctx.provider
const config = provider.config
const namespace = config.gardenSystemNamespace
const api = await KubeApi.factory(log, ctx, provider)
const deploymentStatus = await checkResourceStatus({ api, namespace, manifest: nginxKindMainResource, log })
log.debug(`Status of ingress controller: ${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
}
const provider = ctx.provider
const config = provider.config
const namespace = config.gardenSystemNamespace
const manifests = kindNginxGetManifests(namespace)
log.info("Uninstalling ingress controller for kind cluster")
await deleteResources({ log, ctx, provider, namespace, resources: manifests })
}
}