Skip to content

Commit

Permalink
Merge pull request #51 from empovit/podman
Browse files Browse the repository at this point in the history
Add support for Podman
  • Loading branch information
k8s-ci-robot authored Aug 21, 2024
2 parents f433fdb + 151463a commit 68de9d9
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ vendor/
[._]*.sw[a-p]

./dra-example-kubeletplugin

driver_image.tar
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

DOCKER ?= docker
CONTAINER_TOOL ?= docker
MKDIR ?= mkdir
TR ?= tr
DIST_DIR ?= $(CURDIR)/dist
Expand Down Expand Up @@ -118,37 +118,41 @@ generate-deepcopy: vendor
.PHONY: .build-image
.build-image: docker/Dockerfile.devel
if [ x"$(SKIP_IMAGE_BUILD)" = x"" ]; then \
$(DOCKER) build \
$(CONTAINER_TOOL) build \
--progress=plain \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--tag $(BUILDIMAGE) \
-f $(^) \
docker; \
fi

ifeq ($(CONTAINER_TOOL),podman)
CONTAINER_TOOL_OPTS=-v $(PWD):$(PWD):Z
else
CONTAINER_TOOL_OPTS=-v $(PWD):$(PWD) --user $$(id -u):$$(id -g)
endif

$(DOCKER_TARGETS): docker-%: .build-image
@echo "Running 'make $(*)' in docker container $(BUILDIMAGE)"
$(DOCKER) run \
@echo "Running 'make $(*)' in container $(BUILDIMAGE)"
$(CONTAINER_TOOL) run \
--rm \
-e HOME=$(PWD) \
-e GOCACHE=$(PWD)/.cache/go \
-e GOPATH=$(PWD)/.cache/gopath \
-v $(PWD):$(PWD) \
$(CONTAINER_TOOL_OPTS) \
-w $(PWD) \
--user $$(id -u):$$(id -g) \
$(BUILDIMAGE) \
make $(*)

# Start an interactive shell using the development image.
PHONY: .shell
.shell:
$(DOCKER) run \
$(CONTAINER_TOOL) run \
--rm \
-ti \
-e HOME=$(PWD) \
-e GOCACHE=$(PWD)/.cache/go \
-e GOPATH=$(PWD)/.cache/gopath \
-v $(PWD):$(PWD) \
$(CONTAINER_TOOL_OPTS) \
-w $(PWD) \
--user $$(id -u):$$(id -g) \
$(BUILDIMAGE)
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The procedure below has been tested and verified on both Linux and Mac.

