Skip to content

Commit

Permalink
modified the file
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhadapaithankar committed Jun 24, 2024
1 parent d2d8745 commit d37d3f9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ acr-login:
runlocal-rp: deploy-database acr-login
@set -a; source secrets/env; set +a; \
if [ ! -f $(PWD)/aks.kubeconfig ]; then echo "aks.kubeconfig not found"; exit 1; fi; \
podman run --rm -p 8443:8443 --network host \
podman run --rm -p 8443:8443 \
--name aro-rp \
-w /app \
-e RP_MODE="development" \
Expand Down Expand Up @@ -134,9 +134,12 @@ runlocal-rp: deploy-database acr-login
-e KUBECONFIG="/app/secrets/aks.kubeconfig" \
-e HIVE_KUBE_CONFIG_PATH="/app/secrets/aks.kubeconfig" \
-e ARO_CHECKOUT_PATH="/app" \
-e ARO_INSTALL_VIA_HIVE="true" \
-e ARO_ADOPT_BY_HIVE="true" \
-v $(PWD)/aks.kubeconfig:/app/secrets/aks.kubeconfig:z \
-v $(PWD)/secrets:/app/secrets:z \
$$ARO_IMAGE rp
go run -ldflags "-X github.com/Azure/ARO-RP/pkg/util/version.GitCommit=$(VERSION)" ./cmd/aro rp >aro.log 2>&1 &

