|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function k8s_cleanup { |
| 4 | + local RELEASE=$1 |
| 5 | + local NAMESPACE=$2 |
| 6 | + |
| 7 | + # Create namespace if it doesn't exist. |
| 8 | + kubectl create namespace "$NAMESPACE" || true |
| 9 | + |
| 10 | + # Uninstall previous feast release if there is any. |
| 11 | + helm uninstall "$RELEASE" -n "$NAMESPACE" || true |
| 12 | + |
| 13 | + # `helm uninstall` doesn't remove PVCs, delete them manually. |
| 14 | + time kubectl delete pvc --all -n "$NAMESPACE" || true |
| 15 | + |
| 16 | + kubectl get service -n "$NAMESPACE" |
| 17 | + |
| 18 | + # Set a new postgres password. Note that the postgres instance is not available outside |
| 19 | + # the k8s cluster anyway so it doesn't have to be super secure. |
| 20 | + echo "${STEP_BREADCRUMB} Setting PG password" |
| 21 | + PG_PASSWORD=$(head -c 59 /dev/urandom | md5sum | head -c 16) |
| 22 | + kubectl delete secret feast-postgresql -n "$NAMESPACE" || true |
| 23 | + kubectl create secret generic feast-postgresql --from-literal=postgresql-password="$PG_PASSWORD" -n "$NAMESPACE" |
| 24 | +} |
| 25 | + |
| 26 | +function helm_install { |
| 27 | + # helm install Feast into k8s cluster and display a nice error if it fails. |
| 28 | + # Usage: helm_install $RELEASE $DOCKER_REPOSITORY $GIT_TAG ... |
| 29 | + # Args: |
| 30 | + # $RELEASE is helm release name |
| 31 | + # $DOCKER_REPOSITORY is the docker repo containing feast images tagged with $GIT_TAG |
| 32 | + # ... you can pass additional args to this function that are passed on to helm install |
| 33 | + |
| 34 | + local RELEASE=$1 |
| 35 | + local DOCKER_REPOSITORY=$2 |
| 36 | + local GIT_TAG=$3 |
| 37 | + |
| 38 | + shift 3 |
| 39 | + |
| 40 | + # Wait for images to be available in the docker repository; ci is the last image built |
| 41 | + timeout 15m bash -c 'while ! gcloud container images list-tags ${DOCKER_REPOSITORY}/feast-ci --format=json | jq -e ".[] | select(.tags[] | contains (\"$GIT_TAG\"))" > /dev/null; do sleep 10s; done' |
| 42 | + |
| 43 | + # We skip statsd exporter and other metrics stuff since we're not using it anyway, and it |
| 44 | + # has some issues with unbound PVCs (that cause kubectl delete pvc to hang). |
| 45 | + echo "${STEP_BREADCRUMB} Helm installing feast" |
| 46 | + |
| 47 | + if ! time helm install --wait "$RELEASE" infra/charts/feast \ |
| 48 | + --timeout 15m \ |
| 49 | + --set "feast-jupyter.image.repository=${DOCKER_REPOSITORY}/feast-jupyter" \ |
| 50 | + --set "feast-jupyter.image.tag=${GIT_TAG}" \ |
| 51 | + --set "feast-online-serving.image.repository=${DOCKER_REPOSITORY}/feast-serving" \ |
| 52 | + --set "feast-online-serving.image.tag=${GIT_TAG}" \ |
| 53 | + --set "feast-jobservice.image.repository=${DOCKER_REPOSITORY}/feast-jobservice" \ |
| 54 | + --set "feast-jobservice.image.tag=${GIT_TAG}" \ |
| 55 | + --set "feast-core.image.repository=${DOCKER_REPOSITORY}/feast-core" \ |
| 56 | + --set "feast-core.image.tag=${GIT_TAG}" \ |
| 57 | + --set "prometheus-statsd-exporter.enabled=false" \ |
| 58 | + --set "prometheus.enabled=false" \ |
| 59 | + --set "grafana.enabled=false" \ |
| 60 | + --set "feast-jobservice.enabled=false" \ |
| 61 | + "$@" ; then |
| 62 | + |
| 63 | + echo "Error during helm install. " |
| 64 | + kubectl -n "$NAMESPACE" get pods |
| 65 | + |
| 66 | + readarray -t CRASHED_PODS < <(kubectl -n "$NAMESPACE" get pods --no-headers=true | grep "$RELEASE" | awk '{if ($2 == "0/1") { print $1 } }') |
| 67 | + echo "Crashed pods: ${CRASHED_PODS[*]}" |
| 68 | + |
| 69 | + for POD in "${CRASHED_PODS[@]}"; do |
| 70 | + echo "Logs from pod error $POD:" |
| 71 | + kubectl -n "$NAMESPACE" logs "$POD" --previous |
| 72 | + done |
| 73 | + |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | +} |
| 77 | + |
| 78 | +function setup_sparkop_role { |
| 79 | + # Set up permissions for the default user in sparkop namespace so that Feast SDK can manage |
| 80 | + # sparkapplication resources from the test runner pod. |
| 81 | + |
| 82 | + cat <<EOF | kubectl apply -f - |
| 83 | +kind: Role |
| 84 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 85 | +metadata: |
| 86 | + name: use-spark-operator |
| 87 | +rules: |
| 88 | +- apiGroups: ["sparkoperator.k8s.io"] |
| 89 | + resources: ["sparkapplications"] |
| 90 | + verbs: ["create", "delete", "deletecollection", "get", "list", "update", "watch", "patch"] |
| 91 | +--- |
| 92 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 93 | +kind: RoleBinding |
| 94 | +metadata: |
| 95 | + name: use-spark-operator |
| 96 | +roleRef: |
| 97 | + kind: Role |
| 98 | + name: use-spark-operator |
| 99 | + apiGroup: rbac.authorization.k8s.io |
| 100 | +subjects: |
| 101 | + - kind: ServiceAccount |
| 102 | + name: default |
| 103 | +EOF |
| 104 | +} |
0 commit comments