Skip to content
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
10 changes: 10 additions & 0 deletions Gopkg.lock

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

9 changes: 7 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ required = [
branch = "master"
name = "golang.org/x/oauth2"

[[constraint]]
[[constraint]]
branch = "master"
name = "github.com/openshift/cluster-api-provider-gcp"

[[constraint]]
branch = "master"
name = "github.com/openshift/machine-config-operator"

[[constraint]]
[[constraint]]
name = "github.com/containers/image"
version = "2.0.0"

Expand All @@ -144,3 +144,8 @@ required = [
[[constraint]]
name = "github.com/ovirt/go-ovirt"
version = "v4.3.9"

[[constraint]]
branch = "master"
name = "github.com/openshift/machine-api-operator"
source = "github.com/openshift/machine-api-operator"
33 changes: 33 additions & 0 deletions data/data/vsphere/bootstrap/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "vsphere_virtual_machine" "vm" {
name = "${var.cluster_id}-bootstrap"
resource_pool_id = var.resource_pool
datastore_id = var.datastore
num_cpus = 4
memory = 16384
guest_id = var.guest_id
folder = var.folder
enable_disk_uuid = "true"

wait_for_guest_net_timeout = 0
wait_for_guest_net_routable = false

network_interface {
network_id = var.network
}

disk {
label = "disk0"
size = 120
}

clone {
template_uuid = var.template
}

extra_config = {
"guestinfo.ignition.config.data" = base64encode(var.ignition)
"guestinfo.ignition.config.data.encoding" = "base64"
}
tags = var.tags
}

40 changes: 40 additions & 0 deletions data/data/vsphere/bootstrap/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
variable "ignition" {
type = string
default = ""
}

variable "resource_pool" {
type = string
}

variable "folder" {
type = string
}

variable "datastore" {
type = string
}

variable "network" {
type = string
}

variable "datacenter" {
type = string
}

variable "template" {
type = string
}

variable "guest_id" {
type = string
}

variable "tags" {
type = list
}

variable "cluster_id" {
type = string
}
97 changes: 97 additions & 0 deletions data/data/vsphere/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
provider "vsphere" {
user = var.vsphere_username
password = var.vsphere_password
vsphere_server = var.vsphere_url
allow_unverified_ssl = false
}

data "vsphere_datacenter" "datacenter" {
name = var.vsphere_datacenter
}

data "vsphere_compute_cluster" "cluster" {
name = var.vsphere_cluster
datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_datastore" "datastore" {
name = var.vsphere_datastore
datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_network" "network" {
name = var.vsphere_network
datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_virtual_machine" "template" {
name = var.vsphere_template
datacenter_id = data.vsphere_datacenter.datacenter.id
}

resource "vsphere_tag_category" "category" {
name = "openshift-${var.cluster_id}"
description = "Added by openshift-install do not remove"
cardinality = "SINGLE"

associable_types = [
"VirtualMachine",
"ResourcePool",
"Folder"
]
}

resource "vsphere_tag" "tag" {
name = var.cluster_id
category_id = vsphere_tag_category.category.id
description = "Added by openshift-install do not remove"
}

resource "vsphere_folder" "folder" {
path = var.vsphere_folder
type = "vm"
datacenter_id = data.vsphere_datacenter.datacenter.id
tags = [vsphere_tag.tag.id]
}


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

ignition = var.ignition_bootstrap
resource_pool = data.vsphere_compute_cluster.cluster.resource_pool_id
datastore = data.vsphere_datastore.datastore.id
folder = vsphere_folder.folder.path
network = data.vsphere_network.network.id
datacenter = data.vsphere_datacenter.datacenter.id
template = data.vsphere_virtual_machine.template.id
guest_id = data.vsphere_virtual_machine.template.guest_id

cluster_id = var.cluster_id
tags = [vsphere_tag.tag.id]
}

module "master" {
source = "./master"

// limitation of baremetal-runtimecfg. The hostname must be master
name = "master"
instance_count = var.master_count
ignition = var.ignition_master

resource_pool = data.vsphere_compute_cluster.cluster.resource_pool_id
datastore = data.vsphere_datastore.datastore.id
folder = vsphere_folder.folder.path
network = data.vsphere_network.network.id
datacenter = data.vsphere_datacenter.datacenter.id
template = data.vsphere_virtual_machine.template.id
guest_id = data.vsphere_virtual_machine.template.guest_id
tags = [vsphere_tag.tag.id]

cluster_domain = var.cluster_domain
cluster_id = var.cluster_id
memory = var.control_plane_memory_mib
num_cpus = var.control_plane_num_cpus
disk_size = var.control_plane_disk_gib
}

28 changes: 28 additions & 0 deletions data/data/vsphere/master/ignition.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
locals {
ignition_encoded = "data:text/plain;charset=utf-8;base64,${base64encode(var.ignition)}"
}

data "ignition_file" "hostname" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the machine-api is to recreate the machine, how will it recreate this behavior?

count = var.instance_count

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need static ignition config here? post cluster creation we should be able to create a valid master instance via API by relying only on the ignition config served by the mco (machine config operator).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enxebre not sure how else we would set the hostname of the control plane nodes which is required for "baremetal networking" which we are using with vSphere IPI.
https://github.com/openshift/enhancements/pull/148/files#diff-141f756d80782cc4aa106f6b3d264f2dR208

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the template's linux-costomization-options to set hostname?
https://www.terraform.io/docs/providers/vsphere/r/virtual_machine.html#linux-customization-options

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jstuever that would certainly make it easier. Looks like it requires perl.
https://docs.vmware.com/en/VMware-vSphere/6.7/com.vmware.vsphere.vm_admin.doc/GUID-E63B6FAA-8D35-428D-B40C-744769845906.html#GUID-E63B6FAA-8D35-428D-B40C-744769845906

KB article regarding CoreOS specifically says:
"Guest Customization of CoreOS from vCenter or vCloud Director is not supported."
https://kb.vmware.com/s/article/2109161

Not surpising the guest guide doesn't mention RHCOS:
https://www.vmware.com/resources/compatibility/pdf/VMware_GOS_Compatibility_Guide.pdf

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a shame... I was hoping maybe it was using DHCP trickery.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the host look itself via mDNS and set its hostname that way? This certainly seems like a tricky problem to solve. I'm inclined to suggest we move forward but make sure to track this as something we must figure out

I don't know how close we are to realistically being able to replace control plane hosts today outside of this specific concern. @enxebre do you know?

filesystem = "root"
path = "/etc/hostname"
mode = "420"

content {
content = "${var.name}-${count.index}"
}
}

