Skip to content

Commit

Permalink
fix(setup_truefoundry_cluster.sh): correct cluster status check logic…
Browse files Browse the repository at this point in the history
… and error handling for non-generic clusters
  • Loading branch information
sachincool committed Jan 2, 2025
1 parent aeb667d commit c692e62
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions scripts/setup_truefoundry_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function is_cluster_provisioned() {
log_info "is_cluster_provisioned: Checking if cluster exists and is provisioned..."

# Make GET request to check cluster status
local response=$(make_request "GET" "${CONTROL_PLANE_URL}/api/svc/v1/cluster/${CLUSTER_NAME}" "" "200,400") || {
log_info "is_cluster_provisioned: Cluster does not exist"
local response=$(make_request "GET" "${CONTROL_PLANE_URL}/api/svc/v1/cluster/${CLUSTER_NAME}" "" "200") || {
log_info "is_cluster_provisioned: Got error while querying for cluster ${CLUSTER_NAME}"
echo "false"
return 0
}
Expand Down Expand Up @@ -196,23 +196,24 @@ function main() {
local cluster_token

# Check if cluster exists and is provisioned
if [ "${CLUSTER_TYPE}" != "generic" ]; then
local cluster_status=$(is_cluster_provisioned)
log_info "main: Cluster status: ${cluster_status}"

if [ "${cluster_status}" = "true" ]; then
if [ "${cluster_status}" = "true" ]; then
log_info "main: Cluster already exists and is provisioned. Skipping creation."
# Get existing cluster ID from the response
cluster_id=$(make_request "GET" "${CONTROL_PLANE_URL}/api/svc/v1/cluster/${CLUSTER_NAME}" "" "200" | jq -r '.id')
else
else
if [ "${CLUSTER_TYPE}" != "generic" ]; then
# Setup provider account and create cluster if not provisioned or doesn't exist
setup_provider_account || handle_error "Failed to setup provider account"
cluster_id=$(create_cluster) || handle_error "Failed to create cluster"
else
cluster_id=$(create_cluster) || handle_error "Failed to create cluster"
fi
else
cluster_id=$(create_cluster) || handle_error "Failed to create cluster"
fi


cluster_token=$(get_cluster_token "${cluster_id}") || handle_error "Failed to get cluster token"

log_info "main: cluster_id=$cluster_id"
Expand Down

0 comments on commit c692e62

Please sign in to comment.