mirror of
https://github.com/openshift/installer.git
synced 2026-02-06 00:48:45 +01:00
pkg/destroy/libvirt: Use prefix-based deletion
To avoid wiping out the caller's whole libvirt environment, regardless
of whether it was associated with our cluster or not. Using
cluster-name prefixes still makes me a bit jumpy, so I've added
warnings to both the environment-variable and asset-prompt docs
warning libvirt users to pick something sufficiently unique.
Also:
* Use {cluster-name}-master-{count} naming. We used to use
master{count}, which diverged from other usage (e.g. AWS, which has
used master-{count} since way back in ca443c5e (openstack/nova:
replace cloud-init with ignition, 2017-02-27,
coreos/tectonic-installer#7).
* Rename module.libvirt_base_volume -> module.volume. There's no
reason to diverge from the module source for that name.
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
@@ -2,17 +2,18 @@ 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}"
|
||||
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}"
|
||||
@@ -20,17 +21,17 @@ module "bootstrap" {
|
||||
|
||||
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}"
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
resource "libvirt_volume" "coreos_base" {
|
||||
name = "coreos_base"
|
||||
name = "${var.cluster_name}-base"
|
||||
source = "${var.image}"
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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,
|
||||
@@ -69,10 +69,10 @@ func provider(clusterName string, platform *libvirt.Platform, name string) *libv
|
||||
},
|
||||
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: clusterName,
|
||||
NetworkInterfaceAddress: platform.Network.IPRange,
|
||||
|
||||
@@ -209,7 +209,7 @@ func deleteNetwork(conn *libvirt.Connect, filter filterFunc, logger logrus.Field
|
||||
func New(logger logrus.FieldLogger, metadata *types.ClusterMetadata) (destroy.Destroyer, error) {
|
||||
return &ClusterUninstaller{
|
||||
LibvirtURI: metadata.ClusterPlatformMetadata.Libvirt.URI,
|
||||
Filter: AlwaysTrueFilter(), //TODO: change to ClusterNamePrefixFilter when all resources are prefixed.
|
||||
Filter: ClusterNamePrefixFilter(metadata.ClusterName),
|
||||
Logger: logger,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user