2020-11-14 20:07:14 +09:00
#!/usr/bin/env bash
set -e
tpe = ${ ACCEPTANCE_TEST_SECRET_TYPE }
2021-05-11 06:30:57 +00:00
VALUES_FILE = ${ VALUES_FILE :- $( dirname $0 ) /values.yaml }
2022-03-12 12:10:04 +00:00
kubectl delete secret -n actions-runner-system controller-manager || :
2022-02-16 11:42:38 +00:00
2020-11-14 20:07:14 +09:00
if [ " ${ tpe } " = = "token" ] ; then
2021-05-02 16:31:07 +09:00
if ! kubectl get secret controller-manager -n actions-runner-system >/dev/null; then
kubectl create secret generic controller-manager \
-n actions-runner-system \
--from-literal= github_token = ${ GITHUB_TOKEN : ?GITHUB_TOKEN must not be empty }
fi
2020-11-14 20:07:14 +09:00
elif [ " ${ tpe } " = = "app" ] ; then
kubectl create secret generic controller-manager \
-n actions-runner-system \
--from-literal= github_app_id = ${ APP_ID : ?must not be empty } \
2022-03-12 12:10:04 +00:00
--from-literal= github_app_installation_id = ${ APP_INSTALLATION_ID : ?must not be empty } \
--from-file= github_app_private_key = ${ APP_PRIVATE_KEY_FILE : ?must not be empty }
2020-11-14 20:07:14 +09:00
else
echo "ACCEPTANCE_TEST_SECRET_TYPE must be set to either \"token\" or \"app\"" 1>& 2
exit 1
fi
2022-02-17 09:16:16 +09:00
if [ -n " ${ WEBHOOK_GITHUB_TOKEN } " ] ; then
kubectl -n actions-runner-system delete secret \
github-webhook-server || :
kubectl -n actions-runner-system create secret generic \
github-webhook-server \
--from-literal= github_token = ${ WEBHOOK_GITHUB_TOKEN : ?WEBHOOK_GITHUB_TOKEN must not be empty }
else
echo 'Skipped deploying secret "github-webhook-server". Set WEBHOOK_GITHUB_TOKEN to deploy.' 1>& 2
fi
2022-12-10 08:24:28 +09:00
if [ -n " ${ WEBHOOK_GITHUB_TOKEN } " ] ; then
kubectl -n actions-runner-system delete secret \
actions-metrics-server || :
kubectl -n actions-runner-system create secret generic \
actions-metrics-server \
--from-literal= github_token = ${ WEBHOOK_GITHUB_TOKEN : ?WEBHOOK_GITHUB_TOKEN must not be empty }
else
echo 'Skipped deploying secret "actions-metrics-server". Set WEBHOOK_GITHUB_TOKEN to deploy.' 1>& 2
fi
2020-11-14 20:31:37 +09:00
tool = ${ ACCEPTANCE_TEST_DEPLOYMENT_TOOL }
2022-02-19 09:24:12 +00:00
TEST_ID = ${ TEST_ID :- default }
2020-11-14 20:31:37 +09:00
if [ " ${ tool } " = = "helm" ] ; then
2022-02-19 09:24:12 +00:00
set -v
2022-08-25 10:25:06 +09:00
CHART = ${ CHART :- charts /actions-runner-controller }
2022-07-17 19:43:01 +09:00
flags = ( )
if [ " ${ IMAGE_PULL_SECRET } " != "" ] ; then
flags += ( --set imagePullSecrets[ 0] .name= ${ IMAGE_PULL_SECRET } )
flags += ( --set image.actionsRunnerImagePullSecrets[ 0] .name= ${ IMAGE_PULL_SECRET } )
flags += ( --set githubWebhookServer.imagePullSecrets[ 0] .name= ${ IMAGE_PULL_SECRET } )
2022-12-10 08:24:28 +09:00
flags += ( --set actionsMetricsServer.imagePullSecrets[ 0] .name= ${ IMAGE_PULL_SECRET } )
2022-07-17 19:43:01 +09:00
fi
2022-08-25 10:25:06 +09:00
if [ " ${ CHART_VERSION } " != "" ] ; then
flags += ( --version ${ CHART_VERSION } )
fi
2022-11-04 01:46:58 +00:00
if [ " ${ LOG_FORMAT } " != "" ] ; then
flags += ( --set logFormat = ${ LOG_FORMAT } )
flags += ( --set githubWebhookServer.logFormat= ${ LOG_FORMAT } )
2022-12-10 08:24:28 +09:00
flags += ( --set actionsMetricsServer.logFormat= ${ LOG_FORMAT } )
2022-11-04 01:46:58 +00:00
fi
2022-08-25 10:25:06 +09:00
2022-07-17 19:43:01 +09:00
set -vx
2022-08-25 10:25:06 +09:00
2020-11-14 20:31:37 +09:00
helm upgrade --install actions-runner-controller \
2022-08-25 10:25:06 +09:00
${ CHART } \
2020-11-14 20:31:37 +09:00
-n actions-runner-system \
2020-11-14 21:58:16 +09:00
--create-namespace \
2021-05-02 16:31:07 +09:00
--set syncPeriod = ${ SYNC_PERIOD } \
2021-05-01 08:10:57 +02:00
--set authSecret.create= false \
--set image.repository= ${ NAME } \
2021-05-11 06:30:57 +00:00
--set image.tag= ${ VERSION } \
2022-02-19 09:24:12 +00:00
--set podAnnotations.test-id= ${ TEST_ID } \
--set githubWebhookServer.podAnnotations.test-id= ${ TEST_ID } \
2022-12-10 08:24:28 +09:00
--set actionsMetricsServer.podAnnotations.test-id= ${ TEST_ID } \
2022-07-17 19:43:01 +09:00
${ flags [@] } --set image.imagePullPolicy= ${ IMAGE_PULL_POLICY } \
2021-05-11 06:30:57 +00:00
-f ${ VALUES_FILE }
2022-02-19 09:24:12 +00:00
set +v
2022-02-16 11:44:28 +00:00
# To prevent `CustomResourceDefinition.apiextensions.k8s.io "runners.actions.summerwind.dev" is invalid: metadata.annotations: Too long: must have at most 262144 bytes`
# errors
kubectl create -f charts/actions-runner-controller/crds || kubectl replace -f charts/actions-runner-controller/crds
2022-02-27 11:49:50 +00:00
# This wait fails due to timeout when it's already in crashloopback and this update doesn't change the image tag.
# That's why we add `|| :`. With that we prevent stopping the script in case of timeout and
# proceed to delete (possibly in crashloopback and/or running with outdated image) pods so that they are recreated by K8s.
kubectl -n actions-runner-system wait deploy/actions-runner-controller --for condition = available --timeout 60s || :
2020-11-14 20:31:37 +09:00
else
kubectl apply \
-n actions-runner-system \
-f release/actions-runner-controller.yaml
2022-02-27 11:49:50 +00:00
kubectl -n actions-runner-system wait deploy/controller-manager --for condition = available --timeout 120s || :
2020-11-14 20:31:37 +09:00
fi
2020-11-14 20:07:14 +09:00
2022-02-27 11:49:50 +00:00
# Restart all ARC pods
kubectl -n actions-runner-system delete po -l app.kubernetes.io/name= actions-runner-controller
echo Waiting for all ARC pods to be up and running after restart
kubectl -n actions-runner-system wait deploy/actions-runner-controller --for condition = available --timeout 120s
2020-11-14 20:07:14 +09:00
# Adhocly wait for some time until actions-runner-controller's admission webhook gets ready
sleep 20