Skip to content

Commit

Permalink
refactor: (7) introduce abstract method
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Nov 8, 2023
1 parent f0d8232 commit 3ec92d2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
7 changes: 6 additions & 1 deletion core/src/plugins/kubernetes/nginx/ingress-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ import { Microk8sGardenIngressController } from "./nginx-microk8s.js"
import { MinikubeGardenIngressController } from "./nginx-minikube.js"
import { KindGardenIngressController } from "./nginx-kind.js"
import { EphemeralHelmGardenIngressController } from "./nginx-helm-ephemeral.js"
import type { DeployState } from "../../../types/service.js"

export abstract class GardenIngressController {
abstract install(ctx: KubernetesPluginContext, log: Log): Promise<void>

abstract uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void>

abstract ready(ctx: KubernetesPluginContext, log: Log): Promise<boolean>
async ready(ctx: KubernetesPluginContext, log: Log): Promise<boolean> {
return (await this.getStatus(ctx, log)) === "ready"
}

abstract getStatus(ctx: KubernetesPluginContext, log: Log): Promise<DeployState>
}

export function getGardenIngressController(ctx: KubernetesPluginContext): GardenIngressController | undefined {
Expand Down
8 changes: 4 additions & 4 deletions core/src/plugins/kubernetes/nginx/nginx-kind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const nginxKindMainResource = {

export class KindGardenIngressController extends GardenIngressController {
override async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await kindNginxStatus(ctx, log)
const status = await this.getStatus(ctx, log)
if (status === "ready") {
return
}
Expand All @@ -53,12 +53,12 @@ export class KindGardenIngressController extends GardenIngressController {
})
}

override async ready(ctx: KubernetesPluginContext, log: Log): Promise<boolean> {
return (await kindNginxStatus(ctx, log)) === "ready"
override async getStatus(ctx: KubernetesPluginContext, log: Log): Promise<DeployState> {
return await kindNginxStatus(ctx, log)
}

override async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await kindNginxStatus(ctx, log)
const status = await this.getStatus(ctx, log)
if (status === "missing") {
return
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/plugins/kubernetes/nginx/nginx-microk8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Microk8sGardenIngressController extends GardenIngressController {
override async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const provider = ctx.provider

const status = await microk8sNginxStatus(log)
const status = await this.getStatus(ctx, log)
if (status === "ready") {
return
}
Expand All @@ -44,12 +44,12 @@ export class Microk8sGardenIngressController extends GardenIngressController {
})
}

override async ready(_ctx: KubernetesPluginContext, log: Log): Promise<boolean> {
return (await microk8sNginxStatus(log)) === "ready"
override async getStatus(_ctx: KubernetesPluginContext, log: Log): Promise<DeployState> {
return await microk8sNginxStatus(log)
}

override async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await microk8sNginxStatus(log)
const status = await this.getStatus(ctx, log)
if (status === "missing") {
return
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/plugins/kubernetes/nginx/nginx-minikube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GardenIngressController } from "./ingress-controller.js"
export class MinikubeGardenIngressController extends GardenIngressController {
override async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const provider = ctx.provider
const status = await minikubeNginxStatus(ctx, log)
const status = await this.getStatus(ctx, log)
if (status === "ready") {
return
}
Expand All @@ -36,12 +36,12 @@ export class MinikubeGardenIngressController extends GardenIngressController {
})
}

override async ready(ctx: KubernetesPluginContext, log: Log): Promise<boolean> {
return (await minikubeNginxStatus(ctx, log)) === "ready"
override async getStatus(ctx: KubernetesPluginContext, log: Log): Promise<DeployState> {
return await minikubeNginxStatus(ctx, log)
}

override async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await minikubeNginxStatus(ctx, log)
const status = await this.getStatus(ctx, log)
if (status === "missing") {
return
}
Expand Down

0 comments on commit 3ec92d2

Please sign in to comment.