Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions .env-kubernetes
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
export KONFIG_PROJECTROOT=/opt/koding

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need to get rid of from this special config file sooner than it might seem ;)

declare -p KONFIG_MONGO &> /dev/null || export KONFIG_MONGO=$MONGO_SERVICE_HOST:27017/koding
declare -p KONFIG_KLOUD_MONGOURL &> /dev/null || export KONFIG_KLOUD_MONGOURL=$KONFIG_MONGO
declare -p KONFIG_KONTROL_MONGOURL &> /dev/null || export KONFIG_KONTROL_MONGOURL=$KONFIG_MONGO
declare -p KONFIG_SOCIALAPI_MONGO &> /dev/null || export KONFIG_SOCIALAPI_MONGO=$KONFIG_MONGO

export KONFIG_MONGO=$BACKEND_POD_IP:27017/koding
declare -p KONFIG_MQ_HOST &> /dev/null || export KONFIG_MQ_HOST=$RABBITMQ_SERVICE_HOST
declare -p KONFIG_MQ_LOGIN &> /dev/null || export KONFIG_MQ_LOGIN=test
declare -p KONFIG_MQ_PASSWORD &> /dev/null || export KONFIG_MQ_PASSWORD=test
declare -p KONFIG_SOCIALAPI_MQ_HOST &> /dev/null || export KONFIG_SOCIALAPI_MQ_HOST=$KONFIG_MQ_HOST
declare -p KONFIG_SOCIALAPI_MQ_LOGIN &> /dev/null || export KONFIG_SOCIALAPI_MQ_LOGIN=test
declare -p KONFIG_SOCIALAPI_MQ_PASSWORD &> /dev/null || export KONFIG_SOCIALAPI_MQ_PASSWORD=test

export KONFIG_MQ_LOGIN=test
export KONFIG_MQ_PASSWORD=test
export KONFIG_MQ_APIPORT=15672
declare -p KONFIG_REDIS_HOST &> /dev/null || export KONFIG_REDIS_HOST=$REDIS_SERVICE_HOST
declare -p KONFIG_REDIS_URL &> /dev/null || export KONFIG_REDIS_URL=$REDIS_SERVICE_HOST:6379

export KONFIG_REDIS_HOST=$BACKEND_POD_IP
export KONFIG_REDIS_PORT=6379
declare -p KONFIG_POSTGRES_HOST &> /dev/null || export KONFIG_POSTGRES_HOST=$POSTGRES_SERVICE_HOST
declare -p KONFIG_KLOUD_POSTGRES_HOST &> /dev/null || export KONFIG_KLOUD_POSTGRES_HOST=$KONFIG_POSTGRES_HOST
declare -p KONFIG_KONTROL_POSTGRES_HOST &> /dev/null || export KONFIG_KONTROL_POSTGRES_HOST=$KONFIG_POSTGRES_HOST
declare -p KONFIG_SOCIALAPI_POSTGRES_HOST &> /dev/null || export KONFIG_SOCIALAPI_POSTGRES_HOST=$KONFIG_POSTGRES_HOST

export KONFIG_POSTGRES_HOST=$BACKEND_POD_IP
export KONFIG_POSTGRES_PORT=5432
export KONFIG_POSTGRES_DBNAME=social
export KONFIG_POSTGRES_USERNAME=socialapplication
declare -p KONFIG_WEBSERVER_PORT &> /dev/null || export KONFIG_WEBSERVER_PORT=8040

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
selenium-debug.log
nginx.conf
nginx.pid
containers.yaml
client-containers.yaml
*.test
*.dump
*.orig
Expand Down Expand Up @@ -109,3 +107,5 @@ website/apidocs/lang
credential

website/a/klient

deployment/kubernetes/
114 changes: 34 additions & 80 deletions config/generateRunFile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -457,105 +457,59 @@ generateDev = (KONFIG, options) ->
command -v kubectl >/dev/null 2>&1 || { echo >&2 "I require kubectl. To install kubectl: \
(curl -L -O https://storage.googleapis.com/kubernetes-release/release/v1.6.4/bin/$(uname | awk '{print tolower($0)}')/amd64/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/)"; exit 1;}

