-
Notifications
You must be signed in to change notification settings - Fork 40
add canary related supporting infra #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| FROM ubuntu:18.04 | ||
|
|
||
| # Build time parameters | ||
| ARG SERVICE=sagemaker | ||
|
|
||
| RUN apt-get update && apt-get install -y curl \ | ||
| wget \ | ||
| git \ | ||
| python3.8 \ | ||
| python3-pip \ | ||
| python3.8-dev \ | ||
| vim \ | ||
| sudo \ | ||
| jq \ | ||
| unzip | ||
|
|
||
| # Install awscli | ||
| RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ | ||
| && unzip -qq awscliv2.zip \ | ||
| && ./aws/install | ||
|
|
||
| # Add yq repository and install yq | ||
| RUN apt-get update && apt install -y software-properties-common \ | ||
| && sudo add-apt-repository ppa:rmescandon/yq \ | ||
| && apt update && apt install -y yq | ||
|
|
||
| # Install kubectl | ||
| RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.6/bin/linux/amd64/kubectl \ | ||
| && chmod +x ./kubectl \ | ||
| && cp ./kubectl /bin | ||
|
|
||
| # Install eksctl | ||
| RUN curl --silent --location "https://github.com/weaveworks/eksctl/releases/download/latest_release/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp && mv /tmp/eksctl /bin | ||
|
|
||
| # Install Helm | ||
| RUN curl -q -L "https://get.helm.sh/helm-v3.2.4-linux-amd64.tar.gz" | tar zxf - -C /usr/local/bin/ \ | ||
| && mv /usr/local/bin/linux-amd64/helm /usr/local/bin/helm \ | ||
| && rm -r /usr/local/bin/linux-amd64 \ | ||
| && chmod +x /usr/local/bin/helm | ||
|
|
||
| ENV SERVICE_REPO_PATH=/$SERVICE-controller | ||
| COPY ./test/e2e/requirements.txt requirements.txt | ||
|
|
||
| RUN ln -s /usr/bin/python3.8 /usr/bin/python \ | ||
| && python -m pip install --upgrade pip | ||
|
|
||
| RUN python -m pip install -r requirements.txt | ||
|
|
||
| WORKDIR /$SERVICE_REPO_PATH | ||
| CMD ["./test/canary/scripts/run_test.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| version: 0.2 | ||
|
|
||
| phases: | ||
| pre_build: | ||
| commands: | ||
| # Make all shell scripts executable. This is required when running code copied from S3 | ||
| - find ./ -type f -name "*.sh" -exec chmod +x {} \; | ||
|
|
||
| # Get cached test image | ||
| - aws ecr get-login-password --region $CLUSTER_REGION | docker login --username AWS --password-stdin $ECR_CACHE_URI || true | ||
| - docker pull ${ECR_CACHE_URI}:latest --quiet || true | ||
|
|
||
| # Login to dockerhub to avoid hitting throttle limit | ||
| - docker login -u $DOCKER_CONFIG_USERNAME -p $DOCKER_CONFIG_PASSWORD | ||
|
|
||
| # Build test image | ||
| - > | ||
| docker build -f ./test/canary/Dockerfile.canary . -t ${ECR_CACHE_URI}:latest | ||
| --build-arg SERVICE="${SERVICE##*/}" --quiet | ||
| || echo "Docker Build Failed" || true | ||
| build: | ||
| commands: | ||
| # Run tests | ||
| - docker run --name ack-canary $(env | cut -f1 -d= | sed 's/^/-e /') --mount type=bind,source="$(pwd)/",target="/${SERVICE}-controller/" ${ECR_CACHE_URI}:latest | ||
|
|
||
| # Push test image to cache ECR repo | ||
| - docker push ${ECR_CACHE_URI}:latest || true | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Deploy ACK Helm Charts | ||
|
|
||
| function install_helm_chart() { | ||
| local service="$1" | ||
| local oidc_role_arn="$2" | ||
| local region="$3" | ||
| local namespace="$4" | ||
|
|
||
| yq w -i helm/values.yaml "serviceAccount.annotations" "" | ||
| yq w -i helm/values.yaml 'serviceAccount.annotations."eks.amazonaws.com/role-arn"' "$oidc_role_arn" | ||
| yq w -i helm/values.yaml "aws.region" $region | ||
|
|
||
| kubectl create namespace $namespace | ||
| helm install -n $namespace ack-$service-controller helm | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/bin/bash | ||
|
|
||
| # cleanup on EXIT regardles of error | ||
|
|
||
| # Inputs to this file as environment variables | ||
| # SERVICE | ||
| # SERVICE_REGION | ||
| # CLUSTER_REGION | ||
| # CLUSTER_NAME | ||
| # SERVICE_REPO_PATH | ||
| # NAMESPACE | ||
|
|
||
| set -euo pipefail | ||
| export NAMESPACE=${NAMESPACE:-"ack-system"} | ||
| export AWS_DEFAULT_REGION=$SERVICE_REGION | ||
| export E2E_DIR=$SERVICE_REPO_PATH/test/e2e/ | ||
| SCRIPTS_DIR=${SERVICE_REPO_PATH}/test/canary/scripts | ||
|
|
||
| source $SCRIPTS_DIR/setup_oidc.sh | ||
| source $SCRIPTS_DIR/install_controller_helm.sh | ||
|
|
||
| function print_controller_logs() { | ||
| pod_id=$( kubectl get pods -n $NAMESPACE --field-selector="status.phase=Running" \ | ||
| --sort-by=.metadata.creationTimestamp \ | ||
| | grep ack-sagemaker-controller | awk '{print $1}' 2>/dev/null ) | ||
|
|
||
| kubectl -n $NAMESPACE logs "$pod_id" | ||
| } | ||
|
|
||
| function cleanup { | ||
| echo "Cleaning up resources" | ||
| set +e | ||
| kubectl delete endpoints.sagemaker --all | ||
| kubectl delete endpointconfigs --all | ||
| kubectl delete models --all | ||
| kubectl delete trainingjobs --all | ||
| kubectl delete processingjobs --all | ||
| kubectl delete transformjobs --all | ||
| kubectl delete hyperparametertuningjobs --all | ||
| kubectl delete dataqualityjobdefinitions --all | ||
| kubectl delete modelbiasjobdefinitions --all | ||
| kubectl delete modelexplainabilityjobdefinitions --all | ||
| kubectl delete modelqualityjobdefinitions --all | ||
| kubectl delete monitoringschedules --all | ||
| kubectl delete adoptedresources --all | ||
|
|
||
| print_controller_logs | ||
|
|
||
| helm delete -n $NAMESPACE ack-$SERVICE-controller | ||
| kubectl delete namespace $NAMESPACE | ||
|
|
||
| cd $E2E_DIR | ||
| export PYTHONPATH=.. | ||
| python service_cleanup.py | ||
|
|
||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| # Update kubeconfig | ||
| aws --region $CLUSTER_REGION eks update-kubeconfig --name $CLUSTER_NAME | ||
|
|
||
| # Setup OIDC | ||
| create_oidc_role "$CLUSTER_NAME" "$CLUSTER_REGION" "$NAMESPACE" | ||
|
|
||
| # Install service helm chart | ||
| install_helm_chart $SERVICE $OIDC_ROLE_ARN $SERVICE_REGION $NAMESPACE | ||
|
|
||
| echo "Log helm charts are deployed properly" | ||
| kubectl -n $NAMESPACE get pods | ||
| kubectl get crds | ||
|
|
||
| pushd $E2E_DIR | ||
| export PYTHONPATH=.. | ||
| # create resources for test | ||
| python service_bootstrap.py | ||
| sleep 5m | ||
|
|
||
| # run tests | ||
| echo "Run Tests" | ||
| pytest -n 10 --dist loadfile --log-cli-level INFO -m canary | ||
| popd | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/usr/bin/env bash | ||
| # OIDC Setup | ||
|
|
||
| # A function to get the OIDC_ID associated with an EKS cluster | ||
| function get_oidc_id() { | ||
| local cluster_name="$1" | ||
| local region = "$2" | ||
| eksctl utils associate-iam-oidc-provider --cluster $cluster_name --region $region --approve | ||
| local oidc_url=$(aws eks describe-cluster --region $region --name $cluster_name --query "cluster.identity.oidc.issuer" --output text | cut -c9-) | ||
| echo "${oidc_url}" | ||
| } | ||
|
|
||
|
|
||
| function generate_trust_policy() { | ||
| local oidc_url="$1" | ||
| local namespace="$2" | ||
| local account_id=$(aws sts get-caller-identity --output text --query "Account") | ||
|
|
||
| cat <<EOF > trust.json | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Principal": { | ||
| "Federated": "arn:aws:iam::${account_id}:oidc-provider/${oidc_url}" | ||
| }, | ||
| "Action": "sts:AssumeRoleWithWebIdentity", | ||
| "Condition": { | ||
| "StringEquals": { | ||
| "${oidc_url}:aud": "sts.amazonaws.com", | ||
| "${oidc_url}:sub": ["system:serviceaccount:${namespace}:ack-sagemaker-controller"] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| EOF | ||
| } | ||
|
|
||
| function create_oidc_role() { | ||
| local cluster_name="$1" | ||
| local region="$2" | ||
| local namespace="$3" | ||
| local oidc_role_name=ack-oidc-role-$cluster_name-$namespace | ||
surajkota marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Create role only if it does not exist | ||
| set +e | ||
| aws iam get-role --role-name ${oidc_role_name} | ||
| exit_code=$? | ||
| set -euo pipefail | ||
|
|
||
| if [[ $exit_code -eq 0 ]]; then | ||
| echo "A role for this cluster and namespace already exists in this account, assuming sagemaker access and proceeding." | ||
| else | ||
| echo "Creating new IAM role: $oidc_role_name" | ||
| local oidc_url=$(get_oidc_id "$cluster_name" "$region") | ||
| local trustfile="trust.json" | ||
| generate_trust_policy "$oidc_url" "$namespace" | ||
| aws iam create-role --role-name "$oidc_role_name" --assume-role-policy-document file://${trustfile} | ||
| aws iam attach-role-policy --role-name "$oidc_role_name" --policy-arn arn:aws:iam::aws:policy/AmazonSageMakerFullAccess | ||
| aws iam attach-role-policy --role-name "$oidc_role_name" --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess | ||
| rm "${trustfile}" | ||
| fi | ||
| local oidc_role_arn=$(aws iam get-role --role-name $oidc_role_name --output text --query 'Role.Arn') | ||
| export OIDC_ROLE_ARN=$oidc_role_arn | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@955d7831ee374a212250179e95a5f3b75e555fd9 | ||
| acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@5ed60a505afa953096e53c9d3d6779830250915b | ||
| black==20.8b1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means we won't be able to run codebuild tests in parallel as one test might delete resources being used in another test.
Right now we don't need this as we don't have a problem of leaking resources.
By doing this we will not come to know if there are some leaking resources in future.
I think we should just handle these kinds of cleanup better in the the tests itself.
(this will help while running tests locally too as they might leave resources behind)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there will some more work to make them run in parallel like not installing helm charts
lets keep this until then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also there is the problem of finalizer where delete might get stuck forever