Skip to content

Instantly share code, notes, and snippets.

@rmohr
Last active November 5, 2021 13:41
Show Gist options
  • Save rmohr/8324bfeea7d0823ca8cb76622eb76f56 to your computer and use it in GitHub Desktop.
Save rmohr/8324bfeea7d0823ca8cb76622eb76f56 to your computer and use it in GitHub Desktop.
kubevirtci-hypershift
#!/bin/bash
# Usage:
#
# git clone git@github.com:openshift/hypershift.git
# cd hypershift
# curl -o kubevirtci https://gist.githubusercontent.com/rmohr/8324bfeea7d0823ca8cb76622eb76f56/raw/6956f7ff77d218c9060d685c88a7895747f8e0d9/kubevirt
# chmod u+x kubevirtci
#
# ./kubevirtci up # start a cluster with kubevirt
# ./kubevirtci sync # build and deploy current hypershift
# ./kubevirtci kubectl get pods --all-namespaces # interact with the cluster
# ./kubevirtci hypershift create cluster # run hypershift commands against the cluster
# ./kubevirtci oc get pods --all-namespaces # interact with the HOSTED cluster
# ./kubevirtci clean # remoe hypershift
# ./kubevirtci down # destroy the cluster
set -e
export KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER:-k8s-1.21}
export KUBEVIRTCI_TAG=${KUBEVIRTCI_TAG:-2110251848-8198e9c}
export KUBECONFIG=$(cluster-up/cluster-up/kubeconfig.sh)
export KUBEVIRT_DEPLOY_PROMETHEUS=true
export KUBEVIRT_NUM_NODES=2
export KUBEVIRT_MEMORY_SIZE=${KUBEVIRT_MEMORY_SIZE:-5120M}
_kubectl=cluster-up/cluster-up/kubectl.sh
_action=$1
shift
function kubevirtci::fetch_kubevirtci() {
[[ -d cluster-up ]] || git clone https://github.com/kubevirt/kubevirtci.git cluster-up
(cd cluster-up && git checkout ${KUEVIRTCI_TAG})
}
function kubevirtci::up() {
make cluster-up -C cluster-up
LATEST=$(curl -L https://storage.googleapis.com/kubevirt-prow/devel/nightly/release/kubevirt/kubevirt/latest)
${_kubectl} apply -f https://storage.googleapis.com/kubevirt-prow/devel/nightly/release/kubevirt/kubevirt/${LATEST}/kubevirt-operator.yaml
${_kubectl} apply -f https://storage.googleapis.com/kubevirt-prow/devel/nightly/release/kubevirt/kubevirt/${LATEST}/kubevirt-cr.yaml
echo "waiting for kubevirt to become ready, this can take a few minutes. You can safely abort this step, the cluster is ready ..."
${_kubectl} -n kubevirt wait kv kubevirt --for condition=Available --timeout=5m
}
function kubevirtci::down() {
make cluster-down -C cluster-up
}
function kubevirtci::build() {
container="localhost:$(cluster-up/cluster-up/cli.sh ports registry)/hypershift:devel"
make build
docker build -f Dockerfile.fast . -t $container
docker push $container
}
function kubevirtci::install() {
container="registry:5000/hypershift:devel"
./bin/hypershift install --hypershift-image=${container}
}
function kubevirtci::clean() {
./bin/hypershift install --render | ${_kubectl} delete -f -
}
function kubevirtci::hosted-oc {
${_kubectl} port-forward -n clusters-example service/kube-apiserver 6443:6443 > /dev/null 2>&1 &
trap 'kill $(jobs -p) > /dev/null 2>&1' EXIT
./bin/hypershift create kubeconfig --name example --namespace=clusters > .example-kubeconfig
sleep 0.1
oc --kubeconfig .example-kubeconfig --insecure-skip-tls-verify --server https://localhost:6443 "$@"
}
kubevirtci::fetch_kubevirtci
case ${_action} in
"up")
kubevirtci::up
;;
"down")
kubevirtci::down
;;
"sync")
kubevirtci::build
kubevirtci::install
;;
"clean")
kubevirtci::clean
;;
"kubectl")
${_kubectl} "$@"
;;
"hypershift")
./bin/hypershift "$@"
;;
"oc")
kubevirtci::hosted-oc "$@"
;;
*)
echo "No command provided, known commands are 'up', 'down', 'sync', 'clean', 'kubectl', 'hypershift' and 'oc'"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment