Skip to content

Commit

Permalink
MGMT-8357: Deploy assisted-service for e2e tests in Kind
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and danmanor committed Aug 21, 2024
1 parent 818b8b9 commit 0f8d231
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 247 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SERVICE := $(or $(SERVICE), quay.io/edge-infrastructure/assisted-service:latest)
SERVICE_NAME := $(or $(SERVICE_NAME),assisted-service)
INDEX_IMAGE := $(or ${INDEX_IMAGE},quay.io/edge-infrastructure/assisted-service-index:latest)
REMOTE_SERVICE_URL := $(or $(REMOTE_SERVICE_URL), "")
USE_LOCAL_SERVICE := $(or $(USE_LOCAL_SERVICE), false)

# terraform
TF_LOG_PATH=$(REPORTS)/terraform_$(TEST_SESSION_ID).log
Expand Down Expand Up @@ -99,7 +100,7 @@ endif
SSO_URL := $(or $(SSO_URL), https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token)
OCM_BASE_URL := $(or $(OCM_BASE_URL), https://api.integration.openshift.com/)

DEPLOY_TARGET := $(or $(DEPLOY_TARGET),minikube)
DEPLOY_TARGET := $(or $(DEPLOY_TARGET),kind)
OCP_KUBECONFIG := $(or $(OCP_KUBECONFIG),build/kubeconfig)

IPV6_SUPPORT := $(or ${IPV6_SUPPORT},true)
Expand Down Expand Up @@ -147,10 +148,10 @@ image_build: bring_assisted_service generate_python_client
$(CONTAINER_COMMAND) tag $(IMAGE_NAME) test-infra:latest # For backwards computability

create_hub_cluster:
scripts/hub-cluster/create.sh
TARGET=${DEPLOY_TARGET} assisted-service/hack/hub_cluster.sh create

delete_hub_cluster:
scripts/hub-cluster/delete.sh
(cd assisted-service && TARGET=${DEPLOY_TARGET} ROOT_DIR=${ROOT_DIR}/assisted-service hack/hub_cluster.sh delete)

clean:
-rm -rf build assisted-service test_infra.log
Expand Down
6 changes: 4 additions & 2 deletions scripts/bring_assisted_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export PULL_BASE_REF=${PULL_BASE_REF:-master}
if ! [[ -d "assisted-service" ]]; then
echo "Can't find assisted-service source locally, cloning ${SERVICE_REPO}"
retry -- git clone "${SERVICE_REPO}"
elif
[[ ${SERVICE_REPO} != $(cd assisted-service && git remote get-url origin) ]]; then
elif [[ "${USE_LOCAL_SERVICE}" == "true" ]]; then
echo "Using local assisted-service"
exit 0
elif [[ ${SERVICE_REPO} != $(cd assisted-service && git remote get-url origin) ]]; then
echo "assisted-service repository found locally but with a different origin, replacing with ${SERVICE_REPO}"
rm -rf ./assisted-service
retry -- git clone "${SERVICE_REPO}"
Expand Down
5 changes: 3 additions & 2 deletions scripts/create_full_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ scripts/install_environment.sh
echo "Done installing"

echo "Installing kind"
scripts/hub-cluster/kind/kind.sh install
make bring_assisted_service
assisted-service/hack/kind/kind.sh install
echo "Done installing kind"

echo "Installing minikube"
scripts/hub-cluster/minikube.sh install
assisted-service/hack/minikube/minikube.sh install
echo "Done installing minikube"

echo "Installing oc and kubectl"
Expand Down
59 changes: 22 additions & 37 deletions scripts/deploy_assisted_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export SERVICE_NAME=assisted-service

case ${DEPLOY_TARGET} in
kind)
export SERVICE_URL=${SERVICE_URL:-$(hostname)}
export SERVICE_PORT=80
export IMAGE_SERVICE_PORT=80
export SERVICE_URL=${SERVICE_URL:-$(get_main_ip)}
export SERVICE_PORT=8090
export IMAGE_SERVICE_PORT=8080
export EXTERNAL_PORT=false
;;
*)
Expand Down Expand Up @@ -165,51 +165,36 @@ else
firewall-cmd --zone=libvirt-routed --add-forward
fi

