Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
Rearrange the code flow to run helpernode before nodes creation
Browse files Browse the repository at this point in the history
Fixes #45

Signed-off-by: Yussuf Shaikh <yussuf@us.ibm.com>
  • Loading branch information
yussufsh committed Sep 11, 2020
1 parent a048d2e commit e3fab39
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 138 deletions.
87 changes: 87 additions & 0 deletions modules/3_helpernode/helpernode.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
################################################################
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Licensed Materials - Property of IBM
#
# ©Copyright IBM Corp. 2020
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################

locals {
helpernode_vars = {
cluster_domain = var.cluster_domain
cluster_id = var.cluster_id
bastion_ip = var.bastion_ip
forwarders = var.dns_forwarders
gateway_ip = var.gateway_ip
netmask = cidrnetmask(var.cidr)
broadcast = cidrhost(var.cidr,-1)
ipid = cidrhost(var.cidr, 0)
pool = var.allocation_pools[0]

bootstrap_info = {
ip = var.bootstrap_ip,
mac = var.bootstrap_mac,
name = "bootstrap"
}
master_info = [ for ix in range(length(var.master_ips)) :
{
ip = var.master_ips[ix],
mac = var.master_macs[ix],
name = "master-${ix}"
}
]
worker_info = [ for ix in range(length(var.worker_ips)) :
{
ip = var.worker_ips[ix],
mac = var.worker_macs[ix],
name = "worker-${ix}"
}
]

client_tarball = var.openshift_client_tarball
install_tarball = var.openshift_install_tarball
}
}

resource "null_resource" "config" {
connection {
type = "ssh"
user = var.rhel_username
host = var.bastion_ip
private_key = var.private_key
agent = var.ssh_agent
timeout = "15m"
bastion_host = var.jump_host
}

provisioner "remote-exec" {
inline = [
"rm -rf ocp4-helpernode",
"echo 'Cloning into ocp4-helpernode...'",
"git clone https://github.com/RedHatOfficial/ocp4-helpernode --quiet",
"cd ocp4-helpernode && git checkout ${var.helpernode_tag}"
]
}
provisioner "file" {
content = templatefile("${path.module}/templates/helpernode_vars.yaml", local.helpernode_vars)
destination = "~/ocp4-helpernode/helpernode_vars.yaml"
}
provisioner "remote-exec" {
inline = [
"echo 'Running ocp4-helpernode playbook...'",
"cd ocp4-helpernode && ansible-playbook -e @helpernode_vars.yaml tasks/main.yml ${var.ansible_extra_options}"
]
}
}
43 changes: 26 additions & 17 deletions modules/4_nodes/outputs.tf → modules/3_helpernode/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,35 @@
#
################################################################

output "bootstrap_ip" {
value = local.bootstrap_ip
variable "cluster_domain" {
default = "example.com"
}

output "master_ips" {
value = null_resource.master_ip.*.triggers.address
variable "cluster_id" {
default = "test-ocp"
}

output "worker_ips" {
value = null_resource.worker_ip.*.triggers.address
}
variable "dns_forwarders" {}
variable "gateway_ip" {}
variable "cidr" {}
variable "allocation_pools" {}

output "bootstrap_mac" {
value = "${join("", flatten(libvirt_domain.bootstrap.*.network_interface).*.mac)}"
}
variable "bastion_ip" {}
variable "rhel_username" {}
variable "private_key" {}
variable "ssh_agent" {}
variable "jump_host" { default = "" }

output "master_macs" {
value = flatten(flatten(libvirt_domain.master.*.network_interface).*.mac)
}
variable "bootstrap_ip" {}
variable "master_ips" {}
variable "worker_ips" {}

output "worker_macs" {
value = flatten(flatten(libvirt_domain.worker.*.network_interface).*.mac)
}
variable "bootstrap_mac" {}
variable "master_macs" {}
variable "worker_macs" {}

variable "openshift_client_tarball" {}
variable "openshift_install_tarball" {}

variable "helpernode_tag" {}

variable "ansible_extra_options" {}
9 changes: 9 additions & 0 deletions modules/3_helpernode/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
null = {
source = "hashicorp/null"
version = "~> 2.1"
}
}
required_version = "~> 0.13"
}
23 changes: 3 additions & 20 deletions modules/4_nodes/nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
#
################################################################

locals {
bootstrap_ip = cidrhost(var.network_cidr, 3)
first_master_ip = 4
first_worker_ip = 11
}