# for local development, minikube must be deleted and recreated if a disk resize is needed
export CHANGE_MINIKUBE_NONE_USER=true
sudo -E minikube start --vm-driver=none

sleep 60
sleep 90

export NAMESPACE_DIR="${KONFIG_PROJECTROOT}/deployment/kubernetes/namespace.yaml"
export BACKEND_DIR="${KONFIG_PROJECTROOT}/deployment/kubernetes/backend-pod/containers.yaml"
export FRONTEND_DIR="${KONFIG_PROJECTROOT}/deployment/kubernetes/frontend-pod/client-containers.yaml"
export BACKEND_DIR="${KONFIG_PROJECTROOT}/deployment/kubernetes/backend-pod/containers.yaml"
export BUILD_DIR="${KONFIG_PROJECTROOT}/deployment/kubernetes/build-pod.yaml"

envsubst < deployment/kubernetes/backend-pod/containers.yaml.template > deployment/kubernetes/backend-pod/containers.yaml
envsubst < deployment/kubernetes/frontend-pod/client-containers.yaml.template > deployment/kubernetes/frontend-pod/client-containers.yaml

cp $BACKEND_DIR ${KONFIG_PROJECTROOT}/deployment/generated_files
cp $FRONTEND_DIR ${KONFIG_PROJECTROOT}/deployment/generated_files

kubectl apply -f $NAMESPACE_DIR || kubectl create -f $NAMESPACE_DIR || exit 1
kubectl apply -f $BACKEND_DIR || kubectl create -f $BACKEND_DIR || exit 1
kubectl apply -f $FRONTEND_DIR || kubectl create -f $FRONTEND_DIR || exit 1

sleep 5
echo "checking if backend pod is ready"
check_pod_ready
export BACKEND_POD_NAME="$(kubectl get pods --namespace koding -o jsonpath="{.items[0].metadata.name}" || exit 1)"
export FRONTEND_POD_NAME="$(kubectl get pods --namespace koding -o jsonpath="{.items[1].metadata.name}" || exit 1)"
sleep 10

k8s_health_check $BACKEND_POD_NAME koding 5 120 backend
k8s_health_check $FRONTEND_POD_NAME koding 5 120 landing

# guest user can only connect via localhost, a test user equivalent to guest will be created to check connectivity via POD IP.
# more info on guest user update: https://www.rabbitmq.com/blog/2014/04/02/breaking-things-with-rabbitmq-3-3/
k8s_health_check $BACKEND_POD_NAME koding 5 120 rabbitmq
sleep 25
kubectl exec -n koding $BACKEND_POD_NAME -c rabbitmq -- bash -c "rabbitmqctl add_user test test && rabbitmqctl set_user_tags test administrator && rabbitmqctl set_permissions -p / test '.*' '.*' '.*'" || exit 1

k8s_connectivity_check $BACKEND_POD_NAME koding backend

echo "all services are ready"
}

function k8s_connectivity_check () {
# args: $1: POD NAME, $2: NAMESPACE, $3: container name
kubectl exec -n $2 $1 -c $3 -- bash -c "./run is_ready" || exit 1
}

