mirror of https://github.com/rancher/dashboard.git
192 lines
6.2 KiB
Bash
Executable File
192 lines
6.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -x
|
|
|
|
# --------------------------------------
|
|
# ----------------------- Setup Env Vars
|
|
# --------------------------------------
|
|
|
|
# K3S_VERSION=v1.32.6+k3s1 // when using the 'latest' repo it can only (atm) install rc1 which has a max of 1.33
|
|
K3S_VERSION=v1.33.1+k3s1
|
|
|
|
# Helm Repo Info
|
|
# - rancher-latest will have released versions (--devel rc's)
|
|
# - RANCHER_HELM_REPO_URL=https://releases.rancher.com/server-charts/latest
|
|
# - rancher-alpha will have alphas (--devel required)
|
|
# - charts.optimus.rancher.io/server-charts/$RANCHER_RELEASE will have the latest and greatest chart
|
|
RANCHER_RELEASE=release-2.13
|
|
RANCHER_HELM_REPO_URL=https://charts.optimus.rancher.io/server-charts/$RANCHER_RELEASE
|
|
|
|
# rancher-latest --devel will have rc's and released versions. rancher-alpha will have alpha
|
|
RANCHER_HELM_REPO_NAME=rancher-$RANCHER_RELEASE
|
|
|
|
# Helm Image version
|
|
RANCHER_IMG_REPO=rancher/rancher
|
|
RANCHER_IMG_TAG=head
|
|
RANCHER_AGENT_IMG=rancher/rancher:head # eh
|
|
|
|
# check if script invoke contains any argument. If so, adjust RANCHER_IMG_TAG
|
|
if [ $# -eq 1 ]; then
|
|
RANCHER_IMG_TAG=$1
|
|
fi
|
|
|
|
DASHBOARD_URL="${TEST_BASE_URL#https://}"
|
|
RANCHER_NAMESPACE=cattle-system
|
|
|
|
DIR=$(cd $(dirname $0)/..; pwd)
|
|
|
|
# See `script/build-e2e`. This is the ui builds we wish to test
|
|
DASHBOARD_DIST=${DIR}/dist
|
|
EMBER_DIST=${DIR}/dist_ember
|
|
|
|
# - See https://ranchermanager.docs.rancher.com/how-to-guides/advanced-user-guides/enable-api-audit-log (0 off, 3 everything)
|
|
# - logs sent to side-car container in rancher pod
|
|
# - e2e-k3s-logs package task will capture logs in all containers in all rancher pods
|
|
RANCHER_AUDIT_LOG_LEVEL=3
|
|
|
|
# ---------------------------------
|
|
# ----------------------- Setup Env
|
|
# ---------------------------------
|
|
|
|
echo "Installing k3s (with kubectl).........."
|
|
# FIXME: cache this in gh
|
|
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="$K3S_VERSION" sh -
|
|
export KUBECONFIG=~/.kube/config
|
|
mkdir ~/.kube 2> /dev/null
|
|
sudo k3s kubectl config view --raw > "$KUBECONFIG"
|
|
chmod 600 "$KUBECONFIG"
|
|
|
|
echo "Installing helm.........."
|
|
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
|
chmod 700 get_helm.sh
|
|
./get_helm.sh
|
|
|
|
echo "Installing cert-manager.........."
|
|
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.7.1/cert-manager.crds.yaml
|
|
helm repo add jetstack https://charts.jetstack.io
|
|
helm repo update
|
|
helm install cert-manager jetstack/cert-manager \
|
|
--namespace cert-manager \
|
|
--create-namespace \
|
|
--version v1.7.1
|
|
|
|
echo "Cert manager pods should be up"
|
|
kubectl get pods --namespace cert-manager
|
|
|
|
echo "Setting up Rancher Repo.........."
|
|
helm repo add $RANCHER_HELM_REPO_NAME $RANCHER_HELM_REPO_URL
|
|
helm repo update
|
|
helm search repo $RANCHER_HELM_REPO_NAME --devel
|
|
|
|
# ---------------------------------------
|
|
# ----------------------- Install Rancher
|
|
# ---------------------------------------
|
|
|
|
echo "Installing Rancher.........."
|
|
kubectl create ns $RANCHER_NAMESPACE
|
|
helm install rancher $RANCHER_HELM_REPO_NAME/rancher \
|
|
--namespace cattle-system \
|
|
--devel \
|
|
--set hostname=$DASHBOARD_URL \
|
|
--set replicas="1" \
|
|
--set rancherImage="$RANCHER_IMG_REPO" \
|
|
--set rancherImageTag="$RANCHER_IMG_TAG" \
|
|
--set rancherImagePullPolicy="Always" \
|
|
--set auditLog.enabled=true \
|
|
--set auditLog.level=$RANCHER_AUDIT_LOG_LEVEL \
|
|
--set extraEnv\[0\].name="CATTLE_AGENT_IMAGE" \
|
|
--set-string extraEnv\[0\].value="$RANCHER_AGENT_IMG" \
|
|
--set extraEnv\[1\].name="CATTLE_UI_OFFLINE_PREFERRED" \
|
|
--set-string extraEnv\[1\].value="true" \
|
|
--set extraEnv\[2\].name="CATTLE_BOOTSTRAP_PASSWORD" \
|
|
--set-string extraEnv\[2\].value="password" \
|
|
--set extraEnv\[3\].name="CATTLE_PASSWORD_MIN_LENGTH" \
|
|
--set-string extraEnv\[3\].value="3" \
|
|
--set 'extraEnv[4].name=CATTLE_FEATURES' \
|
|
--set 'extraEnv[4].value=oidc-provider=true'
|
|
|
|
# ----------------------------------------------------
|
|
# ----------------------- Wait for Rancher to be ready
|
|
# ----------------------------------------------------
|
|
|
|
|
|
echo "Waiting for Rancher to come up.........."
|
|
kubectl -n cattle-system rollout status deploy/rancher
|
|
|
|
echo "Waiting for dashboard UI to be reachable.........."
|
|
|
|
okay=0
|
|
|
|
while [ $okay -lt 20 ]; do
|
|
STATUS=$(curl --silent --location --head -k $DASHBOARD_URL/dashboard/ | awk -F'HTTP/2 ' '{print $2}' | awk 'length { print $1}')
|
|
|
|
echo "Status: $STATUS (Try: $okay)"
|
|
|
|
okay=$((okay+1))
|
|
|
|
if [ "$STATUS" == "200" ]; then
|
|
okay=100
|
|
else
|
|
sleep 5
|
|
fi
|
|
done
|
|
|
|
if [ "$STATUS" != "200" ]; then
|
|
echo "Dashboard did not become available in a reasonable time"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Updating UI within Rancher container.........."
|
|
# Note - these will pick the first container within the pod, so replicas=1 above is important
|
|
POD_NAME=$(kubectl get pods --selector=app=rancher -n $RANCHER_NAMESPACE | tail -n 1 | cut -d ' ' -f1)
|
|
echo "POD NAME: $POD_NAME"
|
|
if [ "$POD_NAME" == "" ]; then
|
|
echo "Failed to find rancher pod"
|
|
exit 1
|
|
fi
|
|
|
|
# Remove root folders that container UIs
|
|
kubectl exec $POD_NAME -n $RANCHER_NAMESPACE -- sh -c 'rm -rf /usr/share/rancher/ui-dashboard/dashboard'
|
|
kubectl exec $POD_NAME -n $RANCHER_NAMESPACE -- sh -c 'rm -rf /usr/share/rancher/ui'
|
|
|
|
# Copy local builds to root folders that should contain UIs
|
|
mv $DASHBOARD_DIST dashboard
|
|
mv $EMBER_DIST ui
|
|
kubectl cp dashboard $POD_NAME:/usr/share/rancher/ui-dashboard -n $RANCHER_NAMESPACE
|
|
kubectl cp ui $POD_NAME:/usr/share/rancher -n $RANCHER_NAMESPACE
|
|
|
|
# Final validation
|
|
STATUS=$(curl --silent --location --head -k $DASHBOARD_URL/dashboard/ | awk -F'HTTP/2 ' '{print $2}' | awk 'length { print $1}')
|
|
echo "Status: $STATUS"
|
|
|
|
if [ "$STATUS" != "200" ]; then
|
|
echo "After updating dashboard with dev build it is no longer available"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Dashboard UI is ready"
|
|
|
|
echo "Waiting for rancher-webhook to be running..."
|
|
okay=0
|
|
while [ $okay -lt 30 ] ; do
|
|
if kubectl -n cattle-system get po -l app=rancher-webhook | grep -q '1/1.*Running' ; then
|
|
break
|
|
else
|
|
echo "Webhook not ready, checking again in 10s..."
|
|
okay=$((okay+1))
|
|
sleep 10
|
|
fi
|
|
done
|
|
|
|
echo "Waiting for capi-webhook-service to exist..."
|
|
okay=0
|
|
while [ $okay -lt 30 ] ; do
|
|
if kubectl -n cattle-provisioning-capi-system get service capi-webhook-service | grep '443/TCP' ; then
|
|
break
|
|
else
|
|
echo "capi-webhook-service does not exist, checking again in 10s..."
|
|
okay=$((okay+1))
|
|
sleep 10
|
|
fi
|
|
done
|
|
|
|
echo "Rancher is ready" |