Skip to content

Commit

Permalink
OPENSHIFTP-128: remove refresh_dhcp_service and calculate the ip of t…
Browse files Browse the repository at this point in the history
…he bastion

Signed-off-by: Paul Bastide <[email protected]>
  • Loading branch information
prb112 committed Jun 13, 2024
1 parent f8d9100 commit 5b09c9f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 60 deletions.
9 changes: 5 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ module "worker" {
powervs_dhcp_service = module.pvs_prepare.powervs_dhcp_service
# Eventually, this should be a bit more dynamic and include MachineConfigPool

private_key_file = var.private_key_file
ssh_agent = var.ssh_agent
bastion_public_ip = module.pvs_prepare.bastion_public_ip[0]
cicd = var.cicd
private_key_file = var.private_key_file
ssh_agent = var.ssh_agent
bastion_public_ip = module.pvs_prepare.bastion_public_ip[0]
powervs_machine_cidr = var.powervs_machine_cidr
cicd = var.cicd
}

module "post" {
Expand Down
2 changes: 1 addition & 1 deletion modules/5_worker/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
################################################################

output "bastion_private_ip" {
value = local.bastion_private_ip
value = local.ignition_ip
}
1 change: 1 addition & 0 deletions modules/5_worker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ variable "system_type" {}
variable "private_key_file" {}
variable "ssh_agent" {}
variable "bastion_public_ip" {}
variable "powervs_machine_cidr" {}
variable "cicd" {}
variable "worker" {
default = {
Expand Down
57 changes: 2 additions & 55 deletions modules/5_worker/worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,8 @@
# SPDX-License-Identifier: Apache-2.0
################################################################

# Dev Note: nop is a debug step
resource "null_resource" "nop" {
triggers = {
bastion_private_ip_mac = var.ignition_mac
}

connection {
type = "ssh"
user = "root"
private_key = file(var.private_key_file)
host = var.bastion_public_ip
agent = var.ssh_agent
}

provisioner "remote-exec" {
inline = [<<EOF
echo "Waiting on DHCP Lease to be registered"
sleep 15
echo "Done waiting on DHCP Lease to be registered"
echo ""
echo "IP Information"
ip a
echo "Looking for mac: ${var.ignition_mac}"
EOF
]
}
}

### Grab the Bastion Data
data "ibm_pi_dhcp" "refresh_dhcp_server" {
count = 1
depends_on = [null_resource.nop]
pi_cloud_instance_id = var.powervs_service_instance_id
pi_dhcp_id = var.powervs_dhcp_service
}

data "ibm_pi_instance" "bastion_instance" {
depends_on = [data.ibm_pi_dhcp.refresh_dhcp_server]
pi_instance_name = var.powervs_bastion_name
pi_cloud_instance_id = var.powervs_service_instance_id
}

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 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]
}

locals {
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 : "bad-ip"
ignition_ip = cidrhost(var.powervs_machine_cidr, 3)
}

# Modeled off the OpenShift Installer work for IPI PowerVS
Expand All @@ -64,8 +13,6 @@ locals {
resource "ibm_pi_instance" "worker" {
count = var.worker["count"]

depends_on = [data.ibm_pi_dhcp.refresh_dhcp_server, null_resource.nop]

pi_cloud_instance_id = var.powervs_service_instance_id
pi_instance_name = "${var.name_prefix}-worker-${count.index}"

Expand All @@ -82,7 +29,7 @@ resource "ibm_pi_instance" "worker" {
pi_key_pair_name = var.key_name
pi_health_status = "WARNING"

### DEV NOTE to fully support FIXED NETWORK
### DEV NOTE
# need a different worker.ign with static ip setting a kernel arg using ignition following this pattern:
# ip={{ item.ipaddr }}::{{ static_ip.gateway }}:{{ static_ip.netmask }}:{{ infraID.stdout }}-{{ item.name }}:ens192:off:{{ coredns_vm.ipaddr }}
pi_user_data = base64encode(
Expand Down

0 comments on commit 5b09c9f

Please sign in to comment.