resource "libvirt_volume" "rhcos_base" {
name = "${var.cluster_id}-rhcos-base-vol"
source = var.rhcos_image
Expand Down Expand Up @@ -157,6 +151,7 @@ resource "libvirt_domain" "bootstrap" {
network_interface {
network_id = var.network_id
hostname = "bootstrap.${var.cluster_id}.${var.cluster_domain}"
mac = var.bootstrap_mac
}
}

Expand All @@ -181,6 +176,7 @@ resource "libvirt_domain" "master" {
network_interface {
network_id = var.network_id
hostname = "master-${count.index}.${var.cluster_id}.${var.cluster_domain}"
mac = var.master_macs[count.index]
}
}

Expand All @@ -205,19 +201,6 @@ resource "libvirt_domain" "worker" {
network_interface {
network_id = var.network_id
hostname = "worker-${count.index}.${var.cluster_id}.${var.cluster_domain}"
}
}

resource "null_resource" "master_ip" {
count = var.master["count"]
triggers = {
address = cidrhost(var.network_cidr, local.first_master_ip + count.index)
}
}

resource "null_resource" "worker_ip" {
count = var.worker["count"]
triggers = {
address = cidrhost(var.network_cidr, local.first_worker_ip + count.index)
mac = var.worker_macs[count.index]
}
}
4 changes: 4 additions & 0 deletions modules/4_nodes/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ variable "worker" {
}
}

variable "bootstrap_mac" {}
variable "master_macs" {}
variable "worker_macs" {}

variable "cpu_mode" {}

variable "rhcos_image" {}
Expand Down
68 changes: 0 additions & 68 deletions modules/5_install/install.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,6 @@
################################################################

locals {
helpernode_vars = {
cluster_domain = var.cluster_domain
cluster_id = var.cluster_id
bastion_ip = var.bastion_ip
forwarders = var.dns_forwarders
gateway_ip = var.gateway_ip
netmask = cidrnetmask(var.cidr)
broadcast = cidrhost(var.cidr,-1)
ipid = cidrhost(var.cidr, 0)
pool = var.allocation_pools[0]

bootstrap_info = {
ip = var.bootstrap_ip,
mac = var.bootstrap_mac,
name = "bootstrap"
}
master_info = [ for ix in range(length(var.master_ips)) :
{
ip = var.master_ips[ix],
mac = var.master_macs[ix],
name = "master-${ix}"
}
]
worker_info = [ for ix in range(length(var.worker_ips)) :
{
ip = var.worker_ips[ix],
mac = var.worker_macs[ix],
name = "worker-${ix}"
}
]

client_tarball = var.openshift_client_tarball
install_tarball = var.openshift_install_tarball
}

inventory = {
bastion_ip = var.bastion_ip
bootstrap_ip = var.bootstrap_ip
Expand All @@ -79,40 +44,7 @@ locals {
}
}

resource "null_resource" "config" {
connection {
type = "ssh"
user = var.rhel_username
host = var.bastion_ip
private_key = var.private_key
agent = var.ssh_agent
timeout = "15m"
bastion_host = var.jump_host
}

provisioner "remote-exec" {
inline = [
"rm -rf ocp4-helpernode",
"echo 'Cloning into ocp4-helpernode...'",
"git clone https://github.com/RedHatOfficial/ocp4-helpernode --quiet",
"cd ocp4-helpernode && git checkout ${var.helpernode_tag}"
]
}
provisioner "file" {
content = templatefile("${path.module}/templates/helpernode_vars.yaml", local.helpernode_vars)
destination = "~/ocp4-helpernode/helpernode_vars.yaml"
}
provisioner "remote-exec" {
inline = [
"echo 'Running ocp4-helpernode playbook...'",
"cd ocp4-helpernode && ansible-playbook -e @helpernode_vars.yaml tasks/main.yml ${var.ansible_extra_options}"
]
}
}

resource "null_resource" "install" {
depends_on = [null_resource.config]

connection {
type = "ssh"
user = var.rhel_username
Expand Down
17 changes: 1 addition & 16 deletions modules/5_install/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ variable "cluster_id" {
default = "test-ocp"
}

variable "dns_forwarders" {
default = "8.8.8.8; 9.9.9.9"
}
variable gateway_ip {}
variable cidr {}
variable allocation_pools {}

variable "bastion_ip" {}
variable "rhel_username" {}
variable "private_key" {}
Expand All @@ -42,19 +35,11 @@ variable "bootstrap_ip" {}
variable "master_ips" {}
variable "worker_ips" {}

variable bootstrap_mac {}
variable master_macs {}
variable worker_macs {}

variable "openshift_client_tarball" {}
variable "openshift_install_tarball" {}

variable "public_key" {}
variable "pull_secret" {}
variable "release_image_override" {}

variable helpernode_tag { default = "master" }
variable install_playbook_tag { default = "master" }
variable "install_playbook_tag" {}

variable "storage_type" {}
variable "log_level" {}
Expand Down
Loading

0 comments on commit e3fab39

Please sign in to comment.