|
1 | 1 | #!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +STEP_BREADCRUMB='~~~~~~~~' |
| 6 | +SECONDS=0 |
| 7 | +TIMEFORMAT="${STEP_BREADCRUMB} took %R seconds" |
| 8 | + |
| 9 | +function k8s_cleanup { |
| 10 | + local RELEASE=$1 |
| 11 | + local NAMESPACE=$2 |
| 12 | + |
| 13 | + # Create namespace if it doesn't exist. |
| 14 | + kubectl create namespace "$NAMESPACE" || true |
| 15 | + |
| 16 | + # Uninstall previous feast release if there is any. |
| 17 | + helm uninstall "$RELEASE" -n "$NAMESPACE" || true |
| 18 | + |
| 19 | + # `helm uninstall` doesn't remove PVCs, delete them manually. |
| 20 | + time kubectl delete pvc --all -n "$NAMESPACE" || true |
| 21 | + |
| 22 | + kubectl get service -n "$NAMESPACE" |
| 23 | + |
| 24 | + # Set a new postgres password. Note that the postgres instance is not available outside |
| 25 | + # the k8s cluster anyway so it doesn't have to be super secure. |
| 26 | + echo "${STEP_BREADCRUMB} Setting PG password" |
| 27 | + PG_PASSWORD=$(head -c 59 /dev/urandom | md5sum | head -c 16) |
| 28 | + kubectl delete secret feast-postgresql -n "$NAMESPACE" || true |
| 29 | + kubectl create secret generic feast-postgresql --from-literal=postgresql-password="$PG_PASSWORD" -n "$NAMESPACE" |
| 30 | +} |
| 31 | + |
| 32 | +function helm_install { |
| 33 | + # helm install Feast into k8s cluster and display a nice error if it fails. |
| 34 | + # Usage: helm_install $RELEASE $DOCKER_REPOSITORY $GIT_TAG ... |
| 35 | + # Args: |
| 36 | + # $RELEASE is helm release name |
| 37 | + # $DOCKER_REPOSITORY is the docker repo containing feast images tagged with $GIT_TAG |
| 38 | + # ... you can pass additional args to this function that are passed on to helm install |
| 39 | + |
| 40 | + local RELEASE=$1 |
| 41 | + local DOCKER_REPOSITORY=$2 |
| 42 | + local GIT_TAG=$3 |
| 43 | + |
| 44 | + shift 3 |
| 45 | + |
| 46 | + # We skip statsd exporter and other metrics stuff since we're not using it anyway, and it |
| 47 | + # has some issues with unbound PVCs (that cause kubectl delete pvc to hang). |
| 48 | + echo "${STEP_BREADCRUMB} Helm installing feast" |
| 49 | + |
| 50 | + if ! time helm install --wait "$RELEASE" infra/charts/feast \ |
| 51 | + --timeout 15m \ |
| 52 | + --set "feast-jupyter.image.repository=${DOCKER_REPOSITORY}/feast-jupyter" \ |
| 53 | + --set "feast-jupyter.image.tag=${GIT_TAG}" \ |
| 54 | + --set "feast-online-serving.image.repository=${DOCKER_REPOSITORY}/feast-serving" \ |
| 55 | + --set "feast-online-serving.image.tag=${GIT_TAG}" \ |
| 56 | + --set "feast-jobservice.image.repository=${DOCKER_REPOSITORY}/feast-jobservice" \ |
| 57 | + --set "feast-jobservice.image.tag=${GIT_TAG}" \ |
| 58 | + --set "feast-core.image.repository=${DOCKER_REPOSITORY}/feast-core" \ |
| 59 | + --set "feast-core.image.tag=${GIT_TAG}" \ |
| 60 | + --set "prometheus-statsd-exporter.enabled=false" \ |
| 61 | + --set "prometheus.enabled=false" \ |
| 62 | + --set "grafana.enabled=false" \ |
| 63 | + --set "feast-jobservice.enabled=false" \ |
| 64 | + "$@" ; then |
| 65 | + |
| 66 | + echo "Error during helm install. " |
| 67 | + kubectl -n "$NAMESPACE" get pods |
| 68 | + |
| 69 | + readarray -t CRASHED_PODS < <(kubectl -n "$NAMESPACE" get pods --no-headers=true | grep "$RELEASE" | awk '{if ($2 == "0/1") { print $1 } }') |
| 70 | + echo "Crashed pods: ${CRASHED_PODS[*]}" |
| 71 | + |
| 72 | + for POD in "${CRASHED_PODS[@]}"; do |
| 73 | + echo "Logs from pod error $POD:" |
| 74 | + kubectl -n "$NAMESPACE" logs "$POD" --previous |
| 75 | + done |
| 76 | + |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | +} |
| 80 | + |
| 81 | +function setup_sparkop_role { |
| 82 | + # Set up permissions for the default user in sparkop namespace so that Feast SDK can manage |
| 83 | + # sparkapplication resources from the test runner pod. |
| 84 | + |
| 85 | + cat <<EOF | kubectl apply -f - |
| 86 | +kind: Role |
| 87 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 88 | +metadata: |
| 89 | + name: use-spark-operator |
| 90 | +rules: |
| 91 | +- apiGroups: ["sparkoperator.k8s.io"] |
| 92 | + resources: ["sparkapplications"] |
| 93 | + verbs: ["create", "delete", "deletecollection", "get", "list", "update", "watch", "patch"] |
| 94 | +--- |
| 95 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 96 | +kind: RoleBinding |
| 97 | +metadata: |
| 98 | + name: use-spark-operator |
| 99 | +roleRef: |
| 100 | + kind: Role |
| 101 | + name: use-spark-operator |
| 102 | + apiGroup: rbac.authorization.k8s.io |
| 103 | +subjects: |
| 104 | + - kind: ServiceAccount |
| 105 | + name: default |
| 106 | +EOF |
| 107 | +} |
| 108 | + |
| 109 | +GIT_TAG=$(git rev-parse HEAD) |
| 110 | +GIT_REMOTE_URL=$(git config --get remote.origin.url) |
| 111 | + |
| 112 | +echo "########## Starting e2e tests for ${GIT_REMOTE_URL} ${GIT_TAG} ###########" |
| 113 | + |
| 114 | +# This seems to make builds a bit faster. |
| 115 | +export DOCKER_BUILDKIT=1 |
| 116 | + |
| 117 | +# Workaround for COPY command in core docker image that pulls local maven repo into the image |
| 118 | +# itself. |
| 119 | +mkdir .m2 2>/dev/null || true |
| 120 | + |
| 121 | +# Log into k8s. |
| 122 | +echo "${STEP_BREADCRUMB} Updating kubeconfig" |
| 123 | +az login --service-principal -u "$AZ_SERVICE_PRINCIPAL_ID" -p "$AZ_SERVICE_PRINCIPAL_PASS" --tenant "$AZ_SERVICE_PRINCIPAL_TENANT_ID" |
| 124 | +az aks get-credentials --resource-group "$RESOURCE_GROUP" --name "$AKS_CLUSTER_NAME" |
| 125 | + |
| 126 | +# Sanity check that kubectl is working. |
| 127 | +echo "${STEP_BREADCRUMB} k8s sanity check" |
| 128 | +kubectl get pods |
| 129 | + |
| 130 | +# e2e test - runs in sparkop namespace for consistency with AWS sparkop test. |
| 131 | +NAMESPACE=sparkop |
| 132 | +RELEASE=sparkop |
| 133 | + |
| 134 | +# Delete old helm release and PVCs |
| 135 | +k8s_cleanup "$RELEASE" "$NAMESPACE" |
| 136 | + |
| 137 | +# Helm install everything in a namespace |
| 138 | +helm_install "$RELEASE" "${DOCKER_REPOSITORY}" "${GIT_TAG}" --namespace "$NAMESPACE" |
| 139 | + |
| 140 | +# Delete old test running pod if it exists |
| 141 | +kubectl delete pod -n "$NAMESPACE" ci-test-runner 2>/dev/null || true |
| 142 | + |
| 143 | +# Delete all sparkapplication resources that may be left over from the previous test runs. |
| 144 | +kubectl delete sparkapplication --all -n "$NAMESPACE" || true |
| 145 | + |
| 146 | +# Make sure the test pod has permissions to create sparkapplication resources |
| 147 | +setup_sparkop_role |
| 148 | + |
| 149 | +# Run the test suite as a one-off pod. |
| 150 | +echo "${STEP_BREADCRUMB} Running the test suite" |
| 151 | +time kubectl run --rm -n "$NAMESPACE" -i ci-test-runner \ |
| 152 | + --restart=Never \ |
| 153 | + --image="${DOCKER_REPOSITORY}/feast-ci:${GIT_TAG}" \ |
| 154 | + --env="STAGING_PATH=$STAGING_PATH" \ |
| 155 | + -- \ |
| 156 | + bash -c "mkdir src && cd src && git clone $GIT_REMOTE_URL && cd feast && git config remote.origin.fetch '+refs/pull/*:refs/remotes/origin/pull/*' && git fetch -q && git checkout $GIT_TAG && ./infra/scripts/setup-e2e-env-sparkop.sh && ./infra/scripts/test-end-to-end-sparkop.sh" |
| 157 | + |
| 158 | +echo "########## e2e tests took $SECONDS seconds ###########" |
0 commit comments