# Function to run VPN
.PHONY: run-vpn
Expand Down
57 changes: 26 additions & 31 deletions setup_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ validate_rp_running() {
ELAPSED=0
while true; do
sleep 5
http_code=$(curl -k -s -o /dev/null -w '%{http_code}' https://localhost:8443/healthz/ready || true)
http_code=$(curl -k -s -o /dev/null -w '%{http_code}' http://localhost:8443/healthz/ready || true)
case $http_code in
"200")
echo "########## ✅ ARO RP Running ##########"
Expand All @@ -27,20 +27,11 @@ validate_rp_running() {
done
}

# Function to access AKS cluster
access_aks_cluster() {
echo "########## Accessing AKS Cluster ##########"
sudo openvpn --config "secrets/vpn-aks-$LOCATION.ovpn" --daemon --writepid vpnpid
make aks.kubeconfig
export KUBECONFIG=aks.kubeconfig
hack/get-admin-aks-kubeconfig.sh
}

# Ensure all env vars are set (CLUSTER_LOCATION, CLUSTER_RESOURCE_GROUP, CLUSTER_NAME)
# Ensure all env vars are set (CLUSTER_LOCATION, RESOURCEGROUP, CLUSTER_NAME)
ALL_SET="true"
if [ -z ${AZURE_SUBSCRIPTION_ID} ]; then ALL_SET="false" && echo "AZURE_SUBSCRIPTION_ID is unset"; else echo "AZURE_SUBSCRIPTION_ID is set to '$AZURE_SUBSCRIPTION_ID'"; fi
if [ -z ${CLUSTER_LOCATION} ]; then ALL_SET="false" && echo "CLUSTER_LOCATION is unset"; else echo "CLUSTER_LOCATION is set to '$CLUSTER_LOCATION'"; fi
if [ -z ${CLUSTER_RESOURCE_GROUP} ]; then ALL_SET="false" && echo "CLUSTER_RESOURCE_GROUP is unset"; else echo "CLUSTER_RESOURCE_GROUP is set to '$CLUSTER_RESOURCE_GROUP'"; fi
if [ -z ${LOCATION} ]; then ALL_SET="false" && echo "LOCATION is unset"; else echo "LOCATION is set to '$LOCATION'"; fi
if [ -z ${RESOURCEGROUP} ]; then ALL_SET="false" && echo "RESOURCEGROUP is unset"; else echo "RESOURCEGROUP is set to '$RESOURCEGROUP'"; fi
if [ -z ${CLUSTER_NAME} ]; then ALL_SET="false" && echo "CLUSTER_NAME is unset"; else echo "CLUSTER_NAME is set to '$CLUSTER_NAME'"; fi
if [ -z ${CLUSTER_VNET} ]; then CLUSTER_VNET="aro-vnet"; echo "CLUSTER_VNET is ${CLUSTER_VNET}"; fi
if [ -z ${CLUSTER_MASTER_SUBNET} ]; then CLUSTER_MASTER_SUBNET="master-subnet"; echo "CLUSTER_MASTER_SUBNET is ${CLUSTER_MASTER_SUBNET}"; fi
Expand All @@ -49,9 +40,6 @@ if [ -z ${OPENSHIFT_VERSION} ]; then ALL_SET="false" && echo "OPENSHIFT_VERSION

if [[ "${ALL_SET}" != "true" ]]; then exit 1; fi

# Access AKS cluster
access_aks_cluster

# Check Azure CLI version
echo "Checking Azure CLI version..."
az_version=$(az --version | grep 'azure-cli' | awk '{print $2}')
Expand Down Expand Up @@ -106,57 +94,64 @@ add_openshift_version "4.13.40" "quay.io/openshift-release-dev/ocp-release@sha25

# Delete the existing cluster if it exists
echo "Deleting the existing cluster if it exists..."
az aro delete --resource-group $CLUSTER_RESOURCE_GROUP --name $CLUSTER_NAME --yes --no-wait || true
az aro delete --resource-group $RESOURCEGROUP --name $CLUSTER_NAME --yes --no-wait || true

# Wait for the cluster deletion to complete
echo "Waiting for the cluster to be deleted..."
while az aro show --name $CLUSTER_NAME --resource-group $CLUSTER_RESOURCE_GROUP &> /dev/null; do
while az aro show --name $CLUSTER_NAME --resource-group $RESOURCEGROUP &> /dev/null; do
echo "Cluster is still being deleted...waiting 30 seconds."
sleep 30
done

# Create resource group
echo "Creating resource group $CLUSTER_RESOURCE_GROUP in $CLUSTER_LOCATION..."
az group create --name $CLUSTER_RESOURCE_GROUP --location $CLUSTER_LOCATION
echo "Creating resource group $RESOURCEGROUP in $LOCATION..."
az group create --name $RESOURCEGROUP --location $LOCATION

# Create virtual network
echo "Creating virtual network $CLUSTER_VNET in $CLUSTER_RESOURCE_GROUP..."
az network vnet create --resource-group $CLUSTER_RESOURCE_GROUP --name $CLUSTER_VNET --address-prefixes 10.0.0.0/22
echo "Creating virtual network $CLUSTER_VNET in $RESOURCEGROUP..."
az network vnet create --resource-group $RESOURCEGROUP --name $CLUSTER_VNET --address-prefixes 10.0.0.0/22

# Create master subnet
echo "Creating master subnet $CLUSTER_MASTER_SUBNET in $CLUSTER_VNET..."
az network vnet subnet create --resource-group $CLUSTER_RESOURCE_GROUP --vnet-name $CLUSTER_VNET --name $CLUSTER_MASTER_SUBNET --address-prefixes 10.0.0.0/23 --service-endpoints Microsoft.ContainerRegistry
az network vnet subnet create --resource-group $RESOURCEGROUP --vnet-name $CLUSTER_VNET --name $CLUSTER_MASTER_SUBNET --address-prefixes 10.0.0.0/23 --service-endpoints Microsoft.ContainerRegistry

# Create worker subnet
echo "Creating worker subnet $CLUSTER_WORKER_SUBNET in $CLUSTER_VNET..."
az network vnet subnet create --resource-group $CLUSTER_RESOURCE_GROUP --vnet-name $CLUSTER_VNET --name $CLUSTER_WORKER_SUBNET --address-prefixes 10.0.2.0/23 --service-endpoints Microsoft.ContainerRegistry
az network vnet subnet create --resource-group $RESOURCEGROUP --vnet-name $CLUSTER_VNET --name $CLUSTER_WORKER_SUBNET --address-prefixes 10.0.2.0/23 --service-endpoints Microsoft.ContainerRegistry

# Create cluster
echo "Creating cluster $CLUSTER_NAME in $CLUSTER_RESOURCE_GROUP..."
az aro create --resource-group $CLUSTER_RESOURCE_GROUP --name $CLUSTER_NAME --vnet $CLUSTER_VNET --master-subnet $CLUSTER_MASTER_SUBNET --worker-subnet $CLUSTER_WORKER_SUBNET --pull-secret "$PULL_SECRET" --location $CLUSTER_LOCATION --version $OPENSHIFT_VERSION || {
echo "Creating cluster $CLUSTER_NAME in $RESOURCEGROUP..."
az aro create --resource-group $RESOURCEGROUP --name $CLUSTER_NAME --vnet $CLUSTER_VNET --master-subnet $CLUSTER_MASTER_SUBNET --worker-subnet $CLUSTER_WORKER_SUBNET --pull-secret "$PULL_SECRET" --location $LOCATION --version $OPENSHIFT_VERSION || {
echo "Cluster creation failed. Fetching deployment logs..."

# Fetch the deployment logs for further analysis
deployment_name=$(az deployment group list --resource-group $CLUSTER_RESOURCE_GROUP --query '[0].name' -o tsv)
deployment_name=$(az deployment group list --resource-group $RESOURCEGROUP --query '[0].name' -o tsv)
if [ -n "$deployment_name" ]; then
az deployment group show --name $deployment_name --resource-group $CLUSTER_RESOURCE_GROUP
az deployment group show --name $deployment_name --resource-group $RESOURCEGROUP
else
echo "No deployment found for resource group $CLUSTER_RESOURCE_GROUP."
echo "No deployment found for resource group $RESOURCEGROUP."
fi

exit 1
}

# Check for the existence of the cluster
if az aro show --name $CLUSTER_NAME --resource-group $CLUSTER_RESOURCE_GROUP &> /dev/null; then
if az aro show --name $CLUSTER_NAME --resource-group $RESOURCEGROUP &> /dev/null; then
echo "Cluster creation successful."
else
echo "Cluster creation failed. Please check the logs for more details."
exit 1
fi

echo "To list cluster credentials, run:"
echo " az aro list-credentials --name $CLUSTER_NAME --resource-group $CLUSTER_RESOURCE_GROUP"
echo " az aro list-credentials --name $CLUSTER_NAME --resource-group $RESOURCEGROUP"

# Validate RP running
validate_rp_running

# Set up port forwarding from 443 to 8443
echo "Setting up port forwarding from 443 to 8443..."
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
sudo iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDIRECT --to-port 8443

echo "Port forwarding setup complete."

0 comments on commit d37d3f9

Please sign in to comment.