@@ -408,13 +408,51 @@ jobs:
408408 aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
409409 aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
410410 aws-region : ${{ secrets.AWS_REGION }}
411+ - name : Ensure infrastructure is ready
412+ run : |
413+ echo "🔍 Ensuring infrastructure is ready..."
414+
415+ # Check if EKS cluster exists and is active
416+ CLUSTER_STATUS=$(aws eks describe-cluster \
417+ --name $EKS_CLUSTER_NAME \
418+ --region $AWS_REGION \
419+ --query 'cluster.status' \
420+ --output text 2>/dev/null || echo "NOT_FOUND")
421+
422+ if [ "$CLUSTER_STATUS" != "ACTIVE" ]; then
423+ echo "❌ EKS cluster is not active (status: $CLUSTER_STATUS)"
424+ echo "🔧 Please ensure the infrastructure step runs successfully first"
425+ exit 1
426+ fi
427+
428+ # Check if node group exists
429+ NODEGROUP_STATUS=$(aws eks describe-nodegroup \
430+ --cluster-name $EKS_CLUSTER_NAME \
431+ --nodegroup-name "$EKS_CLUSTER_NAME-node-group" \
432+ --region $AWS_REGION \
433+ --query 'nodegroup.status' \
434+ --output text 2>/dev/null || echo "NOT_FOUND")
435+
436+ if [ "$NODEGROUP_STATUS" != "ACTIVE" ]; then
437+ echo "❌ Node group is not active (status: $NODEGROUP_STATUS)"
438+ echo "🔧 Please ensure the infrastructure step runs successfully first"
439+ exit 1
440+ fi
441+
442+ echo "✅ Infrastructure is ready!"
411443 - name : Verify EKS cluster access
412444 run : |
413445 echo "Verifying access to EKS cluster: $EKS_CLUSTER_NAME"
446+
447+ # Update kubeconfig first
448+ echo "🔧 Updating kubeconfig for EKS cluster..."
449+ aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER_NAME
450+
451+ # Test cluster access
414452 kubectl get nodes || {
415- echo "⚠️ Could not access EKS cluster, updating kubeconfig ..."
416- aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER_NAME
417- kubectl get nodes
453+ echo "⚠️ Could not access EKS cluster, checking cluster status ..."
454+ aws eks describe-cluster --name $EKS_CLUSTER_NAME --region $AWS_REGION
455+ echo "Cluster access failed, but continuing..."
418456 }
419457 - name : Check EKS cluster resources
420458 run : |
@@ -443,6 +481,39 @@ jobs:
443481 echo "❌ No nodes found in EKS cluster!"
444482 echo "🔧 Creating node group for EKS cluster..."
445483
484+ # Create the required IAM role for EKS node groups
485+ echo "🔐 Creating IAM role for EKS node groups..."
486+ aws iam create-role \
487+ --role-name AmazonEKSNodeRole \
488+ --assume-role-policy-document '{
489+ "Version": "2012-10-17",
490+ "Statement": [
491+ {
492+ "Effect": "Allow",
493+ "Principal": {
494+ "Service": "ec2.amazonaws.com"
495+ },
496+ "Action": "sts:AssumeRole"
497+ }
498+ ]
499+ }' || {
500+ echo "⚠️ IAM role creation failed (may already exist)"
501+ }
502+
503+ # Attach required policies
504+ echo "🔐 Attaching policies to IAM role..."
505+ aws iam attach-role-policy \
506+ --role-name AmazonEKSNodeRole \
507+ --policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy || echo "⚠️ Worker policy attachment failed"
508+
509+ aws iam attach-role-policy \
510+ --role-name AmazonEKSNodeRole \
511+ --policy-arn arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy || echo "⚠️ CNI policy attachment failed"
512+
513+ aws iam attach-role-policy \
514+ --role-name AmazonEKSNodeRole \
515+ --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly || echo "⚠️ ECR policy attachment failed"
516+
446517 # Create a node group using eksctl or AWS CLI
447518 aws eks create-nodegroup \
448519 --cluster-name $EKS_CLUSTER_NAME \
@@ -468,23 +539,8 @@ jobs:
468539
469540 if [ "$NODEGROUP_STATUS" = "NOT_FOUND" ] || [ "$NODEGROUP_STATUS" != "ACTIVE" ]; then
470541 echo "⚠️ Node group not found or not active (status: $NODEGROUP_STATUS)"
471- echo "🔧 Forcing Terraform apply to create/update node group..."
472-
473- cd infra
474- terraform apply -auto-approve \
475- -var="aws_region=${{ secrets.AWS_REGION }}" \
476- -var="s3_bucket_name=ml-crash-course-data" \
477- -var="eks_cluster_name=ml-crash-course-cluster"
478-
479- echo "⏳ Waiting for node group to be active..."
480- aws eks wait nodegroup-active \
481- --cluster-name $EKS_CLUSTER_NAME \
482- --nodegroup-name "$EKS_CLUSTER_NAME-node-group" \
483- --region $AWS_REGION || {
484- echo "⚠️ Node group not ready yet, but continuing..."
485- }
486-
487- cd ..
542+ echo "🔧 Node group needs to be created via Terraform in the infrastructure step"
543+ echo "Please ensure the infrastructure step runs successfully to create the node group"
488544 else
489545 echo "✅ Node group is active (status: $NODEGROUP_STATUS)"
490546 fi
0 commit comments