Skip to content

Commit

Permalink
OCTOPUS-679: Adding ability to scale up/down worker node/s
Browse files Browse the repository at this point in the history
Signed-off-by: Chandan Abhyankar <[email protected]>
  • Loading branch information
Chandan-Abhyankar authored and prb112 committed Apr 5, 2024
1 parent 99f728f commit f2107a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
14 changes: 9 additions & 5 deletions ansible/post/files/destroy-workers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
# SPDX-License-Identifier: Apache-2.0
################################################################

# Var: ${self.triggers.count}
COUNT="${1}"
# Var: ${self.triggers.count} [This is removed OCTOPUS-679]
#COUNT="${1}"

# Var: ${self.triggers.vpc_support_server_ip}
PROXY_SERVER="${2}"
PROXY_SERVER="${1}"

# Var: self.triggers.name_prefix
NAME_PREFIX="${3}"
NAME_PREFIX="${2}"

# Get COUNT for all power workers with name having MACHINE_PREFIX
COUNT=$(oc get nodes -l kubernetes.io/arch=ppc64le | grep "${MACHINE_PREFIX}" | grep -c Ready)
echo "Available COUNT for Power worker/s with Prefix '${MACHINE_PREFIX}' is $COUNT"

IDX=0
while [ "$IDX" -lt "$COUNT" ]
Expand All @@ -21,4 +25,4 @@ do
export HTTPS_PROXY="http://${PROXY_SERVER}:3128"
oc delete node ${NAME_PREFIX}-worker-${IDX} || true
IDX=$(($IDX + 1))
done
done
10 changes: 6 additions & 4 deletions modules/5_worker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ variable "ssh_agent" {}
variable "bastion_public_ip" {}
variable "cicd" {}
variable "worker" {
type = object({ count = number, memory = string, processors = string })
default = {
count = 1
memory = "16"
processors = "1"
}
type = object({ count = number, memory = string, processors = string })
description = "The worker configuration details. You may have 0 or more workers"
validation {
condition = lookup(var.worker, "count", 1) >= 1
error_message = "The worker.count value must be greater than 1."
condition = lookup(var.worker, "count", 1) >= 0
error_message = "The worker.count value must be greater than 0."
}
}
nullable = false
}
10 changes: 8 additions & 2 deletions modules/6_post/post.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "null_resource" "remove_workers" {
depends_on = [null_resource.post_setup]

triggers = {
count = var.worker["count"]
# count = var.worker["count"]
name_prefix = "${var.name_prefix}"
vpc_support_server_ip = "${var.nfs_server}"
private_key = sensitive(file(var.private_key_file))
Expand Down Expand Up @@ -70,7 +70,7 @@ oc login \
"${self.triggers.openshift_api_url}" -u "${self.triggers.openshift_user}" -p "${self.triggers.openshift_pass}" --insecure-skip-tls-verify=true
cd ${self.triggers.ansible_post_path}
bash files/destroy-workers.sh "${self.triggers.count}" "${self.triggers.vpc_support_server_ip}" "${self.triggers.name_prefix}"
bash files/destroy-workers.sh "${self.triggers.vpc_support_server_ip}" "${self.triggers.name_prefix}"
EOF
]
}
Expand All @@ -79,6 +79,12 @@ EOF
#command to run ansible playbook on Bastion
resource "null_resource" "post_ansible" {
depends_on = [null_resource.remove_workers, null_resource.post_setup]

triggers = {
count = var.worker["count"]
name_prefix = "${var.name_prefix}"
}

connection {
type = "ssh"
user = "root"
Expand Down

0 comments on commit f2107a8

Please sign in to comment.