import * as dns from "../net/dns" ; type TraefikEntryPoints = Array < "web" | "web-secure" > ; see https interface TraefikIngressRoute { apiVersion : "traefik.containo.us/v1alpha1" ; kind : "IngressRoute" ; metadata : { name : string ; namespace ? : string ; } ; spec : { entryPoints ? : TraefikEntryPoints ; routes : Array < { match : string ; kind : "Rule" ; priority ? : number ; middlewares ? : Array < { name : string ; } > ; services : Array < { name : string ; port : number ; healthCheck ? : { path : string ; host : string ; intervalSeconds : number ; timeoutSeconds : number ; } ; weight ? : number ; passHostHeader ? : boolean ; responseForwarding ? : { flushInterval : string ; } ; strategy ? : "RoundRobin" ; } > ; } > ; } ; } throws param serviceName param ringName param opts export const create = ( serviceName , ringName , servicePort , versionAndPath , opts ? ) : TraefikIngressRoute => { const { entryPoints , k8sBackend , middlewares = [ ] , namespace , isDefault } = opts ?? { } ; const ringedServiceName = ringName ? `${ serviceName }-${ ringName }` : serviceName ; const ingressName = isDefault ? serviceName : ringedServiceName ; const routeMatchPathPrefix = `PathPrefix(\`${ versionAndPath }\`)` ; const routeMatchHeaders = isDefault ? undefined : ringName && `Headers(\`Ring\`, \`${ ringName }\`)` ; const routeMatch = [ routeMatchPathPrefix , routeMatchHeaders ] . filter ( ( rule ) : rule is NonNullable < typeof rule > => ! ! rule ) . join ( " && " ) ; const backendService = k8sBackend && ringName ? `${ k8sBackend }-${ ringName }` : ringedServiceName ; dns . assertIsValid ( "metadata.name" , ingressName ) ; dns . assertIsValid ( "spec.routes[].services[].name" , backendService ) ; return { apiVersion : "traefik.containo.us/v1alpha1" , kind : "IngressRoute" , metadata : { name : ingressName , ... ( namespace ? { namespace } : { } ) , } , spec : { ... ( ( entryPoints ?? [ ] ) . length > 0 ? { entryPoints } : { } ) , routes : [ { kind : "Rule" , match : routeMatch , middlewares : middlewares . map ( ( middlewareName ) => ( { name : middlewareName , } ) ) , services : [ { name : backendService , port : servicePort , } , ] , } , ] , } , } ; } ;