Skip to content

Commit

Permalink
Merge pull request #1956 from zeenix/own-storage-pool
Browse files Browse the repository at this point in the history
Manage and use own storage pool
  • Loading branch information
openshift-merge-robot authored Jul 16, 2019
2 parents b22983c + cfcd2f4 commit b6cf548
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 46 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/openshift-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."
}
34 changes: 0 additions & 34 deletions docs/dev/libvirt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,6 @@ NOTE: When the firewall rules are no longer needed, `sudo firewall-cmd --reload`
will remove the changes made as they were not permanently added. For persistence,
add `--permanent` to the `firewall-cmd` commands and run them a second time.

### Configure default libvirt storage pool

Check to see if a default storage pool has been defined in Libvirt by running
`virsh --connect qemu:///system pool-list`. If it does not exist, create it:

```sh
sudo virsh pool-define /dev/stdin <<EOF
<pool type='dir'>
<name>default</name>
<target>
<path>/var/lib/libvirt/images</path>
</target>
</pool>
EOF

sudo virsh pool-start default
sudo virsh pool-autostart default
```

### Set up NetworkManager DNS overlay

This step allows installer and users to resolve cluster-internal hostnames from your host.
Expand Down Expand Up @@ -323,21 +304,6 @@ FATA[0019] failed to run Terraform: exit status 1
it is likely that your install configuration contains three backslashes after the protocol (e.g. `qemu+tcp:///...`), when it should only be two.
### SELinux might prevent access to image files
Configuring the storage pool to store images in a path incompatible with the SELinux policies (e.g. your home directory) might lead to the following errors:
```
Error: Error applying plan:
1 error(s) occurred:
* libvirt_domain.etcd: 1 error(s) occurred:
* libvirt_domain.etcd: Error creating libvirt domain: virError(Code=1, Domain=10, Message='internal error: process exited while connecting to monitor: 2018-07-30T22:52:54.865806Z qemu-kvm: -fw_cfg name=opt/com.coreos/config,file=/home/user/VirtualMachines/etcd.ign: can't load /home/user/VirtualMachines/etcd.ign')
```
[As described here][libvirt_selinux_issues] you can workaround by disabling SELinux, or store the images in a place well-known to work, e.g. by using the default pool.
### Random domain creation errors due to libvirt race conditon
Depending on your libvirt version you might encounter [a race condition][bugzilla_libvirt_race] leading to an error similar to:
Expand Down
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
4 changes: 2 additions & 2 deletions pkg/terraform/exec/plugins/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/terraform/exec/plugins/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ignored = [

[[constraint]]
name = "github.com/dmacvicar/terraform-provider-libvirt"
revision = "5417057da4ea76505889ce96e762bdc36dd6894e"
revision = "c0e46b59df8718cdd905b1a3fb9738b0d4905143"

[[constraint]]
name = "github.com/terraform-providers/terraform-provider-aws"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b6cf548

Please sign in to comment.