Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Harvester node driver to support multi nics and disks #1051

Merged
merged 3 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 58 additions & 8 deletions docs/resources/cluster_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,41 @@ resource "rancher2_machine_config_v2" "foo-harvester-v2" {
vm_namespace = "default"
cpu_count = "2"
memory_size = "4"
disk_size = "40"
network_name = "harvester-public/vlan1"
image_name = "harvester-public/image-57hzg"
disk_info = <<EOF
{
"disks": [{
"imageName": "harvester-public/image-57hzg",
"size": 40,
"bootOrder": 1
}]
}
EOF
network_info = <<EOF
{
"interfaces": [{
"networkName": "harvester-public/vlan1",
"macAddress": ""
}]
}
EOF
ssh_user = "ubuntu"
user_data = <<EOF
package_update: true
packages:
- qemu-guest-agent
- iptables
runcmd:
- - systemctl
- enable
- '--now'
- qemu-guest-agent.service
EOF
}
}

resource "rancher2_cluster_v2" "foo-harvester-v2" {
name = "foo-harvester-v2"
kubernetes_version = "v1.22.6+rke2r1"
kubernetes_version = "v1.24.10+rke2r1"
rke_config {
machine_pools {
name = "pool1"
Expand Down Expand Up @@ -347,17 +372,42 @@ resource "rancher2_machine_config_v2" "foo-harvester-v2-cloud-provider" {
vm_namespace = "default"
cpu_count = "2"
memory_size = "4"
disk_size = "40"
network_name = "harvester-public/vlan1"
image_name = "harvester-public/image-57hzg"
disk_info = <<EOF
{
"disks": [{
"imageName": "harvester-public/image-57hzg",
"size": 40,
"bootOrder": 1
}]
}
EOF
network_info = <<EOF
{
"interfaces": [{
"networkName": "harvester-public/vlan1",
"macAddress": ""
}]
}
EOF
ssh_user = "ubuntu"
user_data = <<EOF
package_update: true
packages:
- qemu-guest-agent
- iptables
runcmd:
- - systemctl
- enable
- '--now'
- qemu-guest-agent.service
EOF
}
}

# Create a new harvester rke2 cluster with harvester cloud provider
resource "rancher2_cluster_v2" "foo-harvester-v2-cloud-provider" {
name = "foo-harvester-v2-cloud-provider"
kubernetes_version = "v1.22.6+rke2r1"
kubernetes_version = "v1.24.10+rke2r1"
rke_config {
machine_pools {
name = "pool1"
Expand Down
45 changes: 36 additions & 9 deletions docs/resources/machine_config_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,35 @@ resource "rancher2_machine_config_v2" "foo-harvester-v2" {
vm_namespace = "default"
cpu_count = "2"
memory_size = "4"
disk_size = "40"
network_name = "harvester-public/vlan1"
image_name = "harvester-public/image-57hzg"
disk_info = <<EOF
{
"disks": [{
"imageName": "harvester-public/image-57hzg",
"size": 40,
"bootOrder": 1
}]
}
EOF
network_info = <<EOF
{
"interfaces": [{
"networkName": "harvester-public/vlan1",
"macAddress": ""
}]
}
EOF
ssh_user = "ubuntu"
user_data = <<EOF
package_update: true
packages:
- qemu-guest-agent
- iptables
runcmd:
- - systemctl
- enable
- '--now'
- qemu-guest-agent.service
EOF
}
}
```
Expand Down Expand Up @@ -187,14 +212,16 @@ The following attributes are exported:
* `vm_namespace` - (Required) Virtual machine namespace e.g. `default` (string)
* `cpu_count` - (Optional) CPU count, Default `2` (string)
* `memory_size` - (Optional) Memory size (in GiB), Default `4` (string)
* `disk_size` - (Optional) Disk size (in GiB), Default `40` (string)
* `disk_bus` - (Optional) Disk bus, Default `virtio` (string)
* `image_name` - (Required) Image name e.g. `harvester-public/image-57hzg` (string)
* `disk_size` - (Deprecated) Use `disk_info` instead
* `disk_bus` - (Deprecated) Use `disk_info` instead
* `image_name` - (Deprecated) Use `disk_info` instead
* `disk_info` - (Required) A JSON string specifying info for the disks e.g. `{\"disks\":[{\"imageName\":\"harvester-public/image-57hzg\",\"bootOrder\":1,\"size\":40},{\"storageClassName\":\"node-driver-test\",\"bootOrder\":2,\"size\":1}]}` (string)
* `ssh_user` - (Required) SSH username e.g. `ubuntu` (string)
* `ssh_password` - (Optional/Sensitive) SSH password (string)
* `network_name` - (Required) Network name e.g. `harvester-public/vlan1` (string)
* `network_model` - (Optional) Network model, Default `virtio` (string)
* `user_data` - (Optional) UserData content of cloud-init, base64 is supported (string)
* `network_name` - (Deprecated) Use `network_info` instead
* `network_model` - (Deprecated) Use `network_info` instead
* `network_info` - (Required) A JSON string specifying info for the networks e.g. `{\"interfaces\":[{\"networkName\":\"harvester-public/vlan1\",\"macAddress\":\"\"},{\"networkName\":\"harvester-public/vlan2\",\"macAddress\":\"5a:e7:c5:24:5b:44\"}]}` (string)
* `user_data` - (Optional) UserData content of cloud-init, base64 is supported. If the image does not contain the qemu-guest-agent package, you must install and start qemu-guest-agent using userdata (string)
* `network_data` - (Optional) NetworkData content of cloud-init, base64 is supported (string)
* `vm_affinity` - (Optional) Virtual machine affinity, base64 is supported. For Rancher v2.6.7 or above (string)

Expand Down
45 changes: 36 additions & 9 deletions docs/resources/node_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,35 @@ resource "rancher2_node_template" "foo-harvester" {
vm_namespace = "default"
cpu_count = "2"
memory_size = "4"
disk_size = "40"
network_name = "harvester-public/vlan1"
image_name = "harvester-public/image-57hzg"
disk_info = <<EOF
{
"disks": [{
"imageName": "harvester-public/image-57hzg",
"size": 40,
"bootOrder": 1
}]
}
EOF
network_info = <<EOF
{
"interfaces": [{
"networkName": "harvester-public/vlan1",
"macAddress": ""
}]
}
EOF
ssh_user = "ubuntu"
user_data = <<EOF
package_update: true
packages:
- qemu-guest-agent
- iptables
runcmd:
- - systemctl
- enable
- '--now'
- qemu-guest-agent.service
EOF
}
}
```
Expand Down Expand Up @@ -255,14 +280,16 @@ The following attributes are exported:
* `vm_namespace` - (Required) Virtual machine namespace e.g. `default` (string)
* `cpu_count` - (Optional) CPU count, Default `2` (string)
* `memory_size` - (Optional) Memory size (in GiB), Default `4` (string)
* `disk_size` - (Optional) Disk size (in GiB), Default `40` (string)
* `disk_bus` - (Optional) Disk bus, Default `virtio` (string)
* `image_name` - (Required) Image name e.g. `harvester-public/image-57hzg` (string)
* `disk_size` - (Deprecated) Use `disk_info` instead
* `disk_bus` - (Deprecated) Use `disk_info` instead
* `image_name` - (Deprecated) Use `disk_info` instead
* `disk_info` - (Required) A JSON string specifying info for the disks e.g. `{\"disks\":[{\"imageName\":\"harvester-public/image-57hzg\",\"bootOrder\":1,\"size\":40},{\"storageClassName\":\"node-driver-test\",\"bootOrder\":2,\"size\":1}]}` (string)
* `ssh_user` - (Required) SSH username e.g. `ubuntu` (string)
* `ssh_password` - (Optional/Sensitive) SSH password (string)
* `network_name` - (Required) Network name e.g. `harvester-public/vlan1` (string)
* `network_model` - (Optional) Network model, Default `virtio` (string)
* `user_data` - (Optional) UserData content of cloud-init, base64 is supported (string)
* `network_name` - (Deprecated) Use `network_info` instead
* `network_model` - (Deprecated) Use `network_info` instead
* `network_info` - (Required) A JSON string specifying info for the networks e.g. `{\"interfaces\":[{\"networkName\":\"harvester-public/vlan1\",\"macAddress\":\"\"},{\"networkName\":\"harvester-public/vlan2\",\"macAddress\":\"5a:e7:c5:24:5b:44\"}]}` (string)
* `user_data` - (Optional) UserData content of cloud-init, base64 is supported. If the image does not contain the qemu-guest-agent package, you must install and start qemu-guest-agent using userdata (string)
* `network_data` - (Optional) NetworkData content of cloud-init, base64 is supported (string)
* `vm_affinity` - (Optional) Virtual machine affinity, base64 is supported. For Rancher v2.6.7 or above (string)

Expand Down
60 changes: 56 additions & 4 deletions rancher2/resource_rancher2_node_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,36 @@ resource "` + testAccRancher2NodeTemplateType + `" "foo-harvester" {
harvester_config {
cpu_count = "2"
memory_size = "4"
image_name = "foo"
network_name = "test-net"
disk_info = <<EOF
{
"disks": [{
"imageName": "foo",
"size": 40,
"bootOrder": 1
}]
}
EOF
network_info = <<EOF
{
"interfaces": [{
"networkName": "test-net",
"macAddress": ""
}]
}
EOF
ssh_user = "ubuntu"
vm_namespace = "test"
user_data = <<EOF
package_update: true
packages:
- qemu-guest-agent
- iptables
runcmd:
- - systemctl
- enable
- '--now'
- qemu-guest-agent.service
EOF
}
}
`
Expand All @@ -116,10 +142,36 @@ resource "` + testAccRancher2NodeTemplateType + `" "foo-harvester" {
harvester_config {
cpu_count = "4"
memory_size = "8"
image_name = "foo"
network_name = "test-net"
disk_info = <<EOF
{
"disks": [{
"imageName": "foo",
"size": 40,
"bootOrder": 1
}]
}
EOF
network_info = <<EOF
{
"interfaces": [{
"networkName": "test-net",
"macAddress": ""
}]
}
EOF
ssh_user = "ubuntu"
vm_namespace = "test"
user_data = <<EOF
package_update: true
packages:
- qemu-guest-agent
- iptables
runcmd:
- - systemctl
- enable
- '--now'
- qemu-guest-agent.service
EOF
}
}
`
Expand Down
46 changes: 22 additions & 24 deletions rancher2/schema_machine_config_v2_harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rancher2

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

//Schemas
Expand Down Expand Up @@ -34,24 +33,25 @@ func machineConfigV2HarvesterFields() map[string]*schema.Schema {
"disk_size": {
Type: schema.TypeString,
Optional: true,
Default: "40",
Description: "Disk size (in GiB)",
Deprecated: "Use disk_info instead",
},
"disk_bus": {
Type: schema.TypeString,
Optional: true,
Default: harvesterDiskBusVIRTIO,
ValidateFunc: validation.StringInSlice([]string{
harvesterDiskBusVIRTIO,
harvesterDiskBusSATA,
harvesterDiskBusSCSI,
}, false),
Type: schema.TypeString,
Optional: true,
Description: "Disk bus",
Deprecated: "Use disk_info instead",
},
"image_name": {
Type: schema.TypeString,
Required: true,
Optional: true,
Description: "Image name",
Deprecated: "Use disk_info instead",
},
"disk_info": {
Type: schema.TypeString,
Required: true,
Description: "A JSON string specifying info for the disks e.g. `{\"disks\":[{\"imageName\":\"harvester-public/image-57hzg\",\"bootOrder\":1,\"size\":40},{\"storageClassName\":\"node-driver-test\",\"bootOrder\":2,\"size\":1}]}`",
},
"ssh_user": {
Type: schema.TypeString,
Expand All @@ -66,27 +66,25 @@ func machineConfigV2HarvesterFields() map[string]*schema.Schema {
},
"network_name": {
Type: schema.TypeString,
Required: true,
Optional: true,
Description: "Network name",
Deprecated: "Use network_info instead",
},
"network_model": {
Type: schema.TypeString,
Optional: true,
Default: harvesterNetworkModelVIRTIO,
ValidateFunc: validation.StringInSlice([]string{
harvesterNetworkModelVIRTIO,
harvesterNetworkModelE1000,
harvesterNetworkModelE1000E,
harvesterNetworkModelNE2KPCO,
harvesterNetworkModelPCNET,
harvesterNetworkModelRTL8139,
}, false),
Type: schema.TypeString,
Optional: true,
Description: "Network model",
Deprecated: "Use network_info instead",
},
"network_info": {
Type: schema.TypeString,
Required: true,
Description: "A JSON string specifying info for the networks e.g. `{\"interfaces\":[{\"networkName\":\"harvester-public/vlan1\",\"macAddress\":\"\"},{\"networkName\":\"harvester-public/vlan2\",\"macAddress\":\"5a:e7:c5:24:5b:44\"}]}`",
},
"user_data": {
Type: schema.TypeString,
Optional: true,
Description: "UserData content of cloud-init, base64 is supported",
Description: "UserData content of cloud-init, base64 is supported. If the image does not contain the qemu-guest-agent package, you must install and start qemu-guest-agent using userdata",
},
"network_data": {
Type: schema.TypeString,
Expand Down