Skip to content

Commit

Permalink
OPENSHIFTP-127: remove use_fixed_network logic as it was complicating…
Browse files Browse the repository at this point in the history
… branching

Signed-off-by: Paul Bastide <[email protected]>
  • Loading branch information
prb112 committed Jun 13, 2024
1 parent 70201d5 commit a44a319
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 163 deletions.
2 changes: 2 additions & 0 deletions .terraform.lock.hcl

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

3 changes: 0 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ module "pvs_prepare" {
system_type = var.system_type
vpc_support_server_ip = module.vpc_support.vpc_support_server_ip
override_network_name = var.override_network_name
use_fixed_network = var.use_fixed_network
}

module "transit_gateway" {
Expand Down Expand Up @@ -151,7 +150,6 @@ module "support" {
powervs_machine_cidr = var.powervs_machine_cidr
keep_dns = var.keep_dns
worker = var.worker
use_fixed_network = var.use_fixed_network
nfs_server = module.vpc_support.vpc_support_server_ip
nfs_path = var.nfs_path
}
Expand Down Expand Up @@ -181,7 +179,6 @@ module "worker" {
private_key_file = var.private_key_file
ssh_agent = var.ssh_agent
bastion_public_ip = module.pvs_prepare.bastion_public_ip[0]
use_fixed_network = var.use_fixed_network
cicd = var.cicd
}

Expand Down
43 changes: 22 additions & 21 deletions modules/2_pvs_prepare/bastion/bastion.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ resource "ibm_pi_instance_action" "restart_bastion" {
}

data "ibm_pi_instance_ip" "bastion_public_ip" {
count = var.use_fixed_network ? 0 : 1
count = 1
depends_on = [ibm_pi_instance.bastion]

pi_instance_name = ibm_pi_instance.bastion[count.index].pi_instance_name
Expand All @@ -53,7 +53,7 @@ data "ibm_pi_instance_ip" "bastion_public_ip" {
}

locals {
ext_ip = var.use_fixed_network ? ibm_pi_instance.bastion[0].pi_network[0].external_ip : data.ibm_pi_instance_ip.bastion_public_ip[0].external_ip
ext_ip = data.ibm_pi_instance_ip.bastion_public_ip[0].external_ip
}

resource "null_resource" "bastion_nop" {
Expand Down Expand Up @@ -334,25 +334,26 @@ EOF
# Identifies the networks, and picks the iface that is on the private networkfor_each
# The macaddress is used to identify the private interface and setup with a static ip.
# originally used ${ibm_pi_network_port_attach.bastion_priv_net.macaddress}
provisioner "remote-exec" {
inline = [<<EOF
if [[ "${var.use_fixed_network}" == "true" ]]
then
DEV_NAME=$(find /sys/class/net -mindepth 1 -maxdepth 1 ! -name lo ! -name '*bond*' -printf "%P " -execdir cat {}/address \; | \
grep -v lo | grep -v env2 | awk '{print $1}')
nmcli dev mod $${DEV_NAME} ipv4.addresses ${var.powervs_network_cidr} \
ipv4.gateway ${local.gw} \
ipv4.dns "${var.vpc_support_server_ip}" \
ipv4.method manual \
connection.autoconnect yes \
802-3-ethernet.mtu 9000
nmcli dev up $${DEV_NAME}
fi
EOF
]
}
# Convert this to set ta fixed network for the internal IP for the bastion.
# provisioner "remote-exec" {
# inline = [<<EOF
# if [[ "false" == "true" ]]
# then
# DEV_NAME=$(find /sys/class/net -mindepth 1 -maxdepth 1 ! -name lo ! -name '*bond*' -printf "%P " -execdir cat {}/address \; | \
# grep -v lo | grep -v env2 | awk '{print $1}')

# nmcli dev mod $${DEV_NAME} ipv4.addresses ${var.powervs_network_cidr} \
# ipv4.gateway ${local.gw} \
# ipv4.dns "${var.vpc_support_server_ip}" \
# ipv4.method manual \
# connection.autoconnect yes \
# 802-3-ethernet.mtu 9000

# nmcli dev up $${DEV_NAME}
# fi
# EOF
# ]
# }

provisioner "remote-exec" {
inline = [
Expand Down
1 change: 0 additions & 1 deletion modules/2_pvs_prepare/bastion/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ variable "bastion_public_network_cidr" {}
variable "powervs_network_id" {}
variable "powervs_network_name" {}
variable "powervs_network_cidr" {}
variable "use_fixed_network" {}
variable "vpc_support_server_ip" {}
31 changes: 0 additions & 31 deletions modules/2_pvs_prepare/fixed_network/fixed.tf

This file was deleted.

24 changes: 0 additions & 24 deletions modules/2_pvs_prepare/fixed_network/outputs.tf

This file was deleted.

10 changes: 0 additions & 10 deletions modules/2_pvs_prepare/fixed_network/variables.tf

This file was deleted.

27 changes: 0 additions & 27 deletions modules/2_pvs_prepare/fixed_network/versions.tf

This file was deleted.

6 changes: 3 additions & 3 deletions modules/2_pvs_prepare/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ output "pvs_pubkey_name" {

output "powervs_dhcp_network_id" {
depends_on = [module.network]
value = var.use_fixed_network ? module.fixed_network[0].powervs_network_id : var.override_network_name != "" ? module.existing_network[0].powervs_dhcp_network_id : module.network[0].powervs_dhcp_network_id
value = var.override_network_name != "" ? module.existing_network[0].powervs_dhcp_network_id : module.network[0].powervs_dhcp_network_id
}

output "powervs_dhcp_network_name" {
depends_on = [module.network]
value = var.use_fixed_network ? module.fixed_network[0].powervs_network_name : var.override_network_name != "" ? var.override_network_name : module.network[0].powervs_dhcp_network_name
value = var.override_network_name != "" ? var.override_network_name : module.network[0].powervs_dhcp_network_name
}

output "rhcos_image_id" {
Expand All @@ -34,7 +34,7 @@ output "rhcos_image_id" {
}

output "powervs_dhcp_service" {
value = var.use_fixed_network ? "" : var.override_network_name != "" ? module.existing_network[0].powervs_dhcp_service.dhcp_id : module.network[0].powervs_dhcp_service.dhcp_id
value = var.override_network_name != "" ? module.existing_network[0].powervs_dhcp_service.dhcp_id : module.network[0].powervs_dhcp_service.dhcp_id
}

output "powervs_bastion_name" {
Expand Down
31 changes: 8 additions & 23 deletions modules/2_pvs_prepare/pvs_prepare.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module "keys" {
}

module "existing_network" {
count = var.override_network_name == "" ? 0 : var.use_fixed_network ? 0 : 1
count = var.override_network_name == "" ? 0 : 1
providers = {
ibm = ibm
}
Expand All @@ -44,7 +44,7 @@ module "existing_network" {
}

module "network" {
count = var.override_network_name == "" && !var.use_fixed_network ? 1 : 0
count = var.override_network_name == "" ? 1 : 0
providers = {
ibm = ibm
}
Expand All @@ -58,25 +58,11 @@ module "network" {
cluster_id = var.cluster_id
}

module "fixed_network" {
count = var.use_fixed_network ? 1 : 0
providers = {
ibm = ibm
}
source = "./fixed_network"

powervs_service_instance_id = var.powervs_service_instance_id
cluster_id = var.cluster_id
name_prefix = var.name_prefix
powervs_machine_cidr = var.powervs_machine_cidr
vpc_support_server_ip = var.vpc_support_server_ip
}

module "bastion" {
providers = {
ibm = ibm
}
depends_on = [module.images, module.keys, module.network, module.existing_network, module.fixed_network]
depends_on = [module.images, module.keys, module.network, module.existing_network]
source = "./bastion"

powervs_service_instance_id = var.powervs_service_instance_id
Expand All @@ -88,11 +74,11 @@ module "bastion" {
bastion_image_id = module.images.bastion_image_id
bastion_storage_pool = module.images.bastion_storage_pool
key_name = module.keys.pvs_pubkey_name
bastion_public_network_id = var.use_fixed_network ? module.fixed_network[0].bastion_public_network_id : var.override_network_name != "" ? module.existing_network[0].bastion_public_network_id : module.network[0].bastion_public_network_id
bastion_public_network_name = var.use_fixed_network ? module.fixed_network[0].bastion_public_network_name : var.override_network_name != "" ? module.existing_network[0].bastion_public_network_name : module.network[0].bastion_public_network_name
bastion_public_network_cidr = var.use_fixed_network ? module.fixed_network[0].bastion_public_network_cidr : var.override_network_name != "" ? module.existing_network[0].bastion_public_network_cidr : module.network[0].bastion_public_network_cidr
powervs_network_id = var.use_fixed_network ? module.fixed_network[0].powervs_network_id : var.override_network_name != "" ? module.existing_network[0].powervs_dhcp_network_id : module.network[0].powervs_dhcp_network_id
powervs_network_name = var.use_fixed_network ? module.fixed_network[0].powervs_network_name : var.override_network_name != "" ? module.existing_network[0].powervs_dhcp_network_name : module.network[0].powervs_dhcp_network_name
bastion_public_network_id = var.override_network_name != "" ? module.existing_network[0].bastion_public_network_id : module.network[0].bastion_public_network_id
bastion_public_network_name = var.override_network_name != "" ? module.existing_network[0].bastion_public_network_name : module.network[0].bastion_public_network_name
bastion_public_network_cidr = var.override_network_name != "" ? module.existing_network[0].bastion_public_network_cidr : module.network[0].bastion_public_network_cidr
powervs_network_id = var.override_network_name != "" ? module.existing_network[0].powervs_dhcp_network_id : module.network[0].powervs_dhcp_network_id
powervs_network_name = var.override_network_name != "" ? module.existing_network[0].powervs_dhcp_network_name : module.network[0].powervs_dhcp_network_name
powervs_network_cidr = var.powervs_machine_cidr
private_key_file = var.private_key_file
public_key = module.keys.pvs_pubkey_name
Expand All @@ -107,7 +93,6 @@ module "bastion" {
rhel_subscription_username = var.rhel_subscription_username
rhel_subscription_password = var.rhel_subscription_password
rhel_subscription_activationkey = var.rhel_subscription_activationkey
use_fixed_network = var.use_fixed_network
vpc_support_server_ip = var.vpc_support_server_ip
}

Expand Down
2 changes: 0 additions & 2 deletions modules/2_pvs_prepare/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,5 @@ variable "rhel_smt" {}
variable "rhel_subscription_activationkey" {}
variable "ssh_agent" {}
variable "system_type" {}
#variable "vpc_crn" {}
variable "vpc_support_server_ip" {}
variable "override_network_name" {}
variable "use_fixed_network" {}
1 change: 0 additions & 1 deletion modules/4_pvs_support/pvs_support.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ locals {
client_tarball = var.openshift_client_tarball
openshift_machine_config_url = local.openshift_machine_config_url
vpc_support_server_ip = var.vpc_support_server_ip
use_fixed_network = var.use_fixed_network
power_worker_count = var.worker["count"]
start_host = join(",", local.worker_hosts)
gateway = cidrhost(var.powervs_machine_cidr, 1)
Expand Down
1 change: 0 additions & 1 deletion modules/4_pvs_support/templates/vars.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ports:
- 50825/tcp
- 53248/tcp
ssh_gen_key: false
use_fixed_network: ${use_fixed_network}
power_worker_count: ${power_worker_count}

# NFS Deployment Details
Expand Down
1 change: 0 additions & 1 deletion modules/4_pvs_support/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ variable "kubeconfig_file" {}
variable "cidrs" {}
variable "powervs_machine_cidr" {}
variable "keep_dns" {}
variable "use_fixed_network" {}
variable "nfs_server" {}
variable "nfs_path" {}
variable "worker" {
Expand Down
1 change: 0 additions & 1 deletion modules/5_worker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ variable "powervs_bastion_name" {}
variable "processor_type" {}
variable "rhcos_image_id" {}
variable "system_type" {}
variable "use_fixed_network" {}
variable "private_key_file" {}
variable "ssh_agent" {}
variable "bastion_public_ip" {}
Expand Down
11 changes: 5 additions & 6 deletions modules/5_worker/worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ EOF

### Grab the Bastion Data
data "ibm_pi_dhcp" "refresh_dhcp_server" {
count = var.use_fixed_network ? 0 : 1
count = 1
depends_on = [null_resource.nop]
pi_cloud_instance_id = var.powervs_service_instance_id
pi_dhcp_id = var.powervs_dhcp_service
Expand All @@ -49,10 +49,9 @@ data "ibm_pi_instance" "bastion_instance" {
locals {
# Dev Note: Leases should return the IP, however, they are returning empty in some data centers and existing workspaces.
# the conditionals are:
# 1. if fixed network, pull off the bastion_instance
# 2. if other network, pull off lease from dhcp server
# 3. if not found, use the pub-net ip
bastion_private_ip = var.use_fixed_network ? [] : [for lease in data.ibm_pi_dhcp.refresh_dhcp_server[0].leases : lease if lease.instance_mac == data.ibm_pi_instance.bastion_instance.networks[0].macaddress]
# 1. if other network, pull off lease from dhcp server
# 2. if not found, use the pub-net ip
bastion_private_ip = [for lease in data.ibm_pi_dhcp.refresh_dhcp_server[0].leases : lease if lease.instance_mac == data.ibm_pi_instance.bastion_instance.networks[0].macaddress]
}

# Dev Note: the hypervisor does not report the internal interfaces ip correctly
Expand Down Expand Up @@ -160,7 +159,7 @@ data "http" "bastion_ip_retrieval" {
# }

locals {
ignition_ip = var.use_fixed_network ? data.ibm_pi_instance.bastion_instance.networks[0].ip : length(var.ignition_ip) > 0 ? var.ignition_ip[0].instance_ip : length(local.bastion_private_ip) > 0 ? local.bastion_private_ip[0].instance_ip : chomp(data.http.bastion_ip_retrieval[0].response_body)
ignition_ip = length(var.ignition_ip) > 0 ? var.ignition_ip[0].instance_ip : length(local.bastion_private_ip) > 0 ? local.bastion_private_ip[0].instance_ip : chomp(data.http.bastion_ip_retrieval[0].response_body)
}

# Modeled off the OpenShift Installer work for IPI PowerVS
Expand Down
1 change: 0 additions & 1 deletion scripts/create-var-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ mac_tags = [ "mac-cicd-${CLEAN_VERSION}" ]
#override_network_name="DHCPSERVERmac-dhcp-${VPC_REGION}_Private"
#override_transit_gateway_name="${OVERRIDE_PREFIX}-tg"
#use_fixed_network=true
cicd = true
skip_vpc_key = true
EOFXEOF
Expand Down
7 changes: 0 additions & 7 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,3 @@ variable "override_network_name" {
description = "overrides network creation for a specific dhcp network"
default = ""
}

# FIXED Networks are not fully enabled, and are left in case we need to move back to it.
variable "use_fixed_network" {
type = bool
description = "Switches to using a PowerVS `vlan` instead of `dhcp-vlan`"
default = false
}

0 comments on commit a44a319

Please sign in to comment.