github.com/solo-io/cue@v0.4.7/doc/tutorial/kubernetes/quick/services/kube.cue (about) 1 package kube 2 3 service: [ID=_]: { 4 apiVersion: "v1" 5 kind: "Service" 6 metadata: { 7 name: ID 8 labels: { 9 app: ID // by convention 10 domain: "prod" // always the same in the given files 11 component: #Component // varies per directory 12 } 13 } 14 spec: { 15 // Any port has the following properties. 16 ports: [...{ 17 port: int 18 protocol: *"TCP" | "UDP" // from the Kubernetes definition 19 name: string | *"client" 20 }] 21 selector: metadata.labels // we want those to be the same 22 } 23 } 24 25 deployment: [ID=_]: { 26 apiVersion: "apps/v1" 27 kind: "Deployment" 28 metadata: name: ID 29 spec: { 30 // 1 is the default, but we allow any number 31 replicas: *1 | int 32 template: { 33 metadata: labels: { 34 app: ID 35 domain: "prod" 36 component: #Component 37 } 38 // we always have one namesake container 39 spec: containers: [{name: ID}] 40 } 41 } 42 } 43 44 #Component: string 45 46 daemonSet: [ID=_]: _spec & { 47 apiVersion: "apps/v1" 48 kind: "DaemonSet" 49 _name: ID 50 } 51 52 statefulSet: [ID=_]: _spec & { 53 apiVersion: "apps/v1" 54 kind: "StatefulSet" 55 _name: ID 56 } 57 58 deployment: [ID=_]: _spec & { 59 apiVersion: "apps/v1" 60 kind: "Deployment" 61 _name: ID 62 spec: replicas: *1 | int 63 } 64 65 configMap: [ID=_]: { 66 metadata: name: ID 67 metadata: labels: component: #Component 68 } 69 70 _spec: { 71 _name: string 72 73 metadata: name: _name 74 metadata: labels: component: #Component 75 spec: selector: {} 76 spec: template: { 77 metadata: labels: { 78 app: _name 79 component: #Component 80 domain: "prod" 81 } 82 spec: containers: [{name: _name}] 83 } 84 } 85 86 // Define the _export option and set the default to true 87 // for all ports defined in all containers. 88 _spec: spec: template: spec: containers: [...{ 89 ports: [...{ 90 _export: *true | false // include the port in the service 91 }] 92 }] 93 94 for x in [deployment, daemonSet, statefulSet] for k, v in x { 95 service: "\(k)": { 96 spec: selector: v.spec.template.metadata.labels 97 98 spec: ports: [ 99 for c in v.spec.template.spec.containers 100 for p in c.ports 101 if p._export { 102 let Port = p.containerPort // Port is an alias 103 port: *Port | int 104 targetPort: *Port | int 105 }, 106 ] 107 } 108 }