Skip to content
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.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions data/data/install.openshift.io_installconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,14 @@ spec:
VM. Total CPUs is (Sockets * Cores)
format: int32
type: integer
threads:
description: Threads is the number of CPU threads.
format: int32
type: integer
required:
- cores
- sockets
- threads
type: object
format:
description: Format is the disk format that the disks are
Expand Down Expand Up @@ -1200,9 +1205,14 @@ spec:
Total CPUs is (Sockets * Cores)
format: int32
type: integer
threads:
description: Threads is the number of CPU threads.
format: int32
type: integer
required:
- cores
- sockets
- threads
type: object
format:
description: Format is the disk format that the disks are
Expand Down Expand Up @@ -2659,9 +2669,14 @@ spec:
Total CPUs is (Sockets * Cores)
format: int32
type: integer
threads:
description: Threads is the number of CPU threads.
format: int32
type: integer
required:
- cores
- sockets
- threads
type: object
format:
description: Format is the disk format that the disks are
Expand Down
46 changes: 33 additions & 13 deletions data/data/ovirt/bootstrap/main.tf
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
provider "ovirt" {
url = var.ovirt_url
username = var.ovirt_username
password = var.ovirt_password
cafile = var.ovirt_cafile
ca_bundle = var.ovirt_ca_bundle
insecure = var.ovirt_insecure
url = var.ovirt_url
username = var.ovirt_username
password = var.ovirt_password
tls_ca_files = var.ovirt_cafile == "" ? [] : [var.ovirt_cafile]
tls_ca_bundle = var.ovirt_ca_bundle
tls_insecure = var.ovirt_insecure
}

resource "ovirt_vm" "bootstrap" {
name = "${var.cluster_id}-bootstrap"
memory = "8192"
cores = "4"
cluster_id = var.ovirt_cluster_id
template_id = var.release_image_template_id

initialization {
custom_script = var.ignition_bootstrap
}
memory = 8 * 1024 * 1024 * 1024
cpu_cores = 4
cpu_threads = 1
cpu_sockets = 1

initialization_custom_script = var.ignition_bootstrap
}

resource "ovirt_tag" "cluster_bootstrap_tag" {
name = "${var.cluster_id}-bootstrap"
vm_ids = concat([ovirt_vm.bootstrap.id], [var.tmp_import_vm_id])
name = "${var.cluster_id}-bootstrap"
}

resource "ovirt_vm_tag" "cluster_bootstrap_tag" {
tag_id = ovirt_tag.cluster_bootstrap_tag.id
vm_id = ovirt_vm.bootstrap.id
}

resource "ovirt_vm_tag" "cluster_import_tag" {
tag_id = ovirt_tag.cluster_bootstrap_tag.id
vm_id = var.tmp_import_vm_id
}