* [GNU Make 3.81+](https://www.gnu.org/software/make/)
* [GNU Tar 1.34+](https://www.gnu.org/software/tar/)
* [docker v20.10+ (including buildx)](https://docs.docker.com/engine/install/)
* [docker v20.10+ (including buildx)](https://docs.docker.com/engine/install/) or [Podman v4.9+](https://podman.io/docs/installation)
* [kind v0.17.0+](https://kind.sigs.k8s.io/docs/user/quick-start/)
* [helm v3.7.0+](https://helm.sh/docs/intro/install/)
* [kubectl v1.18+](https://kubernetes.io/docs/reference/kubectl/)
Expand All @@ -38,6 +38,11 @@ git clone https://github.com/kubernetes-sigs/dra-example-driver.git
cd dra-example-driver
```

**Note**: The scripts will automatically use either `docker`, or `podman` as the container tool command, whichever
can be found in the PATH. To override this behavior, set `CONTAINER_TOOL` environment variable either by calling
`export CONTAINER_TOOL=docker`, or by prepending `CONTAINER_TOOL=docker` to a script
(e.g. `CONTAINER_TOOL=docker ./path/to/script.sh`). Keep in mind that building Kind images currently requires Docker.

From here we will build the image for the example resource driver:
```bash
./demo/build-driver.sh
Expand Down
2 changes: 1 addition & 1 deletion demo/build-driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ source "${CURRENT_DIR}/scripts/common.sh"
${SCRIPTS_DIR}/build-driver-image.sh

# If a cluster is already running, load the image onto its nodes
EXISTING_CLUSTER="$(kind get clusters | grep -w "${KIND_CLUSTER_NAME}" || true)"
EXISTING_CLUSTER="$(${KIND} get clusters | grep -w "${KIND_CLUSTER_NAME}" || true)"
if [ "${EXISTING_CLUSTER}" != "" ]; then
${SCRIPTS_DIR}/load-driver-image-into-kind.sh
fi
Expand Down
2 changes: 1 addition & 1 deletion demo/create-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fi
${SCRIPTS_DIR}/create-kind-cluster.sh

# If a driver image already exists load it into the cluster
EXISTING_IMAGE_ID="$(docker images --filter "reference=${DRIVER_IMAGE}" -q)"
EXISTING_IMAGE_ID="$(${CONTAINER_TOOL} images --filter "reference=${DRIVER_IMAGE}" -q)"
if [ "${EXISTING_IMAGE_ID}" != "" ]; then
${SCRIPTS_DIR}/load-driver-image-into-kind.sh
fi
Expand Down
1 change: 1 addition & 0 deletions demo/scripts/build-driver-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cd ${CURRENT_DIR}/../..
export REGISTRY="${DRIVER_IMAGE_REGISTRY}"
export IMAGE="${DRIVER_IMAGE_NAME}"
export VERSION="${DRIVER_IMAGE_TAG}"
export CONTAINER_TOOL="${CONTAINER_TOOL}"

# Regenerate the CRDs and build the container image
make docker-generate
Expand Down
9 changes: 7 additions & 2 deletions demo/scripts/build-kind-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ set -o pipefail
source "${CURRENT_DIR}/common.sh"

# If an image ID already exists for the image we plan to build, we are done.
EXISTING_IMAGE_ID="$(docker images --filter "reference=${KIND_IMAGE}" -q)"
EXISTING_IMAGE_ID="$(${CONTAINER_TOOL} images --filter "reference=${KIND_IMAGE}" -q)"
if [ "${EXISTING_IMAGE_ID}" != "" ]; then
exit 0
fi

if [[ "${CONTAINER_TOOL}" != "docker" ]]; then
echo "Building kind images requires Docker. Cannot use '${CONTAINER_TOOL}'"
exit 1
fi

# Create a temorary directory to hold all the artifacts we need for building the image
TMP_DIR="$(mktemp -d)"
cleanup() {
Expand All @@ -47,4 +52,4 @@ KIND_K8S_DIR="${TMP_DIR}/kubernetes-${KIND_K8S_TAG}"
git clone --depth 1 --branch ${KIND_K8S_TAG} ${KIND_K8S_REPO} ${KIND_K8S_DIR}

# Build the kind base image
kind build node-image --image "${KIND_IMAGE}" "${KIND_K8S_DIR}"
${KIND} build node-image --image "${KIND_IMAGE}" "${KIND_K8S_DIR}"
17 changes: 16 additions & 1 deletion demo/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# A reference to the current directory where this script is located
SCRIPTS_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"

# The name of the example driver
# The name of the example driver
: ${DRIVER_NAME:=dra-example-driver}

# The registry, image and tag for the example driver
Expand Down Expand Up @@ -55,3 +55,18 @@ SCRIPTS_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
# The name of the kind image to build / run
: ${KIND_IMAGE:="kindest/node:${KIND_K8S_TAG}"}

# Container tool, e.g. docker/podman
if [[ -z "${CONTAINER_TOOL}" ]]; then
if [[ -n "$(which docker)" ]]; then
echo "Docker found in PATH."
CONTAINER_TOOL=docker
elif [[ -n "$(which podman)" ]]; then
echo "Podman found in PATH."
CONTAINER_TOOL=podman
else
echo "No container tool detected. Please install Docker or Podman."
return 1
fi
fi

: ${KIND:="env KIND_EXPERIMENTAL_PROVIDER=${CONTAINER_TOOL} kind"}
2 changes: 1 addition & 1 deletion demo/scripts/create-kind-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set -o pipefail

source "${CURRENT_DIR}/common.sh"

kind create cluster \
${KIND} create cluster \
--name "${KIND_CLUSTER_NAME}" \
--image "${KIND_IMAGE}" \
--config "${KIND_CLUSTER_CONFIG_PATH}"
2 changes: 1 addition & 1 deletion demo/scripts/delete-kind-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ set -o pipefail

source "${CURRENT_DIR}/common.sh"

kind delete cluster \
${KIND} delete cluster \
--name "${KIND_CLUSTER_NAME}"
8 changes: 6 additions & 2 deletions demo/scripts/load-driver-image-into-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ set -o pipefail

source "${CURRENT_DIR}/common.sh"

kind load docker-image \
# Work around kind not loading image with podman
IMAGE_ARCHIVE=driver_image.tar
${CONTAINER_TOOL} save -o "${IMAGE_ARCHIVE}" "${DRIVER_IMAGE}" && \
${KIND} load image-archive \
--name "${KIND_CLUSTER_NAME}" \
"${DRIVER_IMAGE}"
"${IMAGE_ARCHIVE}"
rm "${IMAGE_ARCHIVE}"
4 changes: 2 additions & 2 deletions deployments/container/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

##### Global variables #####
DOCKER ?= docker
CONTAINER_TOOL ?= docker
MKDIR ?= mkdir
DISTRIBUTIONS := ubuntu22.04
DOCKERFILE := $(CURDIR)/deployments/container/Dockerfile
Expand All @@ -31,7 +31,7 @@ ubuntu22.04: BASE_IMAGE = docker.io/ubuntu:22.04
# Use a generic build target to build the relevant images
$(DISTRIBUTIONS):
DOCKER_BUILDKIT=1 \
$(DOCKER) build --pull \
$(CONTAINER_TOOL) build --pull \
--tag $(IMAGE) \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--build-arg BASE_IMAGE="$(BASE_IMAGE)" \
Expand Down

0 comments on commit 68de9d9

Please sign in to comment.