github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/dev/k8s/utils/create_certs.sh (about) 1 #!/bin/bash 2 3 # install cert-manager 4 kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.1/cert-manager.yaml 5 6 sleep 10 7 8 # Namespace where cert-manager is installed 9 cert_manager_namespace="cert-manager" 10 11 # Get the list of pod names in the cert-manager namespace 12 pod_list=$(kubectl get pods -n "$cert_manager_namespace" -o custom-columns=:metadata.name --no-headers) 13 14 # Check if there are any pods in the list 15 if [ -z "$pod_list" ]; then 16 echo "No pods found in namespace $cert_manager_namespace." 17 exit 1 18 fi 19 20 # Print the list of pod names 21 echo "List of pods in namespace $cert_manager_namespace:" 22 echo "$pod_list" 23 24 # Function to check if a Kubernetes pod is in the "Running" state 25 function is_pod_running { 26 local pod_name="$1" 27 local pod_status=$(kubectl get pod -n "$cert_manager_namespace" "$pod_name" -o jsonpath='{.status.phase}') 28 29 if [ "$pod_status" == "Running" ]; then 30 return 0 # Pod is running 31 else 32 return 1 # Pod is not running 33 fi 34 } 35 36 # Function to check if a Kubernetes pod is ready 37 function is_pod_ready { 38 local pod_name="$1" 39 local pod_condition=$(kubectl get pod -n "$cert_manager_namespace" "$pod_name" -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') 40 41 if [ "$pod_condition" == "True" ]; then 42 return 0 # Pod is ready 43 else 44 return 1 # Pod is not ready 45 fi 46 } 47 48 # Maximum timeout (in seconds) 49 timeout_seconds=30 50 start_time=$(date +%s) 51 52 # Wait for all cert-manager pods to be in the "Running" and "Ready" state with a timeout 53 for pod_name in $pod_list; do 54 while ! is_pod_running "$pod_name" || ! is_pod_ready "$pod_name"; do 55 current_time=$(date +%s) 56 elapsed_time=$((current_time - start_time)) 57 58 if [ "$elapsed_time" -ge "$timeout_seconds" ]; then 59 echo "Timeout of $timeout_seconds seconds reached. Exiting." 60 exit 1 61 fi 62 63 echo "Waiting for pod $pod_name in namespace $cert_manager_namespace to be in the Running/Ready state..." 64 sleep 5 # Adjust the sleep interval as needed 65 done 66 echo "Pod $pod_name in namespace $cert_manager_namespace is Running/Ready state." 67 done 68 69 # Proceed with the next operations after all pods are ready 70 echo "All cert-manager pods in namespace $cert_manager_namespace are Running and Ready. Proceeding with next operations..." 71 # Your next operations here 72 73 # create cert-issuer and certificate 74 kubectl apply -f kube_templates/cert_manager.yaml