Skip to content

Commit

Permalink
refactor: Remove bash methods from cluster up that have been moved to…
Browse files Browse the repository at this point in the history
… opts

Move params to gocli params intialization instead

Signed-off-by: aerosouund <[email protected]>
  • Loading branch information
aerosouund committed Jul 26, 2024
1 parent 7bb02dc commit ef7328c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 168 deletions.
53 changes: 53 additions & 0 deletions cluster-up/cluster/ephemeral-provider-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,59 @@ function _add_common_params() {
params=" --enable-fips $params"
fi

if [ "$KUBEVIRT_WITH_MULTUS_V3" == "true" ]; then
params=" --deploy-multus $params"
fi

if [ "$KUBEVIRT_WITH_CNAO" == "true" ]; then
params=" --enable-cnao $params"
fi

if [ "$KUBEVIRT_DEPLOY_CDI" == "true" ]; then
params=" --deploy-cdi $params"
fi

if [ -n "$KUBEVIRT_CUSTOM_CDI_VERSION" ]; then
params=" --cdi-version=$KUBEVIRT_CUSTOM_CDI_VERSION $params"
fi

if [ "$KUBEVIRT_DEPLOY_AAQ" == "true" ]; then
params=" --deploy-aaq $params"
fi

if [ -n "$KUBEVIRT_CUSTOM_AAQ_VERSION" ]; then
params=" --aaq-version=$KUBEVIRT_CUSTOM_AAQ_VERSION $params"
fi

if [ "$KUBEVIRT_KSM_ON" == "true" ]; then
params=" --enable-ksm $params"
fi

if [ ! -z $KUBEVIRT_KSM_SLEEP_BETWEEN_SCANS_MS ]; then
params=" --ksm-sleep-interval=$KUBEVIRT_KSM_SLEEP_BETWEEN_SCANS_MS $params"
fi

if [ ! -z $KUBEVIRT_KSM_PAGES_TO_SCAN ]; then
params=" --ksm-page-count=$KUBEVIRT_KSM_PAGES_TO_SCAN $params"
fi

if [ "$KUBEVIRT_SWAP_ON" == "true" ]; then
params=" --enable-swap $params"
fi

if [ ! -z $KUBEVIRT_SWAP_SIZE_IN_GB ]; then
params=" --swap-size=$KUBEVIRT_SWAP_SIZE_IN_GB $params"
fi

if [ ! -z $KUBEVIRT_SWAPPINESS ]; then
params=" --swapiness=$KUBEVIRT_SWAPPINESS $params"
fi

if [ $KUBEVIRT_UNLIMITEDSWAP == "true" ]; then
params=" --unlimited-swap $params"
fi


if [ -n "$KUBEVIRTCI_PROXY" ]; then
params=" --docker-proxy=$KUBEVIRTCI_PROXY $params"
fi
Expand Down
169 changes: 1 addition & 168 deletions cluster-up/cluster/k8s-provider-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,6 @@ set -e
source "${KUBEVIRTCI_PATH}/cluster/ephemeral-provider-common.sh"


#if UNLIMITEDSWAP is set to true - Kubernetes workloads can use as much swap memory as they request, up to the system limit.
#otherwise Kubernetes workloads can use as much swap memory as they request, up to the system limit by default
function configure_swap_memory () {
if [ "$KUBEVIRT_SWAP_ON" == "true" ] ;then
for nodeNum in $(seq -f "%02g" 1 $KUBEVIRT_NUM_NODES); do
if [ ! -z $KUBEVIRT_SWAP_SIZE_IN_GB ]; then
$ssh node${nodeNum} -- sudo dd if=/dev/zero of=/swapfile count=$KUBEVIRT_SWAP_SIZE_IN_GB bs=1G
$ssh node${nodeNum} -- sudo mkswap /swapfile
fi

$ssh node${nodeNum} -- sudo swapon -a

if [ ! -z $KUBEVIRT_SWAPPINESS ]; then
$ssh node${nodeNum} -- "sudo /bin/su -c \"echo vm.swappiness = $KUBEVIRT_SWAPPINESS >> /etc/sysctl.conf\""
$ssh node${nodeNum} -- sudo sysctl vm.swappiness=$KUBEVIRT_SWAPPINESS
fi

if [ $KUBEVIRT_UNLIMITEDSWAP == "true" ]; then
$ssh node${nodeNum} -- "sudo sed -i ':a;N;\$!ba;s/memorySwap: {}/memorySwap:\n swapBehavior: UnlimitedSwap/g' /var/lib/kubelet/config.yaml"
$ssh node${nodeNum} -- sudo systemctl restart kubelet
fi
done
fi
}

function configure_ksm_module () {
if [ "$KUBEVIRT_KSM_ON" == "true" ] ;then
for nodeNum in $(seq -f "%02g" 1 $KUBEVIRT_NUM_NODES); do
$ssh node${nodeNum} -- "echo 1 | sudo tee /sys/kernel/mm/ksm/run >/dev/null"
if [ ! -z $KUBEVIRT_KSM_SLEEP_BETWEEN_SCANS_MS ]; then
$ssh node${nodeNum} -- "echo ${KUBEVIRT_KSM_SLEEP_BETWEEN_SCANS_MS} | sudo tee /sys/kernel/mm/ksm/sleep_millisecs >/dev/null "
fi
if [ ! -z $KUBEVIRT_KSM_PAGES_TO_SCAN ]; then
$ssh node${nodeNum} -- "echo ${KUBEVIRT_KSM_PAGES_TO_SCAN} | sudo tee /sys/kernel/mm/ksm/pages_to_scan >/dev/null "
fi
done
fi
}

function configure_memory_overcommitment_behavior () {
configure_swap_memory
configure_ksm_module
}

function deploy_cnao() {
if [ "$KUBEVIRT_WITH_CNAO" == "true" ] || [ "$KUBVIRT_WITH_CNAO_SKIP_CONFIG" == "true" ]; then
$kubectl create -f /opt/cnao/namespace.yaml
$kubectl create -f /opt/cnao/network-addons-config.crd.yaml
$kubectl create -f /opt/cnao/operator.yaml

if [ "$KUBVIRT_WITH_CNAO_SKIP_CONFIG" != "true" ]; then
create_network_addons_config
fi

# Install whereabouts on CNAO lanes
$kubectl create -f /opt/whereabouts
fi
}

function deploy_kwok() {
if [[ ${KUBEVIRT_DEPLOY_KWOK} == "true" ]]; then
Expand All @@ -74,68 +16,7 @@ function deploy_kwok() {
fi
}

function create_network_addons_config() {
local nac="/opt/cnao/network-addons-config-example.cr.yaml"
if [ "$KUBEVIRT_WITH_MULTUS_V3" == "true" ]; then
local no_multus_nac="/opt/cnao/no-multus-nac.yaml"
$ssh node01 -- "awk '!/multus/' ${nac} | sudo tee ${no_multus_nac}"
nac=${no_multus_nac}
fi

$kubectl apply -f ${nac}
}

function wait_for_cnao_ready() {
if [ "$KUBEVIRT_WITH_CNAO" == "true" ] || [ "$KUBVIRT_WITH_CNAO_SKIP_CONFIG" == "true" ]; then
$kubectl wait deployment -n cluster-network-addons cluster-network-addons-operator --for condition=Available --timeout=200s
if [ "$KUBVIRT_WITH_CNAO_SKIP_CONFIG" != "true" ]; then
$kubectl wait networkaddonsconfig cluster --for condition=Available --timeout=200s
fi
fi
}

function deploy_multus() {
if [ "$KUBEVIRT_WITH_MULTUS_V3" == "true" ]; then
$kubectl create -f /opt/multus/multus.yaml
fi
}

function wait_for_multus_ready() {
if [ "$KUBEVIRT_WITH_MULTUS_V3" == "true" ]; then
$kubectl rollout status -n kube-system ds/kube-multus-ds --timeout=200s
fi
}

function deploy_istio() {
if [ "$KUBEVIRT_DEPLOY_ISTIO" == "true" ]; then
if [ "$KUBEVIRT_WITH_CNAO" == "true" ]; then
$kubectl create -f /opt/istio/istio-operator-with-cnao.cr.yaml
else
$kubectl create -f /opt/istio/istio-operator.cr.yaml
fi
fi
}

function wait_for_istio_ready() {
if [ "$KUBEVIRT_DEPLOY_ISTIO" == "true" ]; then
istio_operator_ns=istio-system
retries=0
max_retries=20
while [[ $retries -lt $max_retries ]]; do
echo "waiting for istio-operator to be healthy"
sleep 5
health=$($kubectl -n $istio_operator_ns get istiooperator istio-operator -o jsonpath="{.status.status}")
if [[ $health == "HEALTHY" ]]; then
break
fi
retries=$((retries + 1))
done
if [ $retries == $max_retries ]; then
echo "waiting istio-operator to be healthy failed"
exit 1
fi
fi
}

# copy_istio_cni_conf_files copy the generated Istio CNI net conf file
# (at '/etc/cni/multus/net.d/') to where Multus expect CNI net conf files ('/etc/cni/net.d/')
Expand All @@ -147,28 +28,6 @@ function copy_istio_cni_conf_files() {
fi
}

function deploy_cdi() {
if [ "$KUBEVIRT_DEPLOY_CDI" == "true" ]; then
if [ -n "${KUBEVIRT_CUSTOM_CDI_VERSION}" ]; then
$ssh node01 -- 'sudo sed --regexp-extended -i s/v[0-9]+\.[0-9]+\.[0-9]+\(.*\)?$/'"$KUBEVIRT_CUSTOM_CDI_VERSION"'/g /opt/cdi-*-operator.yaml'
fi

LATEST_CDI_OPERATOR=$($ssh node01 -- 'ls -rt /opt/cdi-*-operator.yaml | tail -n 1')
LATEST_CDI_CR=$($ssh node01 -- 'ls -rt /opt/cdi-*-cr.yaml | tail -n 1')
$kubectl create -f $LATEST_CDI_OPERATOR
$kubectl create -f $LATEST_CDI_CR
fi
}

function wait_for_cdi_ready() {
if [ "$KUBEVIRT_DEPLOY_CDI" == "true" ]; then
while [ "$($kubectl get pods --namespace cdi | grep -c 'cdi-')" -lt 4 ]; do
$kubectl get pods --namespace cdi
sleep 10
done
$kubectl wait --for=condition=Ready pod --timeout=180s --all --namespace cdi
fi
}

# configure Prometheus to select kubevirt prometheusrules
function configure_prometheus() {
Expand All @@ -177,26 +36,6 @@ function configure_prometheus() {
fi
}

function deploy_aaq() {
if [ "$KUBEVIRT_DEPLOY_AAQ" == "true" ]; then
if [ -n "${KUBEVIRT_CUSTOM_AAQ_VERSION}" ]; then
$ssh node01 -- 'sudo sed --regexp-extended -i s/v[0-9]+\.[0-9]+\.[0-9]+\(.*\)?$/'"$KUBEVIRT_CUSTOM_AAQ_VERSION"'/g /opt/aaq/aaq-*-operator.yaml'
fi

$kubectl create -f /opt/aaq/aaq-*-operator.yaml
$kubectl create -f /opt/aaq/aaq-*-cr.yaml
fi
}

function wait_for_aaq_ready() {
if [ "$KUBEVIRT_DEPLOY_AAQ" == "true" ]; then
while [ "$($kubectl get pods --namespace aaq | grep -c 'aaq-')" -lt 4 ]; do
$kubectl get pods --namespace aaq
sleep 10
done
$kubectl wait --for=condition=Ready pod --timeout=180s --all --namespace aaq
fi
}

function wait_for_kwok_ready() {
if [ "KUBEVIRT_DEPLOY_KWOK" == "true" ]; then
Expand Down Expand Up @@ -261,17 +100,11 @@ function up() {
$kubectl label node -l $label node-role.kubernetes.io/worker=''

configure_prometheus
configure_memory_overcommitment_behavior
configure_cpu_manager

deploy_cnao
deploy_multus
deploy_istio
deploy_cdi
deploy_aaq
deploy_kwok

until wait_for_cnao_ready && wait_for_istio_ready && wait_for_cdi_ready && wait_for_multus_ready && wait_for_aaq_ready && wait_for_kwok_ready; do
until wait_for_kwok_ready; do
echo "Waiting for cluster components..."
sleep 5
done
Expand Down

0 comments on commit ef7328c

Please sign in to comment.