github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/trait/affinity.cue (about) 1 "affinity": { 2 type: "trait" 3 annotations: {} 4 labels: { 5 "ui-hidden": "true" 6 } 7 description: "Affinity specifies affinity and toleration K8s pod for your workload which follows the pod spec in path 'spec.template'." 8 attributes: { 9 appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"] 10 podDisruptive: true 11 } 12 } 13 template: { 14 patch: spec: template: spec: { 15 if parameter.podAffinity != _|_ { 16 affinity: podAffinity: { 17 if parameter.podAffinity.required != _|_ { 18 requiredDuringSchedulingIgnoredDuringExecution: [ 19 for k in parameter.podAffinity.required { 20 if k.labelSelector != _|_ { 21 labelSelector: k.labelSelector 22 } 23 if k.namespace != _|_ { 24 namespace: k.namespace 25 } 26 topologyKey: k.topologyKey 27 if k.namespaceSelector != _|_ { 28 namespaceSelector: k.namespaceSelector 29 } 30 }] 31 } 32 if parameter.podAffinity.preferred != _|_ { 33 preferredDuringSchedulingIgnoredDuringExecution: [ 34 for k in parameter.podAffinity.preferred { 35 weight: k.weight 36 podAffinityTerm: k.podAffinityTerm 37 }] 38 } 39 } 40 } 41 if parameter.podAntiAffinity != _|_ { 42 affinity: podAntiAffinity: { 43 if parameter.podAntiAffinity.required != _|_ { 44 requiredDuringSchedulingIgnoredDuringExecution: [ 45 for k in parameter.podAntiAffinity.required { 46 if k.labelSelector != _|_ { 47 labelSelector: k.labelSelector 48 } 49 if k.namespace != _|_ { 50 namespace: k.namespace 51 } 52 topologyKey: k.topologyKey 53 if k.namespaceSelector != _|_ { 54 namespaceSelector: k.namespaceSelector 55 } 56 }] 57 } 58 if parameter.podAntiAffinity.preferred != _|_ { 59 preferredDuringSchedulingIgnoredDuringExecution: [ 60 for k in parameter.podAntiAffinity.preferred { 61 weight: k.weight 62 podAffinityTerm: k.podAffinityTerm 63 }] 64 } 65 } 66 } 67 if parameter.nodeAffinity != _|_ { 68 affinity: nodeAffinity: { 69 if parameter.nodeAffinity.required != _|_ { 70 requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: [ 71 for k in parameter.nodeAffinity.required.nodeSelectorTerms { 72 if k.matchExpressions != _|_ { 73 matchExpressions: k.matchExpressions 74 } 75 if k.matchFields != _|_ { 76 matchFields: k.matchFields 77 } 78 }] 79 } 80 if parameter.nodeAffinity.preferred != _|_ { 81 preferredDuringSchedulingIgnoredDuringExecution: [ 82 for k in parameter.nodeAffinity.preferred { 83 weight: k.weight 84 preference: k.preference 85 }] 86 } 87 } 88 } 89 if parameter.tolerations != _|_ { 90 tolerations: [ 91 for k in parameter.tolerations { 92 if k.key != _|_ { 93 key: k.key 94 } 95 if k.effect != _|_ { 96 effect: k.effect 97 } 98 if k.value != _|_ { 99 value: k.value 100 } 101 operator: k.operator 102 if k.tolerationSeconds != _|_ { 103 tolerationSeconds: k.tolerationSeconds 104 } 105 }] 106 } 107 } 108 109 #labelSelector: { 110 matchLabels?: [string]: string 111 matchExpressions?: [...{ 112 key: string 113 operator: *"In" | "NotIn" | "Exists" | "DoesNotExist" 114 values?: [...string] 115 }] 116 } 117 118 #podAffinityTerm: { 119 labelSelector?: #labelSelector 120 namespaces?: [...string] 121 topologyKey: string 122 namespaceSelector?: #labelSelector 123 } 124 125 #nodeSelecor: { 126 key: string 127 operator: *"In" | "NotIn" | "Exists" | "DoesNotExist" | "Gt" | "Lt" 128 values?: [...string] 129 } 130 131 #nodeSelectorTerm: { 132 matchExpressions?: [...#nodeSelecor] 133 matchFields?: [...#nodeSelecor] 134 } 135 136 parameter: { 137 // +usage=Specify the pod affinity scheduling rules 138 podAffinity?: { 139 // +usage=Specify the required during scheduling ignored during execution 140 required?: [...#podAffinityTerm] 141 // +usage=Specify the preferred during scheduling ignored during execution 142 preferred?: [...{ 143 // +usage=Specify weight associated with matching the corresponding podAffinityTerm 144 weight: int & >=1 & <=100 145 // +usage=Specify a set of pods 146 podAffinityTerm: #podAffinityTerm 147 }] 148 } 149 // +usage=Specify the pod anti-affinity scheduling rules 150 podAntiAffinity?: { 151 // +usage=Specify the required during scheduling ignored during execution 152 required?: [...#podAffinityTerm] 153 // +usage=Specify the preferred during scheduling ignored during execution 154 preferred?: [...{ 155 // +usage=Specify weight associated with matching the corresponding podAffinityTerm 156 weight: int & >=1 & <=100 157 // +usage=Specify a set of pods 158 podAffinityTerm: #podAffinityTerm 159 }] 160 } 161 // +usage=Specify the node affinity scheduling rules for the pod 162 nodeAffinity?: { 163 // +usage=Specify the required during scheduling ignored during execution 164 required?: { 165 // +usage=Specify a list of node selector 166 nodeSelectorTerms: [...#nodeSelectorTerm] 167 } 168 // +usage=Specify the preferred during scheduling ignored during execution 169 preferred?: [...{ 170 // +usage=Specify weight associated with matching the corresponding nodeSelector 171 weight: int & >=1 & <=100 172 // +usage=Specify a node selector 173 preference: #nodeSelectorTerm 174 }] 175 } 176 // +usage=Specify tolerant taint 177 tolerations?: [...{ 178 key?: string 179 operator: *"Equal" | "Exists" 180 value?: string 181 effect?: "NoSchedule" | "PreferNoSchedule" | "NoExecute" 182 // +usage=Specify the period of time the toleration 183 tolerationSeconds?: int 184 }] 185 } 186 }