// ovirt_vm_start starts the master nodes.
resource "ovirt_vm_start" "bootstrap" {
vm_id = ovirt_vm.bootstrap.id

depends_on = [
ovirt_vm_tag.cluster_bootstrap_tag,
ovirt_vm_tag.cluster_import_tag,
]
}
18 changes: 9 additions & 9 deletions data/data/ovirt/cluster/affinity_group/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
resource "ovirt_affinity_group" "affinity_groups" {
count = length(var.ovirt_affinity_groups)
name = var.ovirt_affinity_groups[count.index]["name"]
description = var.ovirt_affinity_groups[count.index]["description"]
cluster_id = var.ovirt_cluster_id
priority = var.ovirt_affinity_groups[count.index]["priority"]
vm_positive = false
vm_enforcing = var.ovirt_affinity_groups[count.index]["enforcing"]
lifecycle {
ignore_changes = [vm_list]
count = length(var.ovirt_affinity_groups)
cluster_id = var.ovirt_cluster_id
name = var.ovirt_affinity_groups[count.index]["name"]
description = var.ovirt_affinity_groups[count.index]["description"]
priority = var.ovirt_affinity_groups[count.index]["priority"]
enforcing = var.ovirt_affinity_groups[count.index]["enforcing"]
vms_rule {
affinity = "negative"
enforcing = var.ovirt_affinity_groups[count.index]["enforcing"]
}
}
13 changes: 7 additions & 6 deletions data/data/ovirt/cluster/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
provider "ovirt" {
url = var.ovirt_url
username = var.ovirt_username
password = var.ovirt_password
cafile = var.ovirt_cafile
ca_bundle = var.ovirt_ca_bundle
insecure = var.ovirt_insecure
url = var.ovirt_url
username = var.ovirt_username
password = var.ovirt_password
tls_ca_files = var.ovirt_cafile == "" ? [] : [var.ovirt_cafile]
tls_ca_bundle = var.ovirt_ca_bundle
tls_insecure = var.ovirt_insecure
}

module "template" {
Expand Down Expand Up @@ -32,6 +32,7 @@ module "masters" {
ovirt_master_instance_type_id = var.ovirt_master_instance_type_id
ovirt_master_cores = var.ovirt_master_cores
ovirt_master_sockets = var.ovirt_master_sockets
ovirt_master_threads = var.ovirt_master_threads
ovirt_master_memory = var.ovirt_master_memory
ovirt_master_vm_type = var.ovirt_master_vm_type
ovirt_master_os_disk_size_gb = var.ovirt_master_os_disk_gb
Expand Down
128 changes: 107 additions & 21 deletions data/data/ovirt/cluster/masters/main.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
data "ovirt_template_disk_attachments" "master" {
template_id = var.ovirt_template_id
}

data "ovirt_cluster_hosts" "master" {
cluster_id = var.ovirt_cluster_id
}

data "ovirt_affinity_group" "master" {
count = var.ovirt_master_affinity_groups == null ? 0 : length(var.ovirt_master_affinity_groups)
cluster_id = var.ovirt_cluster_id
name = var.ovirt_master_affinity_groups[count.index]
depends_on = [var.ovirt_affinity_group_count]
}

locals {
vm_affinity_groups = [
for pair in setproduct(data.ovirt_affinity_group.master.*.id, ovirt_vm.master.*.id) : {
affinity_group_id = pair[0]
vm_id = pair[1]
}
]
}

resource "ovirt_vm_affinity_group" "master" {
count = length(local.vm_affinity_groups)
vm_id = local.vm_affinity_groups[count.index].vm_id
cluster_id = var.ovirt_cluster_id
affinity_group_id = local.vm_affinity_groups[count.index].affinity_group_id
}

// ovirt_vm creates the master nodes
resource "ovirt_vm" "master" {
count = var.master_count
name = "${var.cluster_id}-master-${count.index}"
cluster_id = var.ovirt_cluster_id
template_id = var.ovirt_template_id
instance_type_id = var.ovirt_master_instance_type_id
type = var.ovirt_master_vm_type
cores = var.ovirt_master_cores
sockets = var.ovirt_master_sockets
instance_type_id = var.ovirt_master_instance_type_id != "" ? var.ovirt_master_instance_type_id : null
vm_type = var.ovirt_master_vm_type
cpu_cores = var.ovirt_master_cores
cpu_sockets = var.ovirt_master_sockets
cpu_threads = var.ovirt_master_threads

// if instance type is declared then memory is redundant. Since terraform
// doesn't allow to condionally omit it, it must be passed.
// doesn't allow to conditionally omit it, it must be passed.
// The number passed is multiplied by 4 and becomes the maximum memory the VM can have.
memory = var.ovirt_master_instance_type_id != "" ? 16348 : var.ovirt_master_memory
affinity_groups = var.ovirt_master_affinity_groups
auto_pinning_policy = var.ovirt_master_auto_pinning_policy != "" ? var.ovirt_master_auto_pinning_policy : null
hugepages = var.ovirt_master_hugepages > 0 ? var.ovirt_master_hugepages : null
memory = var.ovirt_master_instance_type_id != "" || var.ovirt_master_memory == "" ? 16348 * 1024 * 1024 : tonumber(var.ovirt_master_memory) * 1024 * 1024

huge_pages = var.ovirt_master_hugepages > 0 ? var.ovirt_master_hugepages : null
serial_console = var.ovirt_master_vm_type == "high_performance" ? true : null
memory_ballooning = var.ovirt_master_vm_type == "high_performance" ? false : null
cpu_mode = var.ovirt_master_vm_type == "high_performance" ? "host_passthrough" : null

# Here we check if the ovirt_master_clone is set and use that as a bool if yes, default to the VM type otherwise.
#
Expand All @@ -22,23 +58,73 @@ resource "ovirt_vm" "master" {
# VM type server or high performance -> clone = true
clone = var.ovirt_master_clone != null ? tobool(var.ovirt_master_clone) : (var.ovirt_master_vm_type == "desktop" ? false : true)

initialization {
host_name = "${var.cluster_id}-master-${count.index}"
custom_script = var.ignition_master
}
# Initialization sets the host name and script run when the machine first starts.
initialization_hostname = "${var.cluster_id}-master-${count.index}"
initialization_custom_script = var.ignition_master

block_device {
interface = "virtio_scsi"
size = var.ovirt_master_os_disk_size_gb
format = var.ovirt_master_format != "" ? var.ovirt_master_format : null
sparse = tobool(var.ovirt_master_sparse)
storage_domain = var.ovirt_storage_domain_id
# Placement policy dictates which hosts this master can run on.
#
# TODO there may be a bug here since we are pinning the masters to the existing detected hosts and this is never
# updated.
placement_policy_affinity = var.ovirt_master_auto_pinning_policy != "" && var.ovirt_master_auto_pinning_policy != "none" ? "migratable" : null
placement_policy_host_ids = var.ovirt_master_auto_pinning_policy != "" && var.ovirt_master_auto_pinning_policy != "none" ? data.ovirt_cluster_hosts.master.hosts.*.id : null

# This section overrides the format and sparse option for the disks from the template.
dynamic "template_disk_attachment_override" {
for_each = data.ovirt_template_disk_attachments.master.disk_attachments
content {
disk_id = template_disk_attachment_override.value.disk_id
format = var.ovirt_master_format != "" ? var.ovirt_master_format : null
provisioning = var.ovirt_master_sparse == null ? null : (tobool(var.ovirt_master_sparse) ? "sparse" : "non-sparse")
}
}
depends_on = [var.ovirt_affinity_group_count]
}

data "ovirt_disk_attachments" "master" {
count = var.master_count
vm_id = ovirt_vm.master.*.id[count.index]
}

// ovirt_vm_disks_resize resizes the master disks to the specified size.
resource "ovirt_vm_disks_resize" "master" {
count = var.master_count
vm_id = ovirt_vm.master.*.id[count.index]
size = var.ovirt_master_os_disk_size_gb * 1024 * 1024 * 1024
}

// ovirt_vm_graphic_consoles removes the graphic consoles from non-desktop machines.
resource "ovirt_vm_graphics_consoles" "master" {
count = var.ovirt_master_vm_type == "high_performance" ? var.master_count : 0
vm_id = ovirt_vm.master.*.id[count.index]
}

// ovirt_vm_optimize_cpu_settings auto-optimizes CPU and NUMA alignment on server and HP types
resource "ovirt_vm_optimize_cpu_settings" "master" {
count = var.ovirt_master_auto_pinning_policy != "" && var.ovirt_master_auto_pinning_policy != "none" ? var.master_count : 0
vm_id = ovirt_vm.master.*.id[count.index]
}

// ovirt_vm_start starts the master nodes.
resource "ovirt_vm_start" "master" {
count = var.master_count
vm_id = ovirt_vm.master.*.id[count.index]

depends_on = [
ovirt_vm_graphics_consoles.master,
ovirt_vm_optimize_cpu_settings.master,
ovirt_vm_disks_resize.master,
ovirt_vm_tag.master,
ovirt_vm_affinity_group.master,
]
}

resource "ovirt_tag" "cluster_tag" {
name = var.cluster_id
vm_ids = [for instance in ovirt_vm.master.* : instance.id]
name = var.cluster_id
}

resource "ovirt_vm_tag" "master" {
count = length(ovirt_vm.master)
tag_id = ovirt_tag.cluster_tag.id
vm_id = ovirt_vm.master.*.id[count.index]
}
2 changes: 1 addition & 1 deletion data/data/ovirt/cluster/masters/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "control_plane_vm_ids" {
value = ovirt_vm.master.*.id
value = ovirt_vm_start.master.*.vm_id
}
10 changes: 10 additions & 0 deletions data/data/ovirt/cluster/masters/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@ variable "ignition_master" {
variable "ovirt_master_memory" {
type = string
description = "master VM memory in MiB"
default = 16348 * 1024 * 1024
}

variable "ovirt_master_cores" {
type = string
description = "master VM number of cores"
default = 1
}

variable "ovirt_master_sockets" {
type = string
description = "master VM number of sockets"
default = 1
}

variable "ovirt_master_threads" {
type = string
description = "master VM number of threads"
default = 1
}

variable "ovirt_master_os_disk_size_gb" {
Expand All @@ -60,6 +69,7 @@ variable "ovirt_master_instance_type_id" {
variable "ovirt_master_affinity_groups" {
type = list(string)
description = "master VMs affinity groups names"
default = []
}

//TODO: REMOVE once we port to TF 0.13 and can use depends_on modules
Expand Down
10 changes: 2 additions & 8 deletions data/data/ovirt/cluster/template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@ resource "ovirt_template" "releaseimage_template" {
// name the template after the openshift cluster id
name = local.image_name
description = "Template in use by OpenShift. Do not delete!"
cluster_id = var.ovirt_cluster_id
// create from vm
vm_id = var.tmp_import_vm_id
timeouts {
create = "20m"
}
}

// existing template provided by the user
data "ovirt_templates" "finalTemplate" {
count = var.tmp_import_vm_id == "" ? 1 : 0

search = {
criteria = "name=${var.openstack_base_image_name}"
case_sensitive = true
}
fail_on_empty = true
name = var.openstack_base_image_name
}
2 changes: 1 addition & 1 deletion data/data/ovirt/cluster/template/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "releaseimage_template_id" {
value = var.tmp_import_vm_id == "" ? data.ovirt_templates.finalTemplate.0.templates.0.id : ovirt_template.releaseimage_template.0.id
value = var.tmp_import_vm_id == "" ? one(data.ovirt_templates.finalTemplate.0.templates.*.id) : ovirt_template.releaseimage_template.0.id
}
Loading