Skip to content

Commit

Permalink
refactor: (6) convert interface to abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Nov 8, 2023
1 parent b37ca44 commit f0d8232
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
10 changes: 6 additions & 4 deletions core/src/plugins/kubernetes/nginx/ingress-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import { MinikubeGardenIngressController } from "./nginx-minikube.js"
import { KindGardenIngressController } from "./nginx-kind.js"
import { EphemeralHelmGardenIngressController } from "./nginx-helm-ephemeral.js"

export interface GardenIngressController {
install: (ctx: KubernetesPluginContext, log: Log) => Promise<void>
uninstall: (ctx: KubernetesPluginContext, log: Log) => Promise<void>
ready: (ctx: KubernetesPluginContext, log: Log) => Promise<boolean>
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>
}

export function getGardenIngressController(ctx: KubernetesPluginContext): GardenIngressController | undefined {
Expand Down
8 changes: 4 additions & 4 deletions core/src/plugins/kubernetes/nginx/nginx-helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ const HELM_INGRESS_NGINX_DEPLOYMENT_TIMEOUT = "300s"

type _HelmValue = number | string | boolean | object | null | undefined

export abstract class HelmGardenIngressController implements GardenIngressController {
install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
export abstract class HelmGardenIngressController extends GardenIngressController {
override install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
return helmNginxInstall(ctx, log, this.helmValuesGetter())
}

ready(ctx: KubernetesPluginContext, log: Log): Promise<boolean> {
override ready(ctx: KubernetesPluginContext, log: Log): Promise<boolean> {
return helmIngressControllerReady(ctx, log, this.helmValuesGetter())
}

uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
override uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
return helmNginxUninstall(ctx, log, this.helmValuesGetter())
}

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 @@ -24,8 +24,8 @@ const nginxKindMainResource = {
},
}

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

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

async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
override async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await kindNginxStatus(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 @@ -15,8 +15,8 @@ import { configureMicrok8sAddons } from "../local/microk8s.js"
import { waitForResources } from "../status/status.js"
import { GardenIngressController } from "./ingress-controller.js"

export class Microk8sGardenIngressController implements GardenIngressController {
async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
export class Microk8sGardenIngressController extends GardenIngressController {
override async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const provider = ctx.provider

const status = await microk8sNginxStatus(log)
Expand Down Expand Up @@ -44,11 +44,11 @@ export class Microk8sGardenIngressController implements GardenIngressController
})
}

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

async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
override async uninstall(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const status = await microk8sNginxStatus(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 @@ -15,8 +15,8 @@ import { KubeApi } from "../api.js"
import { checkResourceStatus, waitForResources } from "../status/status.js"
import { GardenIngressController } from "./ingress-controller.js"

export class MinikubeGardenIngressController implements GardenIngressController {
async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
export class MinikubeGardenIngressController extends GardenIngressController {
override async install(ctx: KubernetesPluginContext, log: Log): Promise<void> {
const provider = ctx.provider
const status = await minikubeNginxStatus(ctx, log)
if (status === "ready") {
Expand All @@ -36,11 +36,11 @@ export class MinikubeGardenIngressController implements GardenIngressController
})
}

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

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

0 comments on commit f0d8232

Please sign in to comment.