data "ignition_config" "ign" {
count = var.instance_count

append {
source = local.ignition_encoded
}

files = [
data.ignition_file.hostname[count.index].rendered
]
}

36 changes: 36 additions & 0 deletions data/data/vsphere/master/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "vsphere_virtual_machine" "vm" {
count = var.instance_count

name = "${var.cluster_id}-${var.name}-${count.index}"
resource_pool_id = var.resource_pool
datastore_id = var.datastore
num_cpus = var.num_cpus
memory = var.memory
guest_id = var.guest_id
folder = var.folder
enable_disk_uuid = "true"

wait_for_guest_net_timeout = "0"
wait_for_guest_net_routable = "false"

network_interface {
network_id = var.network
}

disk {
label = "disk0"
size = var.disk_size
}

clone {
template_uuid = var.template
}

extra_config = {
"guestinfo.ignition.config.data" = base64encode(data.ignition_config.ign[count.index].rendered)
"guestinfo.ignition.config.data.encoding" = "base64"
}

tags = var.tags
}

65 changes: 65 additions & 0 deletions data/data/vsphere/master/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
variable "name" {
type = string
}

variable "instance_count" {
type = number
}

variable "ignition" {
type = string
default = ""
}

variable "resource_pool" {
type = string
}

variable "folder" {
type = string
}

variable "datastore" {
type = string
}

variable "network" {
type = string
}

variable "cluster_domain" {
type = string
}

variable "datacenter" {
type = string
}

variable "template" {
type = string
}

variable "guest_id" {
type = string
}

variable "memory" {
type = number
}

variable "num_cpus" {
type = number
}

variable "disk_size" {
type = number
}

variable "tags" {
type = list
}

variable "cluster_id" {
type = string
}

4 changes: 4 additions & 0 deletions data/data/vsphere/master/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
Loading