Skip to content

Commit

Permalink
WIP: add e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Or Shoval <[email protected]>
  • Loading branch information
oshoval committed Jun 18, 2024
1 parent c653df2 commit 91fa968
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 20 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Checks
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
e2e:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'

- name: Run e2e tests
env:
KIND_ALLOW_SYSTEM_WRITES: true
run: automation/check-patch.e2e-kubevirt-ipam-controller-functests.sh
52 changes: 52 additions & 0 deletions automation/check-patch.e2e-kubevirt-ipam-controller-functests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -xeuE

# automation/check-patch.e2e-kubevirt-ipam-controller-functests.sh

teardown() {
cd ${TMP_COMPONENT_PATH}
make cluster-down || true
rm -rf "${TMP_COMPONENT_PATH}"
}

main() {
if [ "$GITHUB_ACTIONS" == "true" ]; then
ARCH="amd64"
OS_TYPE="linux"
kubevirt_version="$(curl -L https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirt/stable.txt)"
kubevirt_release_url="https://github.com/kubevirt/kubevirt/releases/download/${kubevirt_version}"
cli_name="virtctl-${kubevirt_version}-${OS_TYPE}-${ARCH}"
curl -LO "${kubevirt_release_url}/${cli_name}"
mv ${cli_name} virtctl
chmod +x virtctl
mv virtctl /usr/local/bin
fi

# Setup CNAO and artifacts temp directory
source automation/check-patch.setup.sh
cd ${TMP_PROJECT_PATH}

export USE_KUBEVIRTCI=false
COMPONENT="kubevirt-ipam-controller" source automation/components-functests.setup.sh

cd ${TMP_COMPONENT_PATH}
export KIND_ARGS="-ic -i6 -mne"
make cluster-up
export KUBECONFIG=${TMP_COMPONENT_PATH}/.output/kubeconfig

trap teardown EXIT

cd ${TMP_PROJECT_PATH}
export KUBEVIRT_PROVIDER=external
export DEV_IMAGE_REGISTRY=localhost:5000
deploy_cnao
deploy_cnao_cr
./hack/deploy-kubevirt.sh

cd ${TMP_COMPONENT_PATH}
echo "Run kubevirt-ipam-controller functional tests"
make test-e2e
}

[[ "${BASH_SOURCE[0]}" == "$0" ]] && main "$@"
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
2 changes: 1 addition & 1 deletion components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ components:
metadata: v0.43.0
kubevirt-ipam-controller:
url: https://github.com/maiqueb/kubevirt-ipam-claims
commit: 81c445c0d7c6841329ac66bba41097733370e0d2
commit: c01d8855783da6b2a1773ec1f82694cd0658cd10
branch: main
update-policy: tagged
metadata: v0.1.0-alpha
Expand Down

0 comments on commit 91fa968

Please sign in to comment.