From 1ad3167b8f8c8bbabc37301709348e9b21c63e8b Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Thu, 13 Jan 2022 13:42:07 +0100 Subject: [PATCH] use storage pools --- README.md | 4 ++-- bootstrap.tf | 4 +++- lb.tf | 5 +++-- main.tf | 6 ++++++ master.tf | 4 +++- storage.tf | 7 ++++--- variables.tf | 12 ++++++------ worker.tf | 4 +++- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0980d3a..3175680 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,8 @@ dns=dnsmasq Download the required images. ```sh -curl https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.7/4.7.0/rhcos-4.7.0-x86_64-qemu.x86_64.qcow2.gz |gunzip -c > /var/lib/libvirt/images/rhcos-4.7.0-x86_64-qemu.x86_64.qcow2 -curl -Lo /var/lib/libvirt/images/centos-stream-8.qcow2 http://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2 +curl https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.9/4.9.0/rhcos-4.9.0-x86_64-qemu.x86_64.qcow2.gz |gunzip -c > /var/lib/libvirt/images/base-images/rhcos-4.9.0-x86_64-qemu.x86_64.qcow2 +curl -Lo /var/lib/libvirt/images/base-images/centos-stream-8.qcow2 http://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2 ``` ## Install diff --git a/bootstrap.tf b/bootstrap.tf index de57239..852cb22 100644 --- a/bootstrap.tf +++ b/bootstrap.tf @@ -2,14 +2,16 @@ resource "libvirt_volume" "bootstrap_disk" { name = "${local.bootstrap_name}.${var.volume_format}" count = var.bootstrap_nodes format = var.volume_format - pool = var.pool_name + pool = libvirt_pool.cluster_storage.name base_volume_name = "${var.coreos_image}.${var.volume_format}" + base_volume_pool = var.base_image_pool size = var.bootstrap_disk_size } resource "libvirt_ignition" "bootstrap_ignition" { name = "${var.cluster_name}-bootstrap-ignition" content = file("${path.module}/.clusters/${var.cluster_name}/bootstrap.ign") + pool = libvirt_pool.cluster_storage.name } locals { diff --git a/lb.tf b/lb.tf index 6f94903..f9f7b7c 100644 --- a/lb.tf +++ b/lb.tf @@ -2,7 +2,7 @@ resource "libvirt_cloudinit_disk" "lb_cloudinit" { name = "${local.lb_name}-cloudinit.iso" user_data = data.template_file.lb_user_data.rendered network_config = data.template_file.lb_network_config.rendered - pool = var.pool_name + pool = libvirt_pool.cluster_storage.name } data "template_file" "lb_user_data" { @@ -23,8 +23,9 @@ data "template_file" "lb_network_config" { resource "libvirt_volume" "lb_disk" { name = "${local.lb_name}.${var.volume_format}" format = var.volume_format - pool = var.pool_name + pool = libvirt_pool.cluster_storage.name base_volume_name = "${var.centos_image}.${var.volume_format}" + base_volume_pool = var.base_image_pool size = var.lb_disk_size } diff --git a/main.tf b/main.tf index a2d9647..083ec5a 100644 --- a/main.tf +++ b/main.tf @@ -32,6 +32,12 @@ terraform { } } +resource "libvirt_pool" "cluster_storage" { + name = var.cluster_name + type = "dir" + path = "/var/lib/libvirt/images/${var.cluster_name}" +} + locals { additional_nodes = [local.lb_node, local.storage_node] all_nodes = concat(local.additional_nodes, local.master_nodes, local.worker_nodes, local.bootstrap_nodes) diff --git a/master.tf b/master.tf index 54e1664..85f205f 100644 --- a/master.tf +++ b/master.tf @@ -2,14 +2,16 @@ resource "libvirt_volume" "master_disk" { name = "${format(local.master_format, count.index + 1)}.${var.volume_format}" count = var.master_nodes format = var.volume_format - pool = var.pool_name + pool = libvirt_pool.cluster_storage.name base_volume_name = "${var.coreos_image}.${var.volume_format}" + base_volume_pool = var.base_image_pool size = var.master_disk_size } resource "libvirt_ignition" "master_ignition" { name = "${var.cluster_name}-master-ignition" content = file("${path.module}/.clusters/${var.cluster_name}/master.ign") + pool = libvirt_pool.cluster_storage.name } locals { diff --git a/storage.tf b/storage.tf index f9cca2b..db553e6 100644 --- a/storage.tf +++ b/storage.tf @@ -2,7 +2,7 @@ resource "libvirt_cloudinit_disk" "storage_cloudinit" { name = "${local.storage_name}-cloudinit.iso" user_data = data.template_file.storage_user_data.rendered network_config = data.template_file.storage_network_config.rendered - pool = var.pool_name + pool = libvirt_pool.cluster_storage.name } data "template_file" "storage_user_data" { @@ -16,14 +16,15 @@ data "template_file" "storage_network_config" { resource "libvirt_volume" "storage_os_disk" { name = "${local.storage_name}-os.${var.volume_format}" format = var.volume_format - pool = var.pool_name + pool = libvirt_pool.cluster_storage.name base_volume_name = "${var.centos_image}.${var.volume_format}" + base_volume_pool = var.base_image_pool } resource "libvirt_volume" "storage_data_disk" { name = "${local.storage_name}-data.${var.volume_format}" format = var.volume_format - pool = var.pool_name + pool = libvirt_pool.cluster_storage.name size = var.storage_disk_size } diff --git a/variables.tf b/variables.tf index c649c05..25320e9 100644 --- a/variables.tf +++ b/variables.tf @@ -13,11 +13,6 @@ variable "bootstrap_nodes" { default = 1 } -variable "pool_name" { - type = string - default = "default" -} - variable "volume_format" { type = string default = "qcow2" @@ -30,7 +25,7 @@ variable "centos_image" { variable "coreos_image" { type = string - default = "rhcos-4.7.0-x86_64-qemu.x86_64" + default = "rhcos-4.9.0-x86_64-qemu.x86_64" } variable "cluster_name" { @@ -146,6 +141,11 @@ variable "acme_account_email" { type = string } +variable "base_image_pool" { + type = string + default = "base-images" +} + locals { master_format = "${var.cluster_name}-master-%02d" worker_format = "${var.cluster_name}-worker-%02d" diff --git a/worker.tf b/worker.tf index f4e74bb..762c71f 100644 --- a/worker.tf +++ b/worker.tf @@ -2,14 +2,16 @@ resource "libvirt_volume" "worker_disk" { name = "${format(local.worker_format, count.index + 1)}.${var.volume_format}" count = var.worker_nodes format = var.volume_format - pool = var.pool_name + pool = libvirt_pool.cluster_storage.name base_volume_name = "${var.coreos_image}.${var.volume_format}" + base_volume_pool = var.base_image_pool size = var.worker_disk_size } resource "libvirt_ignition" "worker_ignition" { name = "${var.cluster_name}-worker-ignition" content = file("${path.module}/.clusters/${var.cluster_name}/worker.ign") + pool = libvirt_pool.cluster_storage.name } locals {