github.com/oam-dev/kubevela@v1.9.11/charts/vela-core/templates/defwithtemplate/storage.yaml (about) 1 # Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. 2 # Definition source cue file: vela-templates/definitions/internal/storage.cue 3 apiVersion: core.oam.dev/v1beta1 4 kind: TraitDefinition 5 metadata: 6 annotations: 7 definition.oam.dev/description: Add storages on K8s pod for your workload which follows the pod spec in path 'spec.template'. 8 name: storage 9 namespace: {{ include "systemDefinitionNamespace" . }} 10 spec: 11 appliesToWorkloads: 12 - deployments.apps 13 - statefulsets.apps 14 - daemonsets.apps 15 - jobs.batch 16 podDisruptive: true 17 schematic: 18 cue: 19 template: | 20 volumesList: [ 21 if parameter.pvc != _|_ for v in parameter.pvc { 22 { 23 name: "pvc-" + v.name 24 persistentVolumeClaim: claimName: v.name 25 } 26 }, 27 if parameter.configMap != _|_ for v in parameter.configMap if v.mountPath != _|_ { 28 { 29 name: "configmap-" + v.name 30 configMap: { 31 defaultMode: v.defaultMode 32 name: v.name 33 if v.items != _|_ { 34 items: v.items 35 } 36 } 37 } 38 }, 39 if parameter.secret != _|_ for v in parameter.secret if v.mountPath != _|_ { 40 { 41 name: "secret-" + v.name 42 secret: { 43 defaultMode: v.defaultMode 44 secretName: v.name 45 if v.items != _|_ { 46 items: v.items 47 } 48 } 49 } 50 }, 51 if parameter.emptyDir != _|_ for v in parameter.emptyDir { 52 { 53 name: "emptydir-" + v.name 54 emptyDir: medium: v.medium 55 } 56 }, 57 if parameter.hostPath != _|_ for v in parameter.hostPath { 58 { 59 name: "hostpath-" + v.name 60 path: v.path 61 } 62 }, 63 ] 64 65 volumeMountsList: [ 66 if parameter.pvc != _|_ for v in parameter.pvc { 67 if v.volumeMode == "Filesystem" { 68 { 69 name: "pvc-" + v.name 70 mountPath: v.mountPath 71 if v.subPath != _|_ { 72 subPath: v.subPath 73 } 74 } 75 } 76 }, 77 if parameter.configMap != _|_ for v in parameter.configMap if v.mountPath != _|_ { 78 { 79 name: "configmap-" + v.name 80 mountPath: v.mountPath 81 if v.subPath != _|_ { 82 subPath: v.subPath 83 } 84 } 85 }, 86 if parameter.secret != _|_ for v in parameter.secret if v.mountPath != _|_ { 87 { 88 name: "secret-" + v.name 89 mountPath: v.mountPath 90 if v.subPath != _|_ { 91 subPath: v.subPath 92 } 93 } 94 }, 95 if parameter.emptyDir != _|_ for v in parameter.emptyDir { 96 { 97 name: "emptydir-" + v.name 98 mountPath: v.mountPath 99 if v.subPath != _|_ { 100 subPath: v.subPath 101 } 102 } 103 }, 104 if parameter.hostPath != _|_ for v in parameter.hostPath { 105 { 106 name: "hostpath-" + v.name 107 mountPath: v.mountPath 108 } 109 }, 110 ] 111 112 envList: [ 113 if parameter.configMap != _|_ for v in parameter.configMap if v.mountToEnv != _|_ { 114 { 115 name: v.mountToEnv.envName 116 valueFrom: configMapKeyRef: { 117 name: v.name 118 key: v.mountToEnv.configMapKey 119 } 120 } 121 }, 122 if parameter.configMap != _|_ for v in parameter.configMap if v.mountToEnvs != _|_ for k in v.mountToEnvs { 123 { 124 name: k.envName 125 valueFrom: configMapKeyRef: { 126 name: v.name 127 key: k.configMapKey 128 } 129 } 130 }, 131 if parameter.secret != _|_ for v in parameter.secret if v.mountToEnv != _|_ { 132 { 133 name: v.mountToEnv.envName 134 valueFrom: secretKeyRef: { 135 name: v.name 136 key: v.mountToEnv.secretKey 137 } 138 } 139 }, 140 if parameter.secret != _|_ for v in parameter.secret if v.mountToEnvs != _|_ for k in v.mountToEnvs { 141 { 142 name: k.envName 143 valueFrom: secretKeyRef: { 144 name: v.name 145 key: k.secretKey 146 } 147 } 148 }, 149 ] 150 151 volumeDevicesList: *[ 152 for v in parameter.pvc if v.volumeMode == "Block" { 153 { 154 name: "pvc-" + v.name 155 devicePath: v.mountPath 156 if v.subPath != _|_ { 157 subPath: v.subPath 158 } 159 } 160 }, 161 ] | [] 162 163 deDupVolumesArray: [ 164 for val in [ 165 for i, vi in volumesList { 166 for j, vj in volumesList if j < i && vi.name == vj.name { 167 _ignore: true 168 } 169 vi 170 }, 171 ] if val._ignore == _|_ { 172 val 173 }, 174 ] 175 176 patch: spec: template: spec: { 177 // +patchKey=name 178 volumes: deDupVolumesArray 179 180 containers: [{ 181 // +patchKey=name 182 env: envList 183 // +patchKey=name 184 volumeDevices: volumeDevicesList 185 // +patchKey=name 186 volumeMounts: volumeMountsList 187 }, ...] 188 189 } 190 191 outputs: { 192 for v in parameter.pvc { 193 if v.mountOnly == false { 194 "pvc-\(v.name)": { 195 apiVersion: "v1" 196 kind: "PersistentVolumeClaim" 197 metadata: name: v.name 198 spec: { 199 accessModes: v.accessModes 200 volumeMode: v.volumeMode 201 if v.volumeName != _|_ { 202 volumeName: v.volumeName 203 } 204 if v.storageClassName != _|_ { 205 storageClassName: v.storageClassName 206 } 207 208 if v.resources.requests.storage == _|_ { 209 resources: requests: storage: "8Gi" 210 } 211 if v.resources.requests.storage != _|_ { 212 resources: requests: storage: v.resources.requests.storage 213 } 214 if v.resources.limits.storage != _|_ { 215 resources: limits: storage: v.resources.limits.storage 216 } 217 if v.dataSourceRef != _|_ { 218 dataSourceRef: v.dataSourceRef 219 } 220 if v.dataSource != _|_ { 221 dataSource: v.dataSource 222 } 223 if v.selector != _|_ { 224 dataSource: v.selector 225 } 226 } 227 } 228 } 229 } 230 231 for v in parameter.configMap { 232 if v.mountOnly == false { 233 "configmap-\(v.name)": { 234 apiVersion: "v1" 235 kind: "ConfigMap" 236 metadata: name: v.name 237 if v.data != _|_ { 238 data: v.data 239 } 240 } 241 } 242 } 243 244 for v in parameter.secret { 245 if v.mountOnly == false { 246 "secret-\(v.name)": { 247 apiVersion: "v1" 248 kind: "Secret" 249 metadata: name: v.name 250 if v.data != _|_ { 251 data: v.data 252 } 253 if v.stringData != _|_ { 254 stringData: v.stringData 255 } 256 } 257 } 258 } 259 260 } 261 262 parameter: { 263 // +usage=Declare pvc type storage 264 pvc?: [...{ 265 name: string 266 mountOnly: *false | bool 267 mountPath: string 268 subPath?: string 269 volumeMode: *"Filesystem" | string 270 volumeName?: string 271 accessModes: *["ReadWriteOnce"] | [...string] 272 storageClassName?: string 273 resources?: { 274 requests: storage: =~"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$" 275 limits?: storage: =~"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$" 276 } 277 dataSourceRef?: { 278 name: string 279 kind: string 280 apiGroup: string 281 } 282 dataSource?: { 283 name: string 284 kind: string 285 apiGroup: string 286 } 287 selector?: { 288 matchLabels?: [string]: string 289 matchExpressions?: { 290 key: string 291 values: [...string] 292 operator: string 293 } 294 } 295 }] 296 297 // +usage=Declare config map type storage 298 configMap?: [...{ 299 name: string 300 mountOnly: *false | bool 301 mountToEnv?: { 302 envName: string 303 configMapKey: string 304 } 305 mountToEnvs?: [...{ 306 envName: string 307 configMapKey: string 308 }] 309 mountPath?: string 310 subPath?: string 311 defaultMode: *420 | int 312 readOnly: *false | bool 313 data?: {...} 314 items?: [...{ 315 key: string 316 path: string 317 mode: *511 | int 318 }] 319 }] 320 321 // +usage=Declare secret type storage 322 secret?: [...{ 323 name: string 324 mountOnly: *false | bool 325 mountToEnv?: { 326 envName: string 327 secretKey: string 328 } 329 mountToEnvs?: [...{ 330 envName: string 331 secretKey: string 332 }] 333 mountPath: string 334 subPath?: string 335 defaultMode: *420 | int 336 readOnly: *false | bool 337 stringData?: {...} 338 data?: {...} 339 items?: [...{ 340 key: string 341 path: string 342 mode: *511 | int 343 }] 344 }] 345 346 // +usage=Declare empty dir type storage 347 emptyDir?: [...{ 348 name: string 349 mountPath: string 350 subPath?: string 351 medium: *"" | "Memory" 352 }] 353 354 // +usage=Declare host path type storage 355 hostPath?: [...{ 356 name: string 357 path: string 358 mountPath: string 359 type: *"Directory" | "DirectoryOrCreate" | "FileOrCreate" | "File" | "Socket" | "CharDevice" | "BlockDevice" 360 }] 361 } 362