Skip to content

Commit

Permalink
refactor: (12) change signature of helmValuesGetter
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Nov 8, 2023
1 parent b1771ee commit a4d0fbf
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 107 deletions.
72 changes: 35 additions & 37 deletions core/src/plugins/kubernetes/nginx/nginx-helm-ephemeral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,48 @@
*/

import type { SystemVars } from "../init.js"
import type { NginxHelmValuesGetter } from "./nginx-helm.js"
import type { NginxHelmValues } from "./nginx-helm.js"
import { HelmGardenIngressController } from "./nginx-helm.js"

export class EphemeralHelmGardenIngressController extends HelmGardenIngressController {
helmValuesGetter(): NginxHelmValuesGetter {
return (systemVars: SystemVars) => {
return {
name: "ingress-controller",
controller: {
kind: "Deployment",
updateStrategy: {
type: "RollingUpdate",
rollingUpdate: {
maxUnavailable: 1,
},
},
extraArgs: {
"default-backend-service": `${systemVars.namespace}/default-backend`,
},
minReadySeconds: 1,
tolerations: systemVars["system-tolerations"],
nodeSelector: systemVars["system-node-selector"],
admissionWebhooks: {
enabled: false,
},
ingressClassResource: {
name: "nginx",
enabled: true,
default: true,
},
replicaCount: 1,
service: {
annotations: {
"kubernetes.namespace.so/expose": "true",
"kubernetes.namespace.so/exposed-port-80": "wildcard",
"kubernetes.namespace.so/exposed-port-443": "wildcard",
},
type: "LoadBalancer",
override helmValuesGetter(systemVars: SystemVars): NginxHelmValues {
return {
name: "ingress-controller",
controller: {
kind: "Deployment",
updateStrategy: {
type: "RollingUpdate",
rollingUpdate: {
maxUnavailable: 1,
},
},
defaultBackend: {
extraArgs: {
"default-backend-service": `${systemVars.namespace}/default-backend`,
},
minReadySeconds: 1,
tolerations: systemVars["system-tolerations"],
nodeSelector: systemVars["system-node-selector"],
admissionWebhooks: {
enabled: false,
},
}
ingressClassResource: {
name: "nginx",
enabled: true,
default: true,
},
replicaCount: 1,
service: {
annotations: {
"kubernetes.namespace.so/expose": "true",
"kubernetes.namespace.so/exposed-port-80": "wildcard",
"kubernetes.namespace.so/exposed-port-443": "wildcard",
},
type: "LoadBalancer",
},
},
defaultBackend: {
enabled: false,
},
}
}
}
68 changes: 33 additions & 35 deletions core/src/plugins/kubernetes/nginx/nginx-helm-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,46 @@
*/

import type { SystemVars } from "../init.js"
import type { NginxHelmValuesGetter } from "./nginx-helm.js"
import type { NginxHelmValues } from "./nginx-helm.js"
import { HelmGardenIngressController } from "./nginx-helm.js"

export class GenericHelmGardenIngressController extends HelmGardenIngressController {
helmValuesGetter(): NginxHelmValuesGetter {
return (systemVars: SystemVars) => {
return {
name: "ingress-controller",
controller: {
kind: "DaemonSet",
updateStrategy: {
type: "RollingUpdate",
rollingUpdate: {
maxUnavailable: 1,
},
},
extraArgs: {
"default-backend-service": `${systemVars.namespace}/default-backend`,
},
minReadySeconds: 1,
tolerations: systemVars["system-tolerations"],
nodeSelector: systemVars["system-node-selector"],
admissionWebhooks: {
enabled: false,
},
ingressClassResource: {
name: "nginx",
enabled: true,
default: true,
},
hostPort: {
enabled: true,
ports: {
http: systemVars["ingress-http-port"],
https: systemVars["ingress-https-port"],
},
override helmValuesGetter(systemVars: SystemVars): NginxHelmValues {
return {
name: "ingress-controller",
controller: {
kind: "DaemonSet",
updateStrategy: {
type: "RollingUpdate",
rollingUpdate: {
maxUnavailable: 1,
},
},
defaultBackend: {
extraArgs: {
"default-backend-service": `${systemVars.namespace}/default-backend`,
},
minReadySeconds: 1,
tolerations: systemVars["system-tolerations"],
nodeSelector: systemVars["system-node-selector"],
admissionWebhooks: {
enabled: false,
},
}
ingressClassResource: {
name: "nginx",
enabled: true,
default: true,
},
hostPort: {
enabled: true,
ports: {
http: systemVars["ingress-http-port"],
https: systemVars["ingress-https-port"],
},
},
},
defaultBackend: {
enabled: false,
},
}
}
}
56 changes: 27 additions & 29 deletions core/src/plugins/kubernetes/nginx/nginx-helm-k3s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,40 @@
*/

import type { SystemVars } from "../init.js"
import type { NginxHelmValuesGetter } from "./nginx-helm.js"
import type { NginxHelmValues } from "./nginx-helm.js"
import { HelmGardenIngressController } from "./nginx-helm.js"

export class K3sHelmGardenIngressController extends HelmGardenIngressController {
helmValuesGetter(): NginxHelmValuesGetter {
return (systemVars: SystemVars) => {
return {
name: "ingress-controller",
controller: {
kind: "Deployment",
updateStrategy: {
type: "RollingUpdate",
rollingUpdate: {
maxUnavailable: 1,
},
override helmValuesGetter(systemVars: SystemVars): NginxHelmValues {
return {
name: "ingress-controller",
controller: {
kind: "Deployment",
updateStrategy: {
type: "RollingUpdate",
rollingUpdate: {
maxUnavailable: 1,
},
extraArgs: {
"default-backend-service": `${systemVars.namespace}/default-backend`,
},
minReadySeconds: 1,
tolerations: systemVars["system-tolerations"],
nodeSelector: systemVars["system-node-selector"],
admissionWebhooks: {
enabled: false,
},
ingressClassResource: {
name: "nginx",
enabled: true,
default: true,
},
replicaCount: 1,
},
defaultBackend: {
extraArgs: {
"default-backend-service": `${systemVars.namespace}/default-backend`,
},
minReadySeconds: 1,
tolerations: systemVars["system-tolerations"],
nodeSelector: systemVars["system-node-selector"],
admissionWebhooks: {
enabled: false,
},
}
ingressClassResource: {
name: "nginx",
enabled: true,
default: true,
},
replicaCount: 1,
},
defaultBackend: {
enabled: false,
},
}
}
}
10 changes: 4 additions & 6 deletions core/src/plugins/kubernetes/nginx/nginx-helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export abstract class HelmGardenIngressController extends GardenIngressComponent
const config = provider.config
const namespace = config.gardenSystemNamespace
const systemVars: SystemVars = getKubernetesSystemVariables(config)
const values = this.helmValuesGetter()(systemVars)
const values = this.helmValuesGetter(systemVars)

const valueArgs: string[] = []
for (const key in values) {
Expand Down Expand Up @@ -89,7 +89,7 @@ export abstract class HelmGardenIngressController extends GardenIngressComponent
const config = provider.config
const api = await KubeApi.factory(log, ctx, provider)
const systemVars: SystemVars = getKubernetesSystemVariables(config)
const values = this.helmValuesGetter()(systemVars)
const values = this.helmValuesGetter(systemVars)

const namespace = config.gardenSystemNamespace
try {
Expand Down Expand Up @@ -142,10 +142,10 @@ export abstract class HelmGardenIngressController extends GardenIngressComponent
await this.defaultBackend.uninstall(ctx, log)
}

abstract helmValuesGetter(): NginxHelmValuesGetter
abstract helmValuesGetter(systemVars: SystemVars): NginxHelmValues
}

interface NginxHelmValues {
export interface NginxHelmValues {
name: string
controller: {
kind: string
Expand Down Expand Up @@ -180,8 +180,6 @@ interface NginxHelmValues {
[key: string]: _HelmValue
}

export type NginxHelmValuesGetter = (systemVars: SystemVars) => NginxHelmValues

function getNginxHelmMainResource(values: NginxHelmValues) {
return {
apiVersion: "apps/v1",
Expand Down

0 comments on commit a4d0fbf

Please sign in to comment.