github.com/solo-io/cue@v0.4.7/cue/testdata/comprehensions/nested.txtar (about) 1 -- in.cue -- 2 package kube 3 service: "node-exporter": { 4 spec: { 5 ports: [{ 6 name: "metrics" 7 port: 9100 8 protocol: "TCP" 9 }] 10 } 11 } 12 deployment: "node-exporter": { 13 spec: template: { 14 spec: { 15 containers: [{ 16 ports: [{ 17 containerPort: 9100 18 name: "scrape" 19 }] 20 }] 21 } 22 } 23 } 24 service: [ID=string]: { 25 spec: { 26 ports: [...{ 27 port: int 28 protocol: *"TCP" | "UDP" 29 name: string | *"client" 30 }] 31 } 32 } 33 deployment: [ID=string]: { } 34 deployment: [ID=_]: _spec & {} 35 _spec: { 36 _name: string 37 spec: template: { 38 spec: containers: [{name: _name}] 39 } 40 } 41 _spec: spec: template: spec: containers: [...{ 42 ports: [...{ 43 _export: *true | false // include the port in the service 44 }] 45 }] 46 for k, v in deployment { 47 service: "\(k)": { 48 spec: selector: v.spec.template.metadata.labels 49 spec: ports: [ 50 for c in v.spec.template.spec.containers 51 for p in c.ports 52 if p._export { 53 let Port = p.containerPort // Port is an alias 54 port: *Port | int 55 targetPort: *Port | int 56 }, 57 ] 58 } 59 } 60 -- out/eval -- 61 (struct){ 62 service: (struct){ 63 "node-exporter": (struct){ 64 spec: (struct){ 65 ports: (#list){ 66 0: (struct){ 67 name: (string){ "metrics" } 68 port: (int){ 9100 } 69 protocol: (string){ "TCP" } 70 targetPort: (int){ |(*(int){ 9100 }, (int){ int }) } 71 } 72 } 73 selector: (_|_){ 74 // [incomplete] service."node-exporter".spec.selector: undefined field: metadata: 75 // ./in.cue:47:35 76 } 77 } 78 } 79 } 80 deployment: (struct){ 81 "node-exporter": (struct){ 82 spec: (struct){ 83 template: (struct){ 84 spec: (struct){ 85 containers: (#list){ 86 0: (struct){ 87 ports: (#list){ 88 0: (struct){ 89 containerPort: (int){ 9100 } 90 name: (string){ "scrape" } 91 _export(:kube): (bool){ |(*(bool){ true }, (bool){ false }) } 92 } 93 } 94 name: (string){ string } 95 } 96 } 97 } 98 } 99 } 100 _name(:kube): (string){ string } 101 } 102 } 103 _spec(:kube): (struct){ 104 _name(:kube): (string){ string } 105 spec: (struct){ 106 template: (struct){ 107 spec: (struct){ 108 containers: (#list){ 109 0: (struct){ 110 name: (string){ string } 111 ports: (list){ 112 } 113 } 114 } 115 } 116 } 117 } 118 } 119 } 120 -- out/compile -- 121 --- in.cue 122 { 123 service: { 124 "node-exporter": { 125 spec: { 126 ports: [ 127 { 128 name: "metrics" 129 port: 9100 130 protocol: "TCP" 131 }, 132 ] 133 } 134 } 135 } 136 deployment: { 137 "node-exporter": { 138 spec: { 139 template: { 140 spec: { 141 containers: [ 142 { 143 ports: [ 144 { 145 containerPort: 9100 146 name: "scrape" 147 }, 148 ] 149 }, 150 ] 151 } 152 } 153 } 154 } 155 } 156 service: { 157 [string]: { 158 spec: { 159 ports: [ 160 ...{ 161 port: int 162 protocol: (*"TCP"|"UDP") 163 name: (string|*"client") 164 }, 165 ] 166 } 167 } 168 } 169 deployment: { 170 [string]: {} 171 } 172 deployment: { 173 [_]: (〈1;_spec〉 & {}) 174 } 175 _spec: { 176 _name: string 177 spec: { 178 template: { 179 spec: { 180 containers: [ 181 { 182 name: 〈4;_name〉 183 }, 184 ] 185 } 186 } 187 } 188 } 189 _spec: { 190 spec: { 191 template: { 192 spec: { 193 containers: [ 194 ...{ 195 ports: [ 196 ...{ 197 _export: (*true|false) 198 }, 199 ] 200 }, 201 ] 202 } 203 } 204 } 205 } 206 for k, v in 〈0;deployment〉 { 207 service: { 208 "\(〈2;k〉)": { 209 spec: { 210 selector: 〈4;v〉.spec.template.metadata.labels 211 } 212 spec: { 213 ports: [ 214 for _, c in 〈4;v〉.spec.template.spec.containers for _, p in 〈0;c〉.ports if 〈0;p〉._export { 215 port: (*〈0;let Port〉|int) 216 targetPort: (*〈0;let Port〉|int) 217 }, 218 ] 219 } 220 } 221 } 222 } 223 }