Skip to content

Commit f454938

Browse files
author
Anna Blendermann
committed
Add vm node affinity support for rancher 2.6
1 parent d545a0d commit f454938

6 files changed

Lines changed: 31 additions & 1 deletion

docs/resources/machine_config_v2.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ page_title: "rancher2_machine_config_v2 Resource"
66

77
Provides a Rancher v2 Machine config v2 resource. This can be used to create Machine Config v2 for Rancher v2 and retrieve their information. This resource is available from Rancher v2.6.0 and above.
88

9-
`amazonec2`, `azure`, `digitalocean`, `linode`, `openstack`, and `vsphere` cloud providers are supported for machine config V2
9+
`amazonec2`, `azure`, `digitalocean`, `harvester`, `linode`, `openstack`, and `vsphere` cloud providers are supported for machine config V2
1010

1111
**Note** This resource is used by
1212

@@ -196,6 +196,7 @@ The following attributes are exported:
196196
* `network_model` - (Optional) Network model, Default `virtio` (string)
197197
* `user_data` - (Optional) UserData content of cloud-init, base64 is supported (string)
198198
* `network_data` - (Optional) NetworkData content of cloud-init, base64 is supported (string)
199+
* `vm_affinity` - (Optional) Virtual machine affinity, base64 is supported. For Rancher v2.6.7 or above (string)
199200

200201
### `linode_config`
201202

docs/resources/node_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ The following attributes are exported:
264264
* `network_model` - (Optional) Network model, Default `virtio` (string)
265265
* `user_data` - (Optional) UserData content of cloud-init, base64 is supported (string)
266266
* `network_data` - (Optional) NetworkData content of cloud-init, base64 is supported (string)
267+
* `vm_affinity` - (Optional) Virtual machine affinity, base64 is supported. For Rancher v2.6.7 or above (string)
267268

268269
### `hetzner_config`
269270

rancher2/schema_machine_config_v2_harvester.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ func machineConfigV2HarvesterFields() map[string]*schema.Schema {
1414
Required: true,
1515
Description: "Virtual machine namespace",
1616
},
17+
"vm_affinity": {
18+
Type: schema.TypeString,
19+
Optional: true,
20+
Description: "VM affinity, base64 is supported",
21+
},
1722
"cpu_count": {
1823
Type: schema.TypeString,
1924
Optional: true,

rancher2/schema_node_template_harvester.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424

2525
type harvesterConfig struct {
2626
VMNamespace string `json:"vmNamespace,omitempty" yaml:"vmNamespace,omitempty"`
27+
VMAffinity string `json:"vmAffinity,omitempty" yaml:"vmAffinity,omitempty"`
2728
CPUCount string `json:"cpuCount,omitempty" yaml:"cpuCount,omitempty"`
2829
MemorySize string `json:"memorySize,omitempty" yaml:"memorySize,omitempty"`
2930
DiskSize string `json:"diskSize,omitempty" yaml:"diskSize,omitempty"`
@@ -46,6 +47,11 @@ func harvesterConfigFields() map[string]*schema.Schema {
4647
Required: true,
4748
Description: "Virtual machine namespace",
4849
},
50+
"vm_affinity": {
51+
Type: schema.TypeString,
52+
Optional: true,
53+
Description: "VM affinity, base64 is supported",
54+
},
4955
"cpu_count": {
5056
Type: schema.TypeString,
5157
Optional: true,

rancher2/structure_machine_config_v2_harvester.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type machineConfigV2Harvester struct {
1818
metav1.TypeMeta `json:",inline"`
1919
metav1.ObjectMeta `json:"metadata,omitempty"`
2020
VMNamespace string `json:"vmNamespace,omitempty" yaml:"vmNamespace,omitempty"`
21+
VMAffinity string `json:"vmAffinity,omitempty" yaml:"vmAffinity,omitempty"`
2122
CPUCount string `json:"cpuCount,omitempty" yaml:"cpuCount,omitempty"`
2223
MemorySize string `json:"memorySize,omitempty" yaml:"memorySize,omitempty"`
2324
DiskSize string `json:"diskSize,omitempty" yaml:"diskSize,omitempty"`
@@ -49,6 +50,10 @@ func flattenMachineConfigV2Harvester(in *MachineConfigV2Harvester) []interface{}
4950
obj["vm_namespace"] = in.VMNamespace
5051
}
5152

53+
if len(in.VMAffinity) > 0 {
54+
obj["vm_affinity"] = in.VMAffinity
55+
}
56+
5257
if len(in.CPUCount) > 0 {
5358
obj["cpu_count"] = in.CPUCount
5459
}
@@ -118,6 +123,10 @@ func expandMachineConfigV2Harvester(p []interface{}, source *MachineConfigV2) *M
118123
obj.VMNamespace = v
119124
}
120125

126+
if v, ok := in["vm_affinity"].(string); ok && len(v) > 0 {
127+
obj.VMAffinity = v
128+
}
129+
121130
if v, ok := in["cpu_count"].(string); ok && len(v) > 0 {
122131
obj.CPUCount = v
123132
}

rancher2/structure_node_template_harvester.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ func flattenHarvesterConfig(in *harvesterConfig) []interface{} {
1212
obj["vm_namespace"] = in.VMNamespace
1313
}
1414

15+
if len(in.VMAffinity) > 0 {
16+
obj["vm_affinity"] = in.VMAffinity
17+
}
18+
1519
if len(in.CPUCount) > 0 {
1620
obj["cpu_count"] = in.CPUCount
1721
}
@@ -72,6 +76,10 @@ func expandHarvestercloudConfig(p []interface{}) *harvesterConfig {
7276
obj.VMNamespace = v
7377
}
7478

79+
if v, ok := in["vm_affinity"].(string); ok && len(v) > 0 {
80+
obj.VMAffinity = v
81+
}
82+
7583
if v, ok := in["cpu_count"].(string); ok && len(v) > 0 {
7684
obj.CPUCount = v
7785
}

0 commit comments

Comments
 (0)