Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(dsl): Enforce types #16375

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/web/infra/web.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Ingress } from 'infra/src/dsl/types/input-types'
import { ref, service, ServiceBuilder } from '../../../infra/src/dsl/dsl'

export const serviceSetup = (services: {
Expand Down Expand Up @@ -49,7 +50,7 @@ export const serviceSetup = (services: {
},
},
paths: ['/'],
},
} as Ingress,
})
.liveness('/liveness')
.readiness({ path: '/readiness', initialDelaySeconds: 20 })
Expand Down
5 changes: 3 additions & 2 deletions infra/src/dsl/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ServiceDefinition,
XroadConfig,
PodDisruptionBudget,
IngressMapping,
} from './types/input-types'
import { logger } from '../logging'
import { COMMON_SECRETS } from './consts'
Expand Down Expand Up @@ -65,7 +66,7 @@ export class ServiceBuilder<ServiceType extends string> {
grantNamespaces: [],
grantNamespacesEnabled: false,
secrets: COMMON_SECRETS,
ingress: {},
ingress: {} as IngressMapping, // Force type conformance for initialization
namespace: 'islandis',
serviceAccountEnabled: false,
securityContext: {
Expand Down Expand Up @@ -461,7 +462,7 @@ export class ServiceBuilder<ServiceType extends string> {
* You can allow ingress traffic (traffic from the internet) to your service by creating an ingress controller. Mapped to an [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/#what-is-ingress).
* @param ingress - Ingress parameters
*/
ingress(ingress: { [name: string]: Ingress }) {
ingress(ingress: IngressMapping) {
this.serviceDef.ingress = ingress
return this
}
Expand Down
2 changes: 1 addition & 1 deletion infra/src/dsl/types/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ export type OpsEnvName =
| 'prod'
| 'prod-ids'

export type EnvironmentServices = { [name in OpsEnv]: ServiceBuilder<any>[] }
export type EnvironmentServices = { [env in OpsEnv]: ServiceBuilder<any>[] }

export type EnvironmentConfigs = { [name in OpsEnvName]: EnvironmentConfig }
16 changes: 10 additions & 6 deletions infra/src/dsl/types/input-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ValueType = MissingSettingType | ValueSource
export type AccessModes = 'ReadWrite' | 'ReadOnly'
export type PostgresInfo = {
host?: {
[idx in OpsEnv]: string
[env in OpsEnv]: string
}
name?: string
username?: string
Expand All @@ -35,7 +35,7 @@ export type PostgresInfoForEnv = {
}

export type RedisInfo = {
host?: { [idx in OpsEnv]: string }
host?: { [env in OpsEnv]: string }
}

export type RedisInfoForEnv = {
Expand Down Expand Up @@ -106,13 +106,15 @@ export type ServiceDefinitionCore = {
volumes: PersistentVolumeClaim[]
podDisruptionBudget?: PodDisruptionBudget
}
export type IngressType = 'primary' | 'internal'
export type IngressMapping = Partial<{ [name in IngressType]: Ingress }>
/**
* This is the definition of a service as generated by ServiceBuilder.
*/
export type ServiceDefinition = ServiceDefinitionCore & {
initContainers?: InitContainers
env: EnvironmentVariables
ingress: { [name: string]: Ingress }
ingress: IngressMapping
postgres?: PostgresInfo
redis?: RedisInfo
extraAttributes?: ExtraValues
Expand All @@ -133,11 +135,13 @@ export type ServiceDefinitionForEnv = ServiceDefinitionCore & {

export interface Ingress {
host: {
[name in OpsEnv]: string | string[]
[env in OpsEnv]: string | string[]
}
paths: string[]
public?: boolean
extraAnnotations?: { [name in OpsEnv]: { [idx: string]: string | null } }
extraAnnotations?: {
[env in OpsEnv]: { [annotation: string]: string | null }
}
}

export interface IngressForEnv {
Expand Down Expand Up @@ -227,4 +231,4 @@ export interface Context {
}

export type ExtraValuesForEnv = Hash
export type ExtraValues = { [idx in OpsEnv]: Hash | MissingSettingType }
export type ExtraValues = { [env in OpsEnv]: Hash | MissingSettingType }
Loading