mik-laj commented on a change in pull request #6496: [AIRFLOW-5704] Improve 
Kind Kubernetes scripts for local testing. Depends on [AIRFLOW-5827] 
[AIRFLOW-5830] [AIRFLOW-5829]
URL: https://github.com/apache/airflow/pull/6496#discussion_r342150960
 
 

 ##########
 File path: scripts/ci/in_container/kubernetes/app/deploy_app.sh
 ##########
 @@ -0,0 +1,185 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -eu
+set -x
+MY_DIR=$(cd "$(dirname "$0")" && pwd)
+
+AIRFLOW_SOURCES=$(
+    cd "${MY_DIR}/../../../../../" || exit 1
+    pwd
+)
+export AIRFLOW_SOURCES
+
+# shellcheck source=scripts/ci/in_container/_in_container_utils.sh
+. "${MY_DIR}/../../_in_container_utils.sh"
+
+assert_in_container
+
+in_container_script_start
+
+export TEMPLATE_DIRNAME="${MY_DIR}/templates"
+export BUILD_DIRNAME="${MY_DIR}/build"
+
+# shellcheck source=common/_autodetect_variables.sh
+. "${AIRFLOW_SOURCES}/common/_autodetect_variables.sh"
+
+# Source branch will be set in DockerHub
+SOURCE_BRANCH=${SOURCE_BRANCH:=${DEFAULT_BRANCH}}
+# if AIRFLOW_CONTAINER_BRANCH_NAME is not set it will be set to either 
SOURCE_BRANCH (if overridden)
+# or default branch for the sources
+AIRFLOW_CONTAINER_BRANCH_NAME=${AIRFLOW_CONTAINER_BRANCH_NAME:=${SOURCE_BRANCH}}
+
+if [[ ! -d "${BUILD_DIRNAME}" ]]; then
+    mkdir -p "${BUILD_DIRNAME}"
+fi
+
+rm -f "${BUILD_DIRNAME}"/*
+
+if [[ "${KUBERNETES_MODE}" == "persistent_mode" ]]; then
+    INIT_DAGS_VOLUME_NAME=airflow-dags
+    POD_AIRFLOW_DAGS_VOLUME_NAME=airflow-dags
+    CONFIGMAP_DAGS_FOLDER=/root/airflow/dags
+    CONFIGMAP_GIT_DAGS_FOLDER_MOUNT_POINT=
+    CONFIGMAP_DAGS_VOLUME_CLAIM=airflow-dags
+else
+    INIT_DAGS_VOLUME_NAME=airflow-dags-fake
+    POD_AIRFLOW_DAGS_VOLUME_NAME=airflow-dags-git
+    CONFIGMAP_DAGS_FOLDER=/root/airflow/dags/repo/airflow/contrib/example_dags
+    CONFIGMAP_GIT_DAGS_FOLDER_MOUNT_POINT=/root/airflow/dags
+    CONFIGMAP_DAGS_VOLUME_CLAIM=
+fi
+
+CONFIGMAP_GIT_REPO=${TRAVIS_REPO_SLUG:-apache/airflow}
+CONFIGMAP_BRANCH=${DEFAULT_BRANCH:=master}
+
+SED_COMMAND="sed"
+
+if [[ "${KUBERNETES_MODE}" == "persistent_mode" ]]; then
+    ${SED_COMMAND} -e "s/{{INIT_GIT_SYNC}}//g" \
+        "${TEMPLATE_DIRNAME}/airflow.template.yaml" 
>"${BUILD_DIRNAME}/airflow.yaml"
+else
+    ${SED_COMMAND} -e "/{{INIT_GIT_SYNC}}/{r 
${TEMPLATE_DIRNAME}/init_git_sync.template.yaml" -e 'd}' \
+        "${TEMPLATE_DIRNAME}/airflow.template.yaml" 
>"${BUILD_DIRNAME}/airflow.yaml"
+fi
+${SED_COMMAND} -i 
"s|{{AIRFLOW_CI_KUBERNETES_IMAGE}}|${AIRFLOW_CI_KUBERNETES_IMAGE}|g" 
"${BUILD_DIRNAME}/airflow.yaml"
+
+${SED_COMMAND} -i "s|{{CONFIGMAP_GIT_REPO}}|${CONFIGMAP_GIT_REPO}|g" 
"${BUILD_DIRNAME}/airflow.yaml"
+${SED_COMMAND} -i "s|{{CONFIGMAP_BRANCH}}|${CONFIGMAP_BRANCH}|g" 
"${BUILD_DIRNAME}/airflow.yaml"
+${SED_COMMAND} -i "s|{{INIT_DAGS_VOLUME_NAME}}|${INIT_DAGS_VOLUME_NAME}|g" 
"${BUILD_DIRNAME}/airflow.yaml"
+${SED_COMMAND} -i 
"s|{{POD_AIRFLOW_DAGS_VOLUME_NAME}}|${POD_AIRFLOW_DAGS_VOLUME_NAME}|g" \
+    "${BUILD_DIRNAME}/airflow.yaml"
+
+${SED_COMMAND} "s|{{CONFIGMAP_DAGS_FOLDER}}|${CONFIGMAP_DAGS_FOLDER}|g" \
+    "${TEMPLATE_DIRNAME}/configmaps.template.yaml" 
>"${BUILD_DIRNAME}/configmaps.yaml"
+${SED_COMMAND} -i "s|{{CONFIGMAP_GIT_REPO}}|${CONFIGMAP_GIT_REPO}|g" 
"${BUILD_DIRNAME}/configmaps.yaml"
+${SED_COMMAND} -i "s|{{CONFIGMAP_BRANCH}}|${CONFIGMAP_BRANCH}|g" 
"${BUILD_DIRNAME}/configmaps.yaml"
+${SED_COMMAND} -i 
"s|{{CONFIGMAP_GIT_DAGS_FOLDER_MOUNT_POINT}}|${CONFIGMAP_GIT_DAGS_FOLDER_MOUNT_POINT}|g"
 \
+    "${BUILD_DIRNAME}/configmaps.yaml"
+${SED_COMMAND} -i 
"s|{{CONFIGMAP_DAGS_VOLUME_CLAIM}}|${CONFIGMAP_DAGS_VOLUME_CLAIM}|g" \
+    "${BUILD_DIRNAME}/configmaps.yaml"
+
+cat "${BUILD_DIRNAME}/airflow.yaml"
+cat "${BUILD_DIRNAME}/configmaps.yaml"
+
+kubectl delete -f "${MY_DIR}/postgres.yaml" || true
+kubectl delete -f "${BUILD_DIRNAME}/airflow.yaml" || true
+kubectl delete -f "${MY_DIR}/secrets.yaml" || true
+
+set -e
+
+kubectl apply -f "${MY_DIR}/secrets.yaml"
+kubectl apply -f "${BUILD_DIRNAME}/configmaps.yaml"
+kubectl apply -f "${MY_DIR}/postgres.yaml"
+kubectl apply -f "${MY_DIR}/volumes.yaml"
+kubectl apply -f "${BUILD_DIRNAME}/airflow.yaml"
+
+dump_logs() {
+    POD=$(kubectl get pods -o go-template --template '{{range 
.items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep airflow | head -1)
+    echo "------- pod description -------"
+    kubectl describe pod "${POD}"
+    echo "------- webserver init container logs - init -------"
+    kubectl logs "${POD}" -c init || true
+    if [[ "${KUBERNETES_MODE}" != "persistent_mode" ]]; then
+        echo "------- webserver init container logs - git-sync-clone -------"
+        kubectl logs "${POD}" -c git-sync-clone || true
+    fi
+    echo "------- webserver logs -------"
+    kubectl logs "${POD}" -c webserver || true
+    echo "------- scheduler logs -------"
+    kubectl logs "${POD}" -c scheduler || true
+    echo "--------------"
+}
+
+set +x
+# wait for up to 10 minutes for everything to be deployed
+PODS_ARE_READY="0"
+for i in {1..150}; do
 
 Review comment:
   It looks weird. Can we use the while loop? 
   ```bash
   START="$(date +"%s")"
   TIMEOUT=5
   
   while [[ "$(date +"%s")" -lt "$((START + TIMEOUT))" ]]; do
       date;
       sleep 1;
   done
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to