if [ "${DEBUG_SERVICE}" == "true" ]; then
# Change the registry service type to LoadBalancer to be able to access it from outside the cluster
kubectl patch service $REGISTRY_SERVICE_NAME -n $REGISTRY_SERVICE_NAMESPACE --type json -p='[{"op": "replace", "path": "/spec/type", "value":"LoadBalancer"}]'
# Forward the minikube registry addon k8s service to the host to push the debug image using localhost:5000
spawn_port_forwarding_command $REGISTRY_SERVICE_NAME $REGISTRY_SERVICE_HOST_PORT $REGISTRY_SERVICE_NAMESPACE 999 $KUBECONFIG minikube undeclaredip $REGISTRY_SERVICE_PORT $REGISTRY_SERVICE_NAME
# Set the local registry to the minikube registry (used by the assisted-service update-local-image target)
export SUBSYSTEM_LOCAL_REGISTRY=localhost:5000

print_log "Patching assisted service image with a debuggable code "
(cd assisted-service/ && skipper --env-file ../skipper.env make update-local-image -e CONTAINER_COMMAND=${CONTAINER_RUNTIME_COMMAND+x} )
DEBUG_DEPLOY_AI_PARAMS="REPLICAS_COUNT=1"
# Override the SERVICE environment variable with the local registry debug image
export SERVICE="${SUBSYSTEM_LOCAL_REGISTRY}/assisted-service:latest"

# Force removing the debugable image before re-deploying the service
# Change replicas to 0 so when applying the deployment it will identify the changes and allow deleting the
# image if it's already in use in the current pods
kubectl scale -n assisted-installer --replicas=0 deployment assisted-service || true
kubectl wait --for=delete -n assisted-installer pod $(kubectl -n assisted-installer get pods | grep assisted-service | awk '{print $1}')
minikube image rm "${SERVICE}" || true
fi

skipper run src/update_assisted_service_cm.py

(cd assisted-service/ && skipper --env-file ../skipper.env run "make deploy-all" ${SKIPPER_PARAMS} $ENABLE_KUBE_API_CMD TARGET=$DEPLOY_TARGET DEPLOY_TAG=${DEPLOY_TAG} DEPLOY_MANIFEST_PATH=${DEPLOY_MANIFEST_PATH} DEPLOY_MANIFEST_TAG=${DEPLOY_MANIFEST_TAG} NAMESPACE=${NAMESPACE} AUTH_TYPE=${AUTH_TYPE} ${DEBUG_DEPLOY_AI_PARAMS:-})
(cd assisted-service/ && skipper --env-file ../skipper.env run "make deploy-all" ${SKIPPER_PARAMS} $ENABLE_KUBE_API_CMD TARGET=$DEPLOY_TARGET DEPLOY_TAG=${DEPLOY_TAG} DEPLOY_MANIFEST_PATH=${DEPLOY_MANIFEST_PATH} DEPLOY_MANIFEST_TAG=${DEPLOY_MANIFEST_TAG} NAMESPACE=${NAMESPACE} AUTH_TYPE=${AUTH_TYPE} ${DEBUG_DEPLOY_AI_PARAMS:-} IP=$(get_main_ip))

add_firewalld_port $SERVICE_PORT

print_log "Starting port forwarding for deployment/${SERVICE_NAME} on port $SERVICE_PORT"
wait_for_url_and_run ${SERVICE_BASE_URL} "spawn_port_forwarding_command $SERVICE_NAME $SERVICE_PORT $NAMESPACE $NAMESPACE_INDEX $KUBECONFIG minikube undeclared $SERVICE_INTERNAL_PORT"
if [ "${DEPLOY_TARGET}" == "minikube" ]; then
print_log "Starting port forwarding for deployment/${SERVICE_NAME} on port $SERVICE_PORT"
wait_for_url_and_run ${SERVICE_BASE_URL} "spawn_port_forwarding_command $SERVICE_NAME $SERVICE_PORT $NAMESPACE $NAMESPACE_INDEX $KUBECONFIG minikube undeclared $SERVICE_INTERNAL_PORT"
fi

if [ "${DEBUG_SERVICE}" == "true" ]; then
# delve stops all the thread/goroutines once a breakpoint hits which cause the health call to fail and kubernetes reboots the containers.
# see: https://github.com/go-delve/delve/issues/777
print_log "Removing liveness Probe to prevent rebooting while debugging"
kubectl patch deployment assisted-service -n $NAMESPACE --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
if [[ "${DEBUG_SERVICE}" == "true" || "${USE_LOCAL_SERVICE}" == "true" ]]; then
(cd assisted-service/ && make patch-service ROOT_DIR=$ROOT_DIR/assisted-service TARGET=$DEPLOY_TARGET)
fi

