Skip to content

Commit

Permalink
OCTOPUS-558: update_lbs.sh is modified
Browse files Browse the repository at this point in the history
Signed-off-by: Chandan Abhyankar <[email protected]>
  • Loading branch information
Chandan-Abhyankar committed Dec 20, 2023
1 parent fe92108 commit f151f94
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 83 deletions.
3 changes: 3 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ module "post" {
bastion_public_ip = var.powervs_bastion_ip
private_key_file = var.private_key_file
vpc_region = var.vpc_region
vpc_name = local.vpc_name
vpc_zone = var.vpc_zone
ibmcloud_api_key = var.ibmcloud_api_key
resource_group_name = module.vpc.vpc_resource_group_name
name_prefix = local.name_prefix
worker_1 = var.worker_1
worker_2 = var.worker_2
Expand Down
44 changes: 42 additions & 2 deletions modules/7_post/ibmcloud_lb/files/remove_lbs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,46 @@
# SPDX-License-Identifier: Apache-2.0
################################################################

# The script removes the workers from the pools.
# The script removes the entry added to the front end listeners for Internal/External Load Balancers
IBMCLOUD_API_KEY=$1
VPC_REGION=$2
RESOURCE_GROUP=$3
VPC_NAME=$4

ibmcloud
echo "Login to the IBM Cloud"
ibmcloud login --apikey ${IBMCLOUD_API_KEY} -r ${VPC_REGION} -g ${RESOURCE_GROUP}

HTTP_POOL="ingress-http"
HTTPS_POOL="ingress-https"

# Find the Load Balancers
INTERNAL_LB_NAME=`ibmcloud is lbs | grep internal-loadbalancer | awk '{print $2}'`
EXTERNAL_LB_NAME=`ibmcloud is lbs | grep external-loadbalancer | awk '{print $2}'`

# Fetch IP addresses of newly added x86 workers
for IP in $(oc get nodes -l kubernetes.io/arch=amd64 -owide --no-headers=true | awk '{print $6}')
do

# Remove member from front end listeners for internal load balancers with Pool name 'ingress-http' and 'ingress-https'
HTTP_MEMBER_ID=`ibmcloud is load-balancer-pool-members "${INTERNAL_LB_NAME}" "${HTTP_POOL}" | grep ${IP} | awk '{print $1}'`
ibmcloud is load-balancer-pool-member-delete \
"${INTERNAL_LB_NAME}" "${HTTP_POOL}" "${HTTP_MEMBER_ID}" --vpc "${VPC_NAME}" --output JSON

sleep 60

HTTPS_MEMBER_ID=`ibmcloud is load-balancer-pool-members "${INTERNAL_LB_NAME}" "${HTTPS_POOL}" | grep ${IP} | awk '{print $1}'`
ibmcloud is load-balancer-pool-member-delete \
"${INTERNAL_LB_NAME}" "${HTTPS_POOL}" "${HTTPS_MEMBER_ID}" --vpc "${VPC_NAME}" --output JSON

# Remove member from front end listeners for external load balancers with Pool name 'ingress-http' and 'ingress-https'
HTTP_MEMBER_ID=`ibmcloud is load-balancer-pool-members "${EXTERNAL_LB_NAME}" "${HTTP_POOL}" | grep ${IP} | awk '{print $1}'`
ibmcloud is load-balancer-pool-member-delete \
"${EXTERNAL_LB_NAME}" "${HTTP_POOL}" "${HTTP_MEMBER_ID}" --vpc "${VPC_NAME}" --output JSON

sleep 60

HTTPS_MEMBER_ID=`ibmcloud is load-balancer-pool-members "${EXTERNAL_LB_NAME}" "${HTTPS_POOL}" | grep ${IP} | awk '{print $1}'`
ibmcloud is load-balancer-pool-member-delete \
"${EXTERNAL_LB_NAME}" "${HTTPS_POOL}" "${HTTPS_MEMBER_ID}" --vpc "${VPC_NAME}" --output JSON

done
84 changes: 21 additions & 63 deletions modules/7_post/ibmcloud_lb/files/update_lbs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,43 @@
# SPDX-License-Identifier: Apache-2.0
################################################################

# The script updates the ibmcloud entries for the new Intel nodes pool
# The script updates the front end listeners for Internal/External UPI automation generated Load Balancers
IBMCLOUD_API_KEY=$1
VPC_REGION=$2
RESOURCE_GROUP=$3
VPC_NAME=$4

# Dev Note: we want to refresh the credentials and not assume it's OK.
echo "Login to the IBM Cloud"
ibmcloud login --apikey ${IBMCLOUD_API_KEY} -r ${VPC_REGION} -g ${RESOURCE_GROUP}

# 1. Fetch IP addresses of newly added x86 workers
for IP in $(oc get nodes -lkubernetes.io/arch=amd64 -owide --no-headers=true | awk '{print $6}')
do
# Find the Load Balancer
HTTP_POOL="ingress-http"
HTTPS_POOL="ingress-https"

# 2. Modify front end listeners for internal and external load balancers with Pool name 'ingress-http' and 'ingress-https'
# Find the Load Balancers
INTERNAL_LB_NAME=`ibmcloud is lbs | grep internal-loadbalancer | awk '{print $2}'`
EXTERNAL_LB_NAME=`ibmcloud is lbs | grep external-loadbalancer | awk '{print $2}'`

# Fetch IP addresses of newly added x86 workers
for IP in $(oc get nodes -l kubernetes.io/arch=amd64 -owide --no-headers=true | awk '{print $6}')
do

# 3.Add Server Instances to above listeners
# Modify front end listeners for internal load balancers with Pool name 'ingress-http' and 'ingress-https'
ibmcloud is load-balancer-pool-member-create \
"${INTERNAL_LB_NAME}" "${HTTP_POOL}" 80 ${IP} --vpc "${VPC_NAME}" --output JSON

sleep 60

ibmcloud is vpc ${VPC_NAME} --output json
ibmcloud is load-balancers --resource-group-name ${RESOURCE_GROUP} --output json
--- figure out which ones are in the vpc
ibmcloud is load-balancer-pool-member-create \
"${INTERNAL_LB_NAME}" "${HTTPS_POOL}" 443 ${IP} --vpc "${VPC_NAME}" --output JSON

1. GET THE INTERNAL IP.
oc get nodes -lkubernetes.io/arch=amd64 -owide --no-headers=true | awk '{print $6}'
# Modify front end listeners for external load balancers with Pool name 'ingress-http' and 'ingress-https'
ibmcloud is load-balancer-pool-member-create \
"${EXTERNAL_LB_NAME}" "${HTTP_POOL}" 80 ${IP} --vpc "${VPC_NAME}" --output JSON

LB=
POOL=
ibmcloud is load-balancer-pool-member-create \
"${INGRESS_HTTP_LB}" "${HTTP_POOL}" 80 ${IP} --output JSON
sleep 60

ibmcloud is load-balancer-pool-member-create \
"${INGRESS_HTTPS_LB}" "${HTTPS_POOL}" 443 ${IP} --output JSON
ibmcloud is load-balancer-pool-member-create \
"${EXTERNAL_LB_NAME}" "${HTTPS_POOL}" 443 ${IP} --vpc "${VPC_NAME}" --output JSON

done

load-balancer-pools
load-balancer-pool-member-create, lb-pmc Create a load balancer pool member
load-balancer-pool-member-delete, lb-pmd Delete one or more members from a load balancer pool.



load-balancer, lb View details of a load balancer
load-balancer-create, lbc Create a load balancer
load-balancer-delete, lbd Delete one or more load balancers.
load-balancer-listener, lb-l View details of a load balancer listener
load-balancer-listener-create, lb-lc Create a load balancer listener
load-balancer-listener-delete, lb-ld Delete one or more load balancer listeners.
load-balancer-listener-policies, lb-lps List all load balancer policies
load-balancer-listener-policy, lb-lp View details of load balancer listener policy
load-balancer-listener-policy-create, lb-lpc Create a load balancer listener policy
load-balancer-listener-policy-delete, lb-lpd Delete one or more policies from a load balancer listener.
load-balancer-listener-policy-rule, lb-lpr List single load balancer policy rule
load-balancer-listener-policy-rule-create, lb-lprc Create a load balancer listener policy rule
load-balancer-listener-policy-rule-delete, lb-lprd Delete one or more policies from a load balancer listener.
load-balancer-listener-policy-rule-update, lb-lpru Update a rule of a load balancer listener policy
load-balancer-listener-policy-rules, lb-lprs List all load balancer policy rules
load-balancer-listener-policy-update, lb-lpu Update a policy of a load balancer listener
load-balancer-listener-update, lb-lu Update a load balancer listener
load-balancer-listeners, lb-ls List all load balancer listeners
load-balancer-pool, lb-p View details of a load balancer pool
load-balancer-pool-create, lb-pc Create a load balancer pool
load-balancer-pool-delete, lb-pd Delete one or more pools from a load balancer.
load-balancer-pool-member, lb-pm View details of load balancer pool member
load-balancer-pool-member-create, lb-pmc Create a load balancer pool member
load-balancer-pool-member-delete, lb-pmd Delete one or more members from a load balancer pool.
load-balancer-pool-member-update, lb-pmu Update a member of a load balancer pool
load-balancer-pool-members, lb-pms List all the members of a load balancer pool
load-balancer-pool-members-update, lb-pmsu Update members of the load balancer pool
load-balancer-pool-update, lb-pu Update a pool of a load balancer
load-balancer-pools, lb-ps List all pools of a load balancer
load-balancer-statistics, lb-statistics List all statistics of a load balancer
load-balancer-update, lbu Update a load balancer
load-balancers, lbs

ibmcloud is load-balancer-pool-members --vpc ${VPC_NAME}


ingress-https
ingress-http
2 changes: 1 addition & 1 deletion modules/7_post/ibmcloud_lb/ibmcloud_lb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ EOF
provisioner "remote-exec" {
inline = [<<EOF
cd /root/ocp4-upi-compute-powervs-ibmcloud/intel/lbs/
bash update_lbs.sh
bash update_lbs.sh "${var.ibmcloud_api_key}" "${var.vpc_region}" "${var.resource_group_name}" "${var.vpc_name}"
EOF
]
}
Expand Down
3 changes: 3 additions & 0 deletions modules/7_post/ibmcloud_lb/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ variable "connection_timeout" {}
variable "rhel_username" {}
variable "bastion_public_ip" {}
variable "private_key_file" {}
variable "ibmcloud_api_key" {}
variable "resource_group_name" {}
variable "vpc_name" {}
variable "vpc_region" {}
variable "vpc_zone" {}
variable "name_prefix" {}
Expand Down
35 changes: 19 additions & 16 deletions modules/7_post/post.tf
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,22 @@ module "haproxy_lb_support" {

# Dev Note: we only execute when CIS, Security Groups and Load Balancers are used
module "ibmcloud_lb_support" {
count = var.ibm_cloud_cis ? 1 : 0
depends_on = [null_resource.patch_nfs_arch_ppc64le]
source = "./ibmcloud_lb"

ssh_agent = var.ssh_agent
rhel_username = var.rhel_username
connection_timeout = var.connection_timeout
bastion_public_ip = var.bastion_public_ip
private_key_file = var.private_key_file
vpc_region = var.vpc_region
vpc_zone = var.vpc_zone
name_prefix = var.name_prefix
worker_1 = var.worker_1
worker_2 = var.worker_2
worker_3 = var.worker_3
}
count = var.ibm_cloud_cis ? 1 : 0
depends_on = [null_resource.patch_nfs_arch_ppc64le]
source = "./ibmcloud_lb"

ssh_agent = var.ssh_agent
rhel_username = var.rhel_username
connection_timeout = var.connection_timeout
bastion_public_ip = var.bastion_public_ip
private_key_file = var.private_key_file
vpc_region = var.vpc_region
vpc_zone = var.vpc_zone
vpc_name = var.vpc_name
ibmcloud_api_key = var.ibmcloud_api_key
resource_group_name = var.resource_group_name
name_prefix = var.name_prefix
worker_1 = var.worker_1
worker_2 = var.worker_2
worker_3 = var.worker_3
}
5 changes: 4 additions & 1 deletion modules/7_post/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ variable "rhel_username" {}
variable "bastion_public_ip" {}
variable "private_key_file" {}
variable "vpc_region" {}
variable "vpc_name" {}
variable "vpc_zone" {}
variable "ibmcloud_api_key" {}
variable "resource_group_name" {}
variable "name_prefix" {}
variable "worker_1" {}
variable "worker_2" {}
variable "worker_3" {}
variable "cicd_image_pruner_cleanup" {}
variable "ibm_cloud_cis" {}
variable "ibm_cloud_cis" {}

0 comments on commit f151f94

Please sign in to comment.