Skip to content

Commit

Permalink
components: Refactor script to allow robust usage
Browse files Browse the repository at this point in the history
Since we introduce a non kubevirtci cluster,
refactor the script to allow code reuse while using
both types of clusters.

All current lanes are agnostic for the change.

Signed-off-by: Or Shoval <oshoval@redhat.com>
  • Loading branch information
oshoval committed Jun 23, 2024
1 parent 5db4e1c commit 09007c6
Showing 1 changed file with 42 additions and 19 deletions.
61 changes: 42 additions & 19 deletions automation/components-functests.setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ source hack/components/git-utils.sh
source hack/components/yaml-utils.sh
source cluster/cluster.sh

# Spin up Kubernetes cluster
export KUBEVIRT_MEMORY_SIZE=9216M
make cluster-down cluster-up
USE_KUBEVIRTCI=${USE_KUBEVIRTCI:-"true"}

# Export .kubeconfig full path, so it will be possible
# to use 'kubectl' directly from the component directory path
export KUBECONFIG=$(cluster::kubeconfig)
export KUBECONFIG=${KUBECONFIG:-$(cluster::kubeconfig)}

# Deploy CNAO latest changes
make cluster-operator-push
make cluster-operator-install
function deploy_cluster {
# Spin up Kubernetes cluster
export KUBEVIRT_MEMORY_SIZE=9216M
make cluster-down cluster-up
}

# Test kubemacpool with restricted
if [ "$COMPONENT" == "kubemacpool" ]; then
function deploy_cnao {
# Deploy CNAO latest changes
make cluster-operator-push
make cluster-operator-install
}

function patch_restricted_namespace {
# Test kubemacpool with restricted
if [ "$COMPONENT" == "kubemacpool" ]; then
cluster/kubectl.sh apply -f - <<EOF
apiVersion: v1
kind: Namespace
Expand All @@ -43,17 +50,18 @@ metadata:
labels:
pod-security.kubernetes.io/enforce: restricted
EOF
fi
fi
}

# Deploy all network addons components with CNAO
cat <<EOF | cluster/kubectl.sh apply -f -
function deploy_cnao_cr {
# Deploy all network addons components with CNAO

cat <<EOF > cr.yaml
apiVersion: networkaddonsoperator.network.kubevirt.io/v1
kind: NetworkAddonsConfig
metadata:
name: cluster
spec:
multus: {}
multusDynamicNetworks: {}
linuxBridge: {}
kubeMacPool:
rangeStart: "02:00:00:00:00:00"
Expand All @@ -65,11 +73,19 @@ spec:
imagePullPolicy: Always
EOF

if [[ ! $(cluster/kubectl.sh wait networkaddonsconfig cluster --for condition=Available --timeout=13m) ]]; then
echo "Failed to wait for CNAO CR to be ready"
cluster/kubectl.sh get networkaddonsconfig -o custom-columns="":.status.conditions[*].message
exit 1
fi
if [[ $USE_KUBEVIRTCI == true ]]; then
echo " multus: {}" >> cr.yaml
echo " multusDynamicNetworks: {}" >> cr.yaml
fi

cluster/kubectl.sh apply -f cr.yaml

if [[ ! $(cluster/kubectl.sh wait networkaddonsconfig cluster --for condition=Available --timeout=13m) ]]; then
echo "Failed to wait for CNAO CR to be ready"
cluster/kubectl.sh get networkaddonsconfig -o custom-columns="":.status.conditions[*].message
exit 1
fi
}

# Clone component repository
component_url=$(yaml-utils::get_component_url ${COMPONENT})
Expand All @@ -82,3 +98,10 @@ component_path=${component_temp_dir}/${component_repo}
git-utils::fetch_component ${component_path} ${component_url} ${component_commit}

export TMP_COMPONENT_PATH=${component_path}

if [[ $USE_KUBEVIRTCI == true ]]; then
deploy_cluster
deploy_cnao
patch_restricted_namespace
deploy_cnao_cr
fi

0 comments on commit 09007c6

Please sign in to comment.