Skip to content

Commit

Permalink
Wait for certificate and log error when it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mads-hartmann authored and roboquat committed Dec 8, 2022
1 parent fc92350 commit 77d765d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions dev/preview/workflow/preview/deploy-gitpod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PREVIEW_NAME="${PREVIEW_NAME:-$(previewctl get name)}"
PREVIEW_K3S_KUBE_PATH="${PREVIEW_K3S_KUBECONFIG_PATH:-/home/gitpod/.kube/config}"
PREVIEW_K3S_KUBE_CONTEXT="${PREVIEW_K3S_KUBE_CONTEXT:-$PREVIEW_NAME}"
PREVIEW_NAMESPACE="default"
PREVIEW_SORUCE_CERT_NAME="harvester-${PREVIEW_NAME}"

GITPOD_AGENT_SMITH_TOKEN="$(openssl rand -hex 30)"
GITPOD_AGENT_SMITH_TOKEN_HASH="$(echo -n "$GITPOD_AGENT_SMITH_TOKEN" | sha256sum - | tr -d ' -')"
Expand Down Expand Up @@ -69,19 +70,18 @@ fi

function copyCachedCertificate {
CERTS_NAMESPACE="certs"
SORUCE_CERT_NAME="harvester-${PREVIEW_NAME}"
DESTINATION_CERT_NAME="$GITPOD_PROXY_SECRET_NAME"

kubectl \
--kubeconfig "${DEV_KUBE_PATH}" \
--context "${DEV_KUBE_CONTEXT}" \
get secret "${SORUCE_CERT_NAME}" --namespace="${CERTS_NAMESPACE}" -o yaml \
get secret "${PREVIEW_SORUCE_CERT_NAME}" --namespace="${CERTS_NAMESPACE}" -o yaml \
| yq d - 'metadata.namespace' \
| yq d - 'metadata.uid' \
| yq d - 'metadata.resourceVersion' \
| yq d - 'metadata.creationTimestamp' \
| yq d - 'metadata.ownerReferences' \
| sed "s/${SORUCE_CERT_NAME}/${DESTINATION_CERT_NAME}/g" \
| sed "s/${PREVIEW_SORUCE_CERT_NAME}/${DESTINATION_CERT_NAME}/g" \
| kubectl \
--kubeconfig "${PREVIEW_K3S_KUBE_PATH}" \
--context "${PREVIEW_K3S_KUBE_CONTEXT}" \
Expand Down Expand Up @@ -205,7 +205,17 @@ waitUntilAllPodsAreReady "${PREVIEW_K3S_KUBE_PATH}" "${PREVIEW_K3S_KUBE_CONTEXT}
waitUntilAllPodsAreReady "${PREVIEW_K3S_KUBE_PATH}" "${PREVIEW_K3S_KUBE_CONTEXT}" "cert-manager"

# Note: These should ideally be handled by `leeway run dev/preview:create`
copyCachedCertificate
tries=0
while ! copyCachedCertificate; do
if [[ ${tries} -gt 30 ]]; then
log_error "Failed to find certificate ${PREVIEW_SORUCE_CERT_NAME}"
exit 1
fi
log_info "Certificate ${PREVIEW_SORUCE_CERT_NAME} is not yet present. Sleeping 10 seconds. Attempt number ${tries}"
sleep 10
tries=$((tries + 1))
done

copyImagePullSecret
installRookCeph
installFluentBit
Expand Down

0 comments on commit 77d765d

Please sign in to comment.