From ee1f233bef4968c8550776c407c9ef149c932808 Mon Sep 17 00:00:00 2001 From: Jason Madigan Date: Mon, 25 Mar 2024 11:43:27 +0000 Subject: [PATCH] Podman fixes --- hack/.binEnv | 18 +++++++++++++++++- hack/.cleanupUtils | 2 +- hack/.kindUtils | 3 ++- hack/.quickstartEnv | 27 ++++++++++++++++++++++++--- hack/quickstart-metrics.sh | 2 +- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/hack/.binEnv b/hack/.binEnv index 6a49866d4..d9029629a 100644 --- a/hack/.binEnv +++ b/hack/.binEnv @@ -3,10 +3,26 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BIN_DIR="${SCRIPT_DIR}/../bin/" +containerRuntime() { + local container_runtime="" + + if command -v docker &> /dev/null; then + container_runtime="docker" + elif command -v podman &> /dev/null; then + container_runtime="podman" + else + echo "Neither Docker nor Podman is installed. Exiting..." + exit 1 + fi + echo "$container_runtime" +} + +export CONTAINER_RUNTIME_BIN=$(containerRuntime) + export KIND_BIN="${BIN_DIR}kind" export KUSTOMIZE_BIN="${BIN_DIR}kustomize" export HELM_BIN="${BIN_DIR}helm" export YQ_BIN="${BIN_DIR}yq" export OPERATOR_SDK_BIN="${BIN_DIR}operator-sdk" export CLUSTERADM_BIN="${BIN_DIR}clusteradm" -export KFILT="docker run --rm -i ryane/kfilt" \ No newline at end of file +export KFILT="$CONTAINER_RUNTIME_BIN run --rm -i ryane/kfilt" \ No newline at end of file diff --git a/hack/.cleanupUtils b/hack/.cleanupUtils index 26ad73e31..b6de4a7ed 100644 --- a/hack/.cleanupUtils +++ b/hack/.cleanupUtils @@ -12,7 +12,7 @@ cleanClusters() { cleanNetwork() { # Delete the network echo "Deleting mgc network" - docker network rm mgc || true + $CONTAINER_RUNTIME_BIN network rm mgc || true } cleanupKind() { diff --git a/hack/.kindUtils b/hack/.kindUtils index 65a1b10eb..23bc1fb90 100644 --- a/hack/.kindUtils +++ b/hack/.kindUtils @@ -58,7 +58,8 @@ kindSetupMGCClusters() { local dataPlaneClusterCount=$5 # Create network for the clusters - docker network create -d bridge --subnet 172.31.0.0/16 ${KIND_CLUSTER_DOCKER_NETWORK} --gateway 172.31.0.1 \ + # TODO: podman equivs of these options? + $CONTAINER_RUNTIME_BIN network create -d bridge --subnet 172.31.0.0/16 ${KIND_CLUSTER_DOCKER_NETWORK} --gateway 172.31.0.1 \ -o "com.docker.network.bridge.enable_ip_masquerade"="true" \ -o "com.docker.network.driver.mtu"="1500" diff --git a/hack/.quickstartEnv b/hack/.quickstartEnv index 3892c44c2..5873f6deb 100644 --- a/hack/.quickstartEnv +++ b/hack/.quickstartEnv @@ -1,14 +1,35 @@ # shellcheck shell=bash export TOOLS_IMAGE=quay.io/kuadrant/mgc-tools:latest -export TMP_DIR=/tmp/mgc +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +export TMP_DIR=$SCRIPT_DIR/tmp/mgc + +trap 'echo "Error on line $LINENO: $BASH_COMMAND"' ERR + + +containerRuntime() { + local container_runtime="" + + if command -v docker &> /dev/null; then + container_runtime="docker" + elif command -v podman &> /dev/null; then + container_runtime="podman" + else + echo "Neither Docker nor Podman is installed. Exiting..." + exit 1 + fi + echo "$container_runtime" +} + +export CONTAINER_RUNTIME_BIN=$(containerRuntime) dockerBinCmd() { local network="" - if [ ! -z ${KIND_CLUSTER_DOCKER_NETWORK} ]; then + if [ ! -z "${KIND_CLUSTER_DOCKER_NETWORK}" ]; then network=" --network ${KIND_CLUSTER_DOCKER_NETWORK}" fi - echo "docker run --rm -u $UID -v ${TMP_DIR}:/tmp/mgc:z${network} -e KUBECONFIG=/tmp/mgc/kubeconfig --entrypoint=$1 $TOOLS_IMAGE" + + echo "$CONTAINER_RUNTIME_BIN run --rm -u $UID -v ${TMP_DIR}:${TMP_DIR}${network} -e KUBECONFIG=${TMP_DIR}/kubeconfig --entrypoint=$1 $TOOLS_IMAGE" } export KIND_BIN=kind diff --git a/hack/quickstart-metrics.sh b/hack/quickstart-metrics.sh index e8b6ea02f..4656d33f2 100755 --- a/hack/quickstart-metrics.sh +++ b/hack/quickstart-metrics.sh @@ -16,7 +16,7 @@ # limitations under the License. # -export KFILT="docker run --rm -i ryane/kfilt" +export KFILT="$CONTAINER_RUNTIME_BIN run --rm -i ryane/kfilt" METRICS_FEDERATION=true