Skip to content

Commit

Permalink
e2e: Add scripts to handler ovn-k cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Enrique Llorente <[email protected]>
  • Loading branch information
qinqon committed Jun 10, 2024
1 parent 1e9d40a commit 422be30
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ go.work
*.swp
*.swo
*~

.output
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
IMG ?= kubevirt-ipam-controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.29.0
# Generated manifest path to install the controller
INSTALLER_PATH ?= dist/install.yaml

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand All @@ -22,6 +24,7 @@ CONTAINER_TOOL ?= docker
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec


.PHONY: all
all: build

Expand Down Expand Up @@ -119,11 +122,11 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
@if [ -d "config/crd" ]; then \
$(KUSTOMIZE) build config/crd > dist/install.yaml; \
$(KUSTOMIZE) build config/crd > $(INSTALLER_PATH); \
fi
echo "---" >> dist/install.yaml # Add a document separator before appending

cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default >> dist/install.yaml
$(KUSTOMIZE) build config/default > $(INSTALLER_PATH)

##@ Deployment

Expand Down Expand Up @@ -180,6 +183,18 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})

.PHONY: cluster-up
cluster-up:
./hack/cluster.sh up

.PHONY: cluster-down
cluster-down:
./hack/cluster.sh down

.PHONY: cluster-down
cluster-sync:
./hack/cluster.sh sync

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
Expand Down
80 changes: 80 additions & 0 deletions hack/cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

set -xe
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"


OUTPUT_DIR=${OUTPUT_DIR:-${SCRIPT_DIR}/../.output}

OVN_KUBERNETES_REPO="${OVN_KUBERNETES_REPO:-https://github.com/ovn-org/ovn-kubernetes}"
OVN_KUBERNETES_BRANCH="${OVN_KUBERNETES_BRANCH:-master}"
OVN_KUBERNETES_DIR=${OUTPUT_DIR}/ovn-kubernetes

# from https://github.com/kubernetes-sigs/kind/releases
KIND_BIN=${OUTPUT_DIR}/kind

export KUBECONFIG=${OUTPUT_DIR}/kubeconfig

cluster_name=kubevirt-ipamclaims
op=$1
shift

function ensure_ovn_kubernetes() {
if [ -d "${OVN_KUBERNETES_DIR}" ]; then
return 0
fi
(
cd ${OUTPUT_DIR}
git clone --single-branch ${OVN_KUBERNETES_REPO} -b ${OVN_KUBERNETES_BRANCH}
)
}

function ensure_kind() {
if [ -f ${KIND_BIN} ]; then
return 0
fi
local kind_version=v0.20.0
local arch=""
case $(uname -m) in
x86_64) arch="amd64";;
aarch64) arch="arm64" ;;
esac
local kind_url=https://kind.sigs.k8s.io/dl/$kind_version/kind-linux-${arch}
curl --retry 5 -Lo ${KIND_BIN} ${kind_url}
chmod +x ${KIND_BIN}
}

function up() {
mkdir -p ${OUTPUT_DIR}
ensure_ovn_kubernetes
ensure_kind
kind delete cluster --name $cluster_name
(
cd ${OVN_KUBERNETES_DIR}
./contrib/kind.sh --local-kind-registry -ic -ikv -i6 -mne -cn ${cluster_name}
)
}

function down() {
ensure_kind
${KIND_BIN} delete cluster --name ${cluster_name}
echo "down"
}

function sync() {
local img=localhost:5000/kubevirt-ipam-controller
local tag=latest
IMG=$img:$tag make \
build \
docker-build \
docker-push

# Generate the manifest with the "sha256" to force kubernetes to reload the image
sha=$(skopeo inspect --tls-verify=false docker://$img:$tag |jq -r .Digest)
INSTALLER_PATH=${OUTPUT_DIR}/installer.yaml IMG=$img@$sha make build-installer
kubectl apply -f ${OUTPUT_DIR}/install.yaml
}



$op $@

0 comments on commit 422be30

Please sign in to comment.