function k8s_health_check () {
# args: $1: POD NAME, $2: NAMESPACE, $3: health check interval (recommended 5 seconds), $4: timeout duration
declare interval=$3
declare timeout=$4
declare duration=0

sleep $interval

declare response_code=$(kubectl exec -n $2 $1 -c $5 -- echo 'i am alive' || exit 1)
cp $BACKEND_DIR ${KONFIG_PROJECTROOT}/deployment/generated_files/
cp $BUILD_DIR ${KONFIG_PROJECTROOT}/deployment/generated_files/
cp $FRONTEND_DIR ${KONFIG_PROJECTROOT}/deployment/generated_files/

echo -n $5 : 'health-check : '
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource $NAMESPACE_DIR

until [[ $response_code != *"error"* ]]; do
if [ $duration -eq $timeout ]; then
echo ' timed out!'
exit 255
fi
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource ${KONFIG_PROJECTROOT}/deployment/kubernetes/external-services/mongo
export MONGO_POD_NAME=$(kubectl get pods --namespace koding -l "app=mongo-ext-service" -o jsonpath="{.items[0].metadata.name}")
$KONFIG_PROJECTROOT/scripts/k8s-utilities.sh check_pod_state $MONGO_POD_NAME Pending

echo -n '.'
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource ${KONFIG_PROJECTROOT}/deployment/kubernetes/external-services/countly
export COUNTLY_POD_NAME=$(kubectl get pods --namespace koding -l "app=countly-ext-service" -o jsonpath="{.items[0].metadata.name}")
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh check_pod_state $COUNTLY_POD_NAME Pending

sleep $interval
duration=$((duration + interval))
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource ${KONFIG_PROJECTROOT}/deployment/kubernetes/external-services/postgres
export POSTGRES_POD_NAME=$(kubectl get pods --namespace koding -l "app=postgres-ext-service" -o jsonpath="{.items[0].metadata.name}")
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh check_pod_state $POSTGRES_POD_NAME Pending

response_code=$(kubectl exec -n $2 $1 -c $5 -- echo 'i am alive' || exit 1)
done
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource ${KONFIG_PROJECTROOT}/deployment/kubernetes/external-services/redis
export REDIS_POD_NAME=$(kubectl get pods --namespace koding -l "app=redis-ext-service" -o jsonpath="{.items[0].metadata.name}")
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh check_pod_state $REDIS_POD_NAME Pending

echo ' succeeded!'
}
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource ${KONFIG_PROJECTROOT}/deployment/kubernetes/external-services/rabbitmq
export RABBITMQ_POD_NAME=$(kubectl get pods --namespace koding -l "app=rabbitmq-ext-service" -o jsonpath="{.items[0].metadata.name}")
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh check_pod_state $RABBITMQ_POD_NAME Pending

function check_pod_ready () {
remaining_time=600
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource $FRONTEND_DIR
export FRONTEND_POD_NAME="frontend"
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh check_pod_state $FRONTEND_POD_NAME Pending

until eval "check_pod_response"; do
sleep 30
let remaining_time--
if [ $remaining_time == 0 ]; then
echo "time out!"
exit 1
fi
echo -n '.'
done
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource $BUILD_DIR
export BUILD_POD_NAME="workers-build"
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh check_pod_state $BUILD_POD_NAME Pending

echo "backend pod is ready and running..."
}
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_rmq_test_user

function check_pod_response () {
declare response_code=$(kubectl get pods --namespace koding -o jsonpath="{.items[0].status.phase}" || exit 1)
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh check_pod_state $BUILD_POD_NAME Running Succeeded

if [[ $response_code == *"Pending"* ]]; then
return 1
fi
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh create_k8s_resource $BACKEND_DIR
export BACKEND_POD_NAME="backend"
${KONFIG_PROJECTROOT}/scripts/k8s-utilities.sh check_pod_state $BACKEND_POD_NAME Pending

return 0
echo "all services are ready..."
}

function switch_client_version () {
Expand Down
4 changes: 4 additions & 0 deletions config/main.dev.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ Configuration = (options = {}) ->
json: JSON.stringify KONFIG, null, 2

KONFIG.supervisorConf = (require '../deployment/supervisord.coffee').create KONFIG
if options.kubernetes
KONFIG.kubernetesConf = (require '../deployment/kubernetes.coffee').create KONFIG, options
KONFIG.buildPodConf = (require '../deployment/kubernetes.coffee').createBuildPod KONFIG, options
KONFIG.clientPodConf = (require '../deployment/kubernetes.coffee').createClientPod KONFIG, options
KONFIG.nginxConf = (require '../deployment/nginx.coffee').create KONFIG, options.environment
KONFIG.runFile = (require './generateRunFile').dev KONFIG, options
KONFIG.configCheckExempt = []
Expand Down
Loading