if [ "${DEBUG_SERVICE}" == "true" ]; then
add_firewalld_port ${DEBUG_SERVICE_PORT}
print_log "Starting port forwarding for deployment/${SERVICE_NAME} on debug port $DEBUG_SERVICE_PORT"
spawn_port_forwarding_command $SERVICE_NAME $DEBUG_SERVICE_PORT $NAMESPACE $NAMESPACE_INDEX $KUBECONFIG minikube undeclaredip $DEBUG_SERVICE_PORT $DEBUG_SERVICE_NAME

if [ "${DEPLOY_TARGET}" == "minikube" ]; then
print_log "Starting port forwarding for deployment/${SERVICE_NAME} on debug port $DEBUG_SERVICE_PORT"
spawn_port_forwarding_command $SERVICE_NAME $DEBUG_SERVICE_PORT $NAMESPACE $NAMESPACE_INDEX $KUBECONFIG minikube undeclaredip $DEBUG_SERVICE_PORT $DEBUG_SERVICE_NAME
fi
fi

add_firewalld_port ${IMAGE_SERVICE_PORT}
print_log "Starting port forwarding for deployment/${IMAGE_SERVICE_NAME} on debug port $IMAGE_SERVICE_PORT"
spawn_port_forwarding_command $IMAGE_SERVICE_NAME $IMAGE_SERVICE_PORT $NAMESPACE $NAMESPACE_INDEX $KUBECONFIG minikube undeclaredip $IMAGE_SERVICE_INTERNAL_PORT $IMAGE_SERVICE_NAME

if [ "${DEPLOY_TARGET}" == "minikube" ]; then
print_log "Starting port forwarding for deployment/${IMAGE_SERVICE_NAME} on debug port $IMAGE_SERVICE_PORT"
spawn_port_forwarding_command $IMAGE_SERVICE_NAME $IMAGE_SERVICE_PORT $NAMESPACE $NAMESPACE_INDEX $KUBECONFIG minikube undeclaredip $IMAGE_SERVICE_INTERNAL_PORT $IMAGE_SERVICE_NAME
fi

print_log "${SERVICE_NAME} can be reached at ${SERVICE_BASE_URL} "
print_log "Done"
Expand Down
11 changes: 7 additions & 4 deletions scripts/deploy_ui.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
set -x

source scripts/utils.sh

Expand All @@ -17,6 +18,9 @@ mkdir -p build
print_log "Starting ui"
skipper run "make -C assisted-service/ deploy-ui" ${SKIPPER_PARAMS} TARGET=${DEPLOY_TARGET} DEPLOY_TAG=${DEPLOY_TAG} DEPLOY_MANIFEST_PATH=${DEPLOY_MANIFEST_PATH} DEPLOY_MANIFEST_TAG=${DEPLOY_MANIFEST_TAG} NAMESPACE=${NAMESPACE}

ui_pod=$(get_pod_name app=assisted-installer-ui ${NAMESPACE})
retry -- is_pod_ready $ui_pod ${NAMESPACE}

case ${DEPLOY_TARGET} in
minikube)
node_ip=$(get_main_ip)
Expand All @@ -25,10 +29,9 @@ case ${DEPLOY_TARGET} in
;;

kind)
EXTERNAL_PORT=false
node_ip=$(hostname)
ui_port=80
ui_url="http://${node_ip}/"
node_ip=$(get_main_ip)
ui_port=8060
ui_url="http://${node_ip}:${ui_port}"
;;
*)
echo "Non-supported deploy target ${DEPLOY_TARGET}!";
Expand Down
24 changes: 0 additions & 24 deletions scripts/hub-cluster/create.sh

This file was deleted.

24 changes: 0 additions & 24 deletions scripts/hub-cluster/delete.sh

This file was deleted.

9 changes: 0 additions & 9 deletions scripts/hub-cluster/kind/kind-config.yaml

This file was deleted.

60 changes: 0 additions & 60 deletions scripts/hub-cluster/kind/kind.sh

This file was deleted.

81 changes: 0 additions & 81 deletions scripts/hub-cluster/minikube.sh

This file was deleted.

16 changes: 16 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,20 @@ function retry() {
return ${rc}
}

function get_pod_name() {
local pod_label=$1
local namespace=$2

kubectl get pods -n $namespace -l $pod_label -o name
}

function is_pod_ready() {
local pod_name=$1
local namespace=$2

while [ $(kubectl get -n $namespace $pod_name -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') != "True" ]; do
sleep 3
done
}

"$@"
Loading

0 comments on commit 0f8d231

Please sign in to comment.