|
| 1 | +# Metal3Machine |
| 2 | + |
| 3 | + |
| 4 | +The Metal3Machine contains information related to the deployment of the |
| 5 | +BareMetalHost such as the image and the host selector. For each machine, there |
| 6 | +must be a Metal3Machine. |
| 7 | + |
| 8 | + |
| 9 | +The fields are: |
| 10 | + |
| 11 | + |
| 12 | +- **image** -- This includes two sub-fields, `url` and `checksum`, which include |
| 13 | + the URL to the image and the URL to a checksum for that image. These fields |
| 14 | + are required. The image will be used for provisioning of the `BareMetalHost` |
| 15 | + chosen by the `Machine` actuator. |
| 16 | + |
| 17 | + |
| 18 | +- **userData** -- This includes two sub-fields, `name` and `namespace`, which |
| 19 | + reference a `Secret` that contains base64 encoded user-data to be written to a |
| 20 | + config drive on the provisioned `BareMetalHost`. This field is optional and is |
| 21 | + automatically set by CAPM3 with the userData from the machine object. If you |
| 22 | + want to overwrite the userData, this should be done in the CAPI machine. |
| 23 | + |
| 24 | + |
| 25 | +- **dataTemplate** -- This includes a reference to a Metal3DataTemplate object |
| 26 | + containing the metadata and network data templates, and includes two fields, |
| 27 | + `name` and `namespace`. |
| 28 | + |
| 29 | + |
| 30 | +- **metaData** is a reference to a secret containing the metadata rendered from |
| 31 | + the Metal3DataTemplate metadata template object automatically. In case this |
| 32 | + would not be managed by the Metal3DataTemplate controller, if provided by the |
| 33 | + user for example, the ownerreference should be set properly to ensure that the |
| 34 | + secret belongs to the cluster ownerReference tree (see |
| 35 | + [doc](https://cluster-api.sigs.k8s.io/clusterctl/provider-contract.html#ownerreferences-chain)). |
| 36 | + |
| 37 | + |
| 38 | +- **networkData** is a reference to a secret containing the network data |
| 39 | + rendered from the Metal3DataTemplate metadata template object automatically. |
| 40 | + In case this would not be managed by the Metal3DataTemplate controller, if |
| 41 | + provided by the user for example, the ownerreference should be set properly to |
| 42 | + ensure that the secret belongs to the cluster ownerReference tree (see |
| 43 | + [doc](https://cluster-api.sigs.k8s.io/clusterctl/provider-contract.html#ownerreferences-chain)). |
| 44 | + The content of the secret should be a yaml equivalent of a json object that |
| 45 | + follows the format definition that can be found |
| 46 | + [here](https://docs.openstack.org/nova/latest/_downloads/9119ca7ac90aa2990e762c08baea3a36/network_data.json). |
| 47 | + |
| 48 | + |
| 49 | +- **hostSelector** -- Specify criteria for matching labels on `BareMetalHost` |
| 50 | + objects. This can be used to limit the set of available `BareMetalHost` |
| 51 | + objects chosen for this `Machine`. |
| 52 | + |
| 53 | + |
| 54 | +- **automatedCleaningMode** -- An interface to enable or disable Ironic |
| 55 | + automated cleaning during provisioning or deprovisioning of a host. When set |
| 56 | + to `disabled`, automated cleaning will be skipped, where `metadata` value |
| 57 | + enables it. It is recommended to tune the cleaning via metal3MachineTemplate |
| 58 | + rather than metal3Machine. When `spec.template.spec.automatedCleaningMode` |
| 59 | + field of metal3MachineTemplate is updated, metal3MachineTemplate controller |
| 60 | + will update all the metal3Machines (generated from the metal3MachineTemplate) |
| 61 | + and eventually BareMetalHosts with the same value. |
| 62 | + |
| 63 | + |
| 64 | +The `metaData` and `networkData` field in the `spec` section are for the user to |
| 65 | +give directly a secret to use as metaData or networkData. The `userData`, |
| 66 | +`metaData` and `networkData` fields in the `status` section are for the |
| 67 | +controller to store the reference to the secret that is actually being used, |
| 68 | +whether it is from one of the spec fields, or somehow generated. This is aimed |
| 69 | +at making a clear difference between the desired state from the user (whether it |
| 70 | +is with a DataTemplate reference, or direct `metaData` or `userData` secrets) |
| 71 | +and what the controller is actually using. |
| 72 | + |
| 73 | + |
| 74 | +The `dataTemplate` field consists of an object reference to a Metal3DataTemplate |
| 75 | +object containing the templates for the metadata and network data generation for |
| 76 | +this Metal3Machine. The `renderedData` field is a reference to the Metal3Data |
| 77 | +object created for this machine. If the dataTemplate field is set but either the |
| 78 | +`renderedData`, `metaData` or `networkData` fields in the status are unset, then |
| 79 | +the Metal3Machine controller will wait until it can find the Metal3Data object |
| 80 | +and the rendered secrets. It will then populate those fields. |
| 81 | + |
| 82 | + |
| 83 | +When CAPM3 controller will set the different fields in the BareMetalHost, it |
| 84 | +will reference the metadata secret and the network data secret in the |
| 85 | +BareMetalHost. If any of the `metaData` or `networkData` status fields are |
| 86 | +unset, that field will also remain unset on the BareMetalHost. |
| 87 | + |
| 88 | + |
| 89 | +When the Metal3Machine gets deleted, the CAPM3 controller will remove its |
| 90 | +ownerreference from the data template object. This will trigger the deletion of |
| 91 | +the generated Metal3Data object and the secrets generated for this machine. |
| 92 | + |
| 93 | + |
| 94 | +### hostSelector Examples |
| 95 | + |
| 96 | + |
| 97 | +The `hostSelector field has two possible optional sub-fields: |
| 98 | + |
| 99 | + |
| 100 | +- **matchLabels** -- Key/value pairs of labels that must match exactly. |
| 101 | + |
| 102 | + |
| 103 | +- **matchExpressions** -- A set of expressions that must evaluate to true for |
| 104 | + the labels on a `BareMetalHost`. |
| 105 | + |
| 106 | + |
| 107 | +Valid operators include: |
| 108 | + |
| 109 | + |
| 110 | +- **!** -- Key does not exist. Values ignored. |
| 111 | +- **=** -- Key equals specified value. There must only be one value specified. |
| 112 | +- **==** -- Key equals specified value. There must only be one value specified. |
| 113 | +- **in** -- Value is a member of a set of possible values |
| 114 | +- **!=** -- Key does not equal the specified value. There must only be one value |
| 115 | + specified. |
| 116 | +- **notin** -- Value not a member of the specified set of values. |
| 117 | +- **exists** -- Key exists. Values ignored. |
| 118 | +- **gt** -- Value is greater than the one specified. Value must be an integer. |
| 119 | +- **lt** -- Value is less than the one specified. Value must be an integer. |
| 120 | + |
| 121 | + |
| 122 | +Example 1: Only consider a `BareMetalHost` with label `key1` set to `value1`. |
| 123 | + |
| 124 | + |
| 125 | +```yaml |
| 126 | +spec: |
| 127 | + providerSpec: |
| 128 | + value: |
| 129 | + hostSelector: |
| 130 | + matchLabels: |
| 131 | + key1: value1 |
| 132 | +``` |
| 133 | +
|
| 134 | +
|
| 135 | +Example 2: Only consider `BareMetalHost` with both `key1` set to `value1` AND |
| 136 | +`key2` set to `value2`. |
| 137 | + |
| 138 | + |
| 139 | +```yaml |
| 140 | +spec: |
| 141 | + providerSpec: |
| 142 | + value: |
| 143 | + hostSelector: |
| 144 | + matchLabels: |
| 145 | + key1: value1 |
| 146 | + key2: value2 |
| 147 | +``` |
| 148 | + |
| 149 | + |
| 150 | +Example 3: Only consider `BareMetalHost` with `key3` set to either `a`, `b`, or |
| 151 | +`c`. |
| 152 | + |
| 153 | + |
| 154 | +```yaml |
| 155 | +spec: |
| 156 | + providerSpec: |
| 157 | + value: |
| 158 | + hostSelector: |
| 159 | + matchExpressions: |
| 160 | + - key: key3 |
| 161 | + operator: in |
| 162 | + values: [‘a’, ‘b’, ‘c’] |
| 163 | +``` |
| 164 | + |
| 165 | + |
| 166 | +Example 3: Only consider `BareMetalHost` with `key1` set to `value1` AND `key2` |
| 167 | +set to `value2` AND `key3` set to either `a`, `b`, or `c`. |
| 168 | + |
| 169 | + |
| 170 | +```yaml |
| 171 | +spec: |
| 172 | + providerSpec: |
| 173 | + value: |
| 174 | + hostSelector: |
| 175 | + matchLabels: |
| 176 | + key1: value1 |
| 177 | + key2: value2 |
| 178 | + matchExpressions: |
| 179 | + - key: key3 |
| 180 | + operator: in |
| 181 | + values: [‘a’, ‘b’, ‘c’] |
| 182 | +``` |
| 183 | + |
| 184 | + |
| 185 | +### Metal3Machine example |
| 186 | + |
| 187 | + |
| 188 | +```yaml |
| 189 | +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 |
| 190 | +kind: Metal3Machine |
| 191 | +metadata: |
| 192 | + name: controlplane-0 |
| 193 | + namespace: metal3 |
| 194 | +spec: |
| 195 | + automatedCleaningMode: metadata |
| 196 | + image: |
| 197 | + checksum: http://172.22.0.1/images/UBUNTU_22.04_NODE_IMAGE_K8S_v1.29.0-raw.img.sha256sum |
| 198 | + checksumType: sha256 |
| 199 | + format: raw |
| 200 | + url: http://172.22.0.1/images/UBUNTU_22.04_NODE_IMAGE_K8S_v1.29.0-raw.img |
| 201 | + hostSelector: |
| 202 | + matchLabels: |
| 203 | + key1: value1 |
| 204 | + matchExpressions: |
| 205 | + key: key2 |
| 206 | + operator: in |
| 207 | + values: { ‘abc’, ‘123’, ‘value2’ } |
| 208 | + dataTemplate: |
| 209 | + Name: controlplane-metadata |
| 210 | + metaData: |
| 211 | + Name: controlplane-0-metadata-0 |
| 212 | +``` |
0 commit comments