Skip to content

Commit

Permalink
libvirt: Use custom storage pool
Browse files Browse the repository at this point in the history
Don't assume `default` storage pool and create a new custom one.

Fixes openshift#1457.
  • Loading branch information
zeenix committed Jul 9, 2019
1 parent 74546e6 commit 53bdc3e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions data/data/libvirt/bootstrap/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
resource "libvirt_volume" "bootstrap" {
name = "${var.cluster_id}-bootstrap"
base_volume_id = var.base_volume_id
pool = var.pool
}

resource "libvirt_ignition" "bootstrap" {
name = "${var.cluster_id}-bootstrap.ign"
content = var.ignition
pool = var.pool
}

resource "libvirt_domain" "bootstrap" {
Expand Down
4 changes: 4 additions & 0 deletions data/data/libvirt/bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ variable "network_id" {
description = "The ID of a network resource containing the bootstrap node's addresses."
}

variable "pool" {
type = string
description = "The name of the storage pool."
}
10 changes: 10 additions & 0 deletions data/data/libvirt/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ provider "libvirt" {
uri = var.libvirt_uri
}

resource "libvirt_pool" "storage_pool" {
name = var.cluster_id
type = "dir"
path = "/var/lib/libvirt/images/${var.cluster_id}"
}

module "volume" {
source = "./volume"

cluster_id = var.cluster_id
image = var.os_image
pool = libvirt_pool.storage_pool.name
}

module "bootstrap" {
Expand All @@ -17,17 +24,20 @@ module "bootstrap" {
cluster_id = var.cluster_id
ignition = var.ignition_bootstrap
network_id = libvirt_network.net.id
pool = libvirt_pool.storage_pool.name
}

resource "libvirt_volume" "master" {
count = var.master_count
name = "${var.cluster_id}-master-${count.index}"
base_volume_id = module.volume.coreos_base_volume_id
pool = libvirt_pool.storage_pool.name
}

resource "libvirt_ignition" "master" {
name = "${var.cluster_id}-master.ign"
content = var.ignition_master
pool = libvirt_pool.storage_pool.name
}

resource "libvirt_network" "net" {
Expand Down
2 changes: 1 addition & 1 deletion data/data/libvirt/volume/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "libvirt_volume" "coreos_base" {
name = "${var.cluster_id}-base"
source = var.image
pool = var.pool
}

4 changes: 4 additions & 0 deletions data/data/libvirt/volume/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ variable "image" {
type = string
}

variable "pool" {
type = string
description = "The name of the storage pool."
}
2 changes: 1 addition & 1 deletion pkg/asset/machines/libvirt/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func provider(clusterID string, networkInterfaceAddress string, platform *libvir
UserDataSecret: userDataSecret,
},
Volume: &libvirtprovider.Volume{
PoolName: "default",
PoolName: clusterID,
BaseVolumeID: fmt.Sprintf("%s-base", clusterID),
},
NetworkInterfaceName: clusterID,
Expand Down

0 comments on commit 53bdc3e

Please sign in to comment.