blob: e16bbffbbeb49d0dcdada422248fa14755ff7743 [file] [log] [blame]
Marcel van Lohuizen02173f82018-12-20 13:27:07 +01001package kube
2
3// _base defines settings that apply to all cloud objects
4_base: {
5 name: string
6
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +02007 label: [string]: string
Marcel van Lohuizen02173f82018-12-20 13:27:07 +01008
9 // k8s is a set of Kubernetes-specific settings that will be merged in at
10 // the top-level. The allowed fields are type specfic.
11 kubernetes: {}
12}
13
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020014deployment: [Name=_]: _base & {
Marcel van Lohuizenc9b3cb22019-01-30 11:32:41 +010015 // Allow any string, but take Name by default.
16 name: string | *Name
Marcel van Lohuizene5d8d092019-01-30 15:58:07 +010017 kind: *"deployment" | "stateful" | "daemon"
Marcel van Lohuizenc9b3cb22019-01-30 11:32:41 +010018 replicas: int | *1
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010019
20 image: string
21
22 // expose port defines named ports that is exposed in the service
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020023 expose: port: [string]: int
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010024
25 // port defines named ports that is not exposed in the service.
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020026 port: [string]: int
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010027
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020028 arg: [string]: string
Marcel van Lohuizen1370f0a2020-04-15 11:27:13 +020029 args: [ for k, v in arg { "-\(k)=\(v)" } ] | [...string]
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010030
31 // Environment variables
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020032 env: [string]: string
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010033
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020034 envSpec: [string]: {}
Marcel van Lohuizen9af9a902019-09-07 20:30:10 +020035 envSpec: {
36 for k, v in env {
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020037 "\(k)": value: v
Marcel van Lohuizen9af9a902019-09-07 20:30:10 +020038 }
39 }
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010040
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020041 volume: [Name=_]: {
Marcel van Lohuizenc9b3cb22019-01-30 11:32:41 +010042 name: string | *Name
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010043 mountPath: string
Marcel van Lohuizenc9b3cb22019-01-30 11:32:41 +010044 subPath: string | *null
45 readOnly: *false | true
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010046 kubernetes: {}
47 }
48}
49
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020050service: [Name=_]: _base & {
Marcel van Lohuizene5d8d092019-01-30 15:58:07 +010051 name: *Name | string
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010052
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020053 port: [Name=_]: {
Marcel van Lohuizenc9b3cb22019-01-30 11:32:41 +010054 name: string | *Name
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010055
Marcel van Lohuizene5d8d092019-01-30 15:58:07 +010056 port: int
57 protocol: *"TCP" | "UDP"
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010058 }
59
60 kubernetes: {}
61}
62
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020063configMap: [string]: {
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010064}
65
66// define services implied by deployments
Marcel van Lohuizen9af9a902019-09-07 20:30:10 +020067for k, spec in deployment if len(spec.expose.port) > 0 {
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020068 service: "\(k)": {
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010069
Marcel van Lohuizen9af9a902019-09-07 20:30:10 +020070 // Copy over all ports exposed from containers.
71 for Name, Port in spec.expose.port {
Marcel van Lohuizen23623fa2019-10-23 19:28:59 +020072 port: "\(Name)": {
Marcel van Lohuizen9af9a902019-09-07 20:30:10 +020073 // Set default external port to Port. targetPort must be
74 // the respective containerPort (Port) if it differs from port.
75 port: int | *Port
76 if port != Port {
77 targetPort: Port
78 }
79 }
80 }
Marcel van Lohuizen02173f82018-12-20 13:27:07 +010081
Marcel van Lohuizen9af9a902019-09-07 20:30:10 +020082 // Copy over the labels
83 label: spec.label
84 }
85}