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

pkg/destroy/libvirt: Use prefix-based deletion #660

Merged
merged 3 commits into from
Nov 13, 2018
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions data/data/libvirt/bootstrap/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
resource "libvirt_volume" "bootstrap" {
name = "bootstrap"
name = "${var.cluster_name}-bootstrap"
base_volume_id = "${var.base_volume_id}"
}

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

resource "libvirt_domain" "bootstrap" {
name = "bootstrap"
name = "${var.cluster_name}-bootstrap"

memory = "2048"

Expand Down
19 changes: 10 additions & 9 deletions data/data/libvirt/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,41 @@ provider "libvirt" {
uri = "${var.tectonic_libvirt_uri}"
}

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

image = "${var.tectonic_os_image}"
cluster_name = "${var.tectonic_cluster_name}"
wking marked this conversation as resolved.
Show resolved Hide resolved
image = "${var.tectonic_os_image}"
}

module "bootstrap" {
source = "./bootstrap"

addresses = ["${var.tectonic_libvirt_bootstrap_ip}"]
base_volume_id = "${module.libvirt_base_volume.coreos_base_volume_id}"
base_volume_id = "${module.volume.coreos_base_volume_id}"
cluster_name = "${var.tectonic_cluster_name}"
ignition = "${var.ignition_bootstrap}"
network_id = "${libvirt_network.tectonic_net.id}"
}

resource "libvirt_volume" "master" {
count = "${var.tectonic_master_count}"
name = "master${count.index}"
base_volume_id = "${module.libvirt_base_volume.coreos_base_volume_id}"
name = "${var.tectonic_cluster_name}-master-${count.index}"
base_volume_id = "${module.volume.coreos_base_volume_id}"
}

resource "libvirt_ignition" "master" {
name = "master.ign"
name = "${var.tectonic_cluster_name}-master.ign"
content = "${var.ignition_master}"
}

resource "libvirt_ignition" "worker" {
name = "worker.ign"
name = "${var.tectonic_cluster_name}-worker.ign"
content = "${var.ignition_worker}"
}

resource "libvirt_network" "tectonic_net" {
name = "${var.tectonic_libvirt_network_name}"
name = "${var.tectonic_cluster_name}"

mode = "nat"
bridge = "${var.tectonic_libvirt_network_if}"
Expand Down Expand Up @@ -67,7 +68,7 @@ resource "libvirt_network" "tectonic_net" {
resource "libvirt_domain" "master" {
count = "${var.tectonic_master_count}"

name = "master${count.index}"
name = "${var.tectonic_cluster_name}-master-${count.index}"

memory = "3072"
vcpu = "2"
Expand Down
5 changes: 0 additions & 5 deletions data/data/libvirt/variables-libvirt.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ variable "tectonic_libvirt_uri" {
description = "libvirt connection URI"
}

variable "tectonic_libvirt_network_name" {
type = "string"
description = "Name of the libvirt network to create"
}

variable "tectonic_libvirt_network_if" {
type = "string"
description = "The name of the bridge to use"
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,4 +1,4 @@
resource "libvirt_volume" "coreos_base" {
name = "coreos_base"
name = "${var.cluster_name}-base"
source = "${var.image}"
}
5 changes: 5 additions & 0 deletions data/data/libvirt/volume/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
variable "cluster_name" {
type = "string"
description = "The name of the cluster."
}

variable "image" {
description = "The URL of the OS disk image"
type = "string"
Expand Down
3 changes: 3 additions & 0 deletions docs/user/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ The installer accepts a number of environment variable that allow the interactiv
* `OPENSHIFT_INSTALL_CLUSTER_NAME`:
The name of the cluster.
This will be used when generating sub-domains.

For libvirt, choose a name that is unique enough to be used as a prefix during cluster deletion.
For example, if you use `demo` as your cluster name, `openshift-install destroy cluster` may destroy all domains, networks, pools, and volumes that begin with `demo`.
* `OPENSHIFT_INSTALL_EMAIL_ADDRESS`:
The email address of the cluster administrator.
This will be used to log in to the console.
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/clustername.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (a *clusterName) Generate(asset.Parents) error {
&survey.Question{
Prompt: &survey.Input{
Message: "Cluster Name",
Help: "The name of the cluster. This will be used when generating sub-domains.",
Help: "The name of the cluster. This will be used when generating sub-domains.\n\nFor libvirt, choose a name that is unique enough to be used as a prefix during cluster deletion. For example, if you use 'demo' as your cluster name, `openshift-install destroy cluster` may destroy all domains, networks, pools, and volumes that begin with 'demo'.",
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
return validate.DomainName(ans.(string))
Expand Down
1 change: 0 additions & 1 deletion pkg/asset/installconfig/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (a *InstallConfig) Generate(parents asset.Parents) error {
a.Config.OpenStack = platform.OpenStack
case platform.Libvirt != nil:
a.Config.Libvirt = platform.Libvirt
a.Config.Libvirt.Network.Name = clusterName.ClusterName
numberOfMasters = 1
numberOfWorkers = 1
default:
Expand Down
12 changes: 6 additions & 6 deletions pkg/asset/machines/libvirt/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDa
if pool.Replicas != nil {
total = *pool.Replicas
}
provider := provider(platform, pool.Name)
provider := provider(clustername, platform, pool.Name)
var machines []clusterapi.Machine
for idx := int64(0); idx < total; idx++ {
machine := clusterapi.Machine{
Expand All @@ -41,7 +41,7 @@ func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDa
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-cluster-api",
Name: fmt.Sprintf("%s%d", pool.Name, idx),
Name: fmt.Sprintf("%s-%s-%d", clustername, pool.Name, idx),
Labels: map[string]string{
"sigs.k8s.io/cluster-api-cluster": clustername,
"sigs.k8s.io/cluster-api-machine-role": role,
Expand All @@ -61,20 +61,20 @@ func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDa
return machines, nil
}

func provider(platform *libvirt.Platform, name string) *libvirtprovider.LibvirtMachineProviderConfig {
func provider(clusterName string, platform *libvirt.Platform, name string) *libvirtprovider.LibvirtMachineProviderConfig {
return &libvirtprovider.LibvirtMachineProviderConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "libvirtproviderconfig.k8s.io/v1alpha1",
Kind: "LibvirtMachineProviderConfig",
},
DomainMemory: 2048,
DomainVcpu: 2,
IgnKey: fmt.Sprintf("/var/lib/libvirt/images/%s.ign", name),
IgnKey: fmt.Sprintf("/var/lib/libvirt/images/%s-%s.ign", clusterName, name),
Volume: &libvirtprovider.Volume{
PoolName: "default",
BaseVolumeID: "/var/lib/libvirt/images/coreos_base",
BaseVolumeID: fmt.Sprintf("/var/lib/libvirt/images/%s-base", clusterName),
},
NetworkInterfaceName: platform.Network.Name,
NetworkInterfaceName: clusterName,
NetworkInterfaceAddress: platform.Network.IPRange,
Autostart: false,
URI: platform.URI,
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/machines/libvirt/machinesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func MachineSets(config *types.InstallConfig, pool *types.MachinePool, role, use
total = *pool.Replicas
}

provider := provider(platform, pool.Name)
provider := provider(clustername, platform, pool.Name)
name := fmt.Sprintf("%s-%s-%d", clustername, pool.Name, 0)
mset := clusterapi.MachineSet{
TypeMeta: metav1.TypeMeta{
Expand Down
Loading