@@ -20,6 +20,7 @@ function echoerr {
2020 >&2 echo " $@ "
2121}
2222
23+ CLUSTER=" "
2324REGION=" us-east-2"
2425K8S_VERSION=" 1.21"
2526AWS_NODE_TYPE=" t3.medium"
@@ -32,6 +33,7 @@ KUBECONFIG_PATH="$HOME/jenkins/out/eks"
3233MODE=" report"
3334TEST_SCRIPT_RC=0
3435KUBE_CONFORMANCE_IMAGE_VERSION=auto
36+ INSTALL_EKSCTL=true
3537
3638_usage=" Usage: $0 [--cluster-name <EKSClusterNameToUse>] [--kubeconfig <KubeconfigSavePath>] [--k8s-version <ClusterVersion>]\
3739 [--aws-access-key <AccessKey>] [--aws-secret-key <SecretKey>] [--aws-region <Region>] [--ssh-key <SSHKey] \
@@ -48,7 +50,8 @@ Setup a EKS cluster to run K8s e2e community tests (Conformance & Network Policy
4850 --ssh-key The path of key to be used for ssh access to worker nodes.
4951 --log-mode Use the flag to set either 'report', 'detail', or 'dump' level data for sonobouy results.
5052 --setup-only Only perform setting up the cluster and run test.
51- --cleanup-only Only perform cleaning up the cluster."
53+ --cleanup-only Only perform cleaning up the cluster.
54+ --skip-eksctl-install Do not install the latest eksctl version. Eksctl must be installed already."
5255
5356function print_usage {
5457 echoerr " $_usage "
@@ -109,6 +112,10 @@ case $key in
109112 RUN_ALL=false
110113 shift
111114 ;;
115+ --skip-eksctl-install)
116+ INSTALL_EKSCTL=false
117+ shift
118+ ;;
112119 -h|--help)
113120 print_usage
114121 exit 0
@@ -120,6 +127,39 @@ case $key in
120127esac
121128done
122129
130+ if [[ " $CLUSTER " == " " ]]; then
131+ echoerr " --cluster-name is required"
132+ exit 1
133+ fi
134+
135+ function generate_eksctl_config() {
136+ AMI_ID=$( aws ssm get-parameter \
137+ --name /aws/service/eks/optimized-ami/${K8S_VERSION} /amazon-linux-2/recommended/image_id \
138+ --query " Parameter.Value" --output text)
139+
140+ cat > eksctl-containerd.yaml << EOF
141+ ---
142+ apiVersion: eksctl.io/v1alpha5
143+ kind: ClusterConfig
144+ metadata:
145+ name: ${CLUSTER}
146+ region: ${REGION}
147+ version: "${K8S_VERSION} "
148+ managedNodeGroups:
149+ - name: containerd
150+ instanceType: ${AWS_NODE_TYPE}
151+ desiredCapacity: 2
152+ ami: ${AMI_ID}
153+ ssh:
154+ allow: true
155+ publicKeyPath: ${SSH_KEY_PATH}
156+ overrideBootstrapCommand: |
157+ #!/bin/bash
158+ /etc/eks/bootstrap.sh ${CLUSTER} --container-runtime containerd
159+ EOF
160+ echo " eksctl-containerd.yaml"
161+ }
162+
123163function setup_eks() {
124164
125165 echo " === This cluster to be created is named: ${CLUSTER} ==="
@@ -139,20 +179,21 @@ ${AWS_SECRET_KEY}
139179${REGION}
140180JSON
141181EOF
142- echo " === Installing latest version of eksctl ==="
143- curl --silent --location " https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$( uname -s) _amd64.tar.gz" | tar xz -C /tmp
144- sudo mv /tmp/eksctl /usr/local/bin
182+ if [[ " $INSTALL_EKSCTL " == true ]]; then
183+ echo " === Installing latest version of eksctl ==="
184+ curl --silent --location " https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$( uname -s) _amd64.tar.gz" | tar xz -C /tmp
185+ sudo mv /tmp/eksctl /usr/local/bin
186+ fi
145187 set -e
146188 printf " \n"
189+ echo " === Using the following eksctl ==="
190+ which eksctl
147191 echo " === Using the following kubectl ==="
148192 which kubectl
149193
150194 echo ' === Creating a cluster in EKS ==='
151- eksctl create cluster \
152- --name ${CLUSTER} --region ${REGION} --version=${K8S_VERSION} \
153- --nodegroup-name workers --node-type ${AWS_NODE_TYPE} --nodes 2 \
154- --ssh-access --ssh-public-key ${SSH_KEY_PATH} \
155- --managed
195+ config=" $( generate_eksctl_config) "
196+ eksctl create cluster -f $config
156197 if [[ $? -ne 0 ]]; then
157198 echo " === Failed to deploy EKS cluster! ==="
158199 exit 1
@@ -203,7 +244,7 @@ function deliver_antrea_to_eks() {
203244
204245 kubectl get nodes -o wide --no-headers=true | awk ' {print $7}' | while read IP; do
205246 scp -o StrictHostKeyChecking=no -i ${SSH_PRIVATE_KEY_PATH} ${antrea_image} .tar ec2-user@${IP} :~
206- ssh -o StrictHostKeyChecking=no -i ${SSH_PRIVATE_KEY_PATH} -n ec2-user@${IP} " sudo docker load -i ~/${antrea_image} .tar ; sudo docker tag ${DOCKER_IMG_NAME} :${DOCKER_IMG_VERSION} ${DOCKER_IMG_NAME} :latest"
247+ ssh -o StrictHostKeyChecking=no -i ${SSH_PRIVATE_KEY_PATH} -n ec2-user@${IP} " sudo ctr -n=k8s.io images import ~/${antrea_image} .tar ; sudo ctr -n=k8s.io images tag ${DOCKER_IMG_NAME} :${DOCKER_IMG_VERSION} ${DOCKER_IMG_NAME} :latest --force "
207248 done
208249 rm ${antrea_image} .tar
209250
0 commit comments