Skip to content

Commit 151463a

Browse files
committed
Add support for Podman
Add podman as an option for building images and running on Kind
1 parent f433fdb commit 151463a

12 files changed

+57
-21
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ vendor/
33
[._]*.sw[a-p]
44

55
./dra-example-kubeletplugin
6+
7+
driver_image.tar

Makefile

+13-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
DOCKER ?= docker
15+
CONTAINER_TOOL ?= docker
1616
MKDIR ?= mkdir
1717
TR ?= tr
1818
DIST_DIR ?= $(CURDIR)/dist
@@ -118,37 +118,41 @@ generate-deepcopy: vendor
118118
.PHONY: .build-image
119119
.build-image: docker/Dockerfile.devel
120120
if [ x"$(SKIP_IMAGE_BUILD)" = x"" ]; then \
121-
$(DOCKER) build \
121+
$(CONTAINER_TOOL) build \
122122
--progress=plain \
123123
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
124124
--tag $(BUILDIMAGE) \
125125
-f $(^) \
126126
docker; \
127127
fi
128128

129+
ifeq ($(CONTAINER_TOOL),podman)
130+
CONTAINER_TOOL_OPTS=-v $(PWD):$(PWD):Z
131+
else
132+
CONTAINER_TOOL_OPTS=-v $(PWD):$(PWD) --user $$(id -u):$$(id -g)
133+
endif
134+
129135
$(DOCKER_TARGETS): docker-%: .build-image
130-
@echo "Running 'make $(*)' in docker container $(BUILDIMAGE)"
131-
$(DOCKER) run \
136+
@echo "Running 'make $(*)' in container $(BUILDIMAGE)"
137+
$(CONTAINER_TOOL) run \
132138
--rm \
133139
-e HOME=$(PWD) \
134140
-e GOCACHE=$(PWD)/.cache/go \
135141
-e GOPATH=$(PWD)/.cache/gopath \
136-
-v $(PWD):$(PWD) \
142+
$(CONTAINER_TOOL_OPTS) \
137143
-w $(PWD) \
138-
--user $$(id -u):$$(id -g) \
139144
$(BUILDIMAGE) \
140145
make $(*)
141146

142147
# Start an interactive shell using the development image.
143148
PHONY: .shell
144149
.shell:
145-
$(DOCKER) run \
150+
$(CONTAINER_TOOL) run \
146151
--rm \
147152
-ti \
148153
-e HOME=$(PWD) \
149154
-e GOCACHE=$(PWD)/.cache/go \
150155
-e GOPATH=$(PWD)/.cache/gopath \
151-
-v $(PWD):$(PWD) \
156+
$(CONTAINER_TOOL_OPTS) \
152157
-w $(PWD) \
153-
--user $$(id -u):$$(id -g) \
154158
$(BUILDIMAGE)

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The procedure below has been tested and verified on both Linux and Mac.
2424

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

41+
**Note**: The scripts will automatically use either `docker`, or `podman` as the container tool command, whichever
42+
can be found in the PATH. To override this behavior, set `CONTAINER_TOOL` environment variable either by calling
43+
`export CONTAINER_TOOL=docker`, or by prepending `CONTAINER_TOOL=docker` to a script
44+
(e.g. `CONTAINER_TOOL=docker ./path/to/script.sh`). Keep in mind that building Kind images currently requires Docker.
45+
4146
From here we will build the image for the example resource driver:
4247
```bash
4348
./demo/build-driver.sh

demo/build-driver.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ source "${CURRENT_DIR}/scripts/common.sh"
3131
${SCRIPTS_DIR}/build-driver-image.sh
3232

3333
# If a cluster is already running, load the image onto its nodes
34-
EXISTING_CLUSTER="$(kind get clusters | grep -w "${KIND_CLUSTER_NAME}" || true)"
34+
EXISTING_CLUSTER="$(${KIND} get clusters | grep -w "${KIND_CLUSTER_NAME}" || true)"
3535
if [ "${EXISTING_CLUSTER}" != "" ]; then
3636
${SCRIPTS_DIR}/load-driver-image-into-kind.sh
3737
fi

demo/create-cluster.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fi
3434
${SCRIPTS_DIR}/create-kind-cluster.sh
3535

3636
# If a driver image already exists load it into the cluster
37-
EXISTING_IMAGE_ID="$(docker images --filter "reference=${DRIVER_IMAGE}" -q)"
37+
EXISTING_IMAGE_ID="$(${CONTAINER_TOOL} images --filter "reference=${DRIVER_IMAGE}" -q)"
3838
if [ "${EXISTING_IMAGE_ID}" != "" ]; then
3939
${SCRIPTS_DIR}/load-driver-image-into-kind.sh
4040
fi

demo/scripts/build-driver-image.sh

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ cd ${CURRENT_DIR}/../..
4141
export REGISTRY="${DRIVER_IMAGE_REGISTRY}"
4242
export IMAGE="${DRIVER_IMAGE_NAME}"
4343
export VERSION="${DRIVER_IMAGE_TAG}"
44+
export CONTAINER_TOOL="${CONTAINER_TOOL}"
4445

4546
# Regenerate the CRDs and build the container image
4647
make docker-generate

demo/scripts/build-kind-image.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ set -o pipefail
2828
source "${CURRENT_DIR}/common.sh"
2929

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

36+
if [[ "${CONTAINER_TOOL}" != "docker" ]]; then
37+
echo "Building kind images requires Docker. Cannot use '${CONTAINER_TOOL}'"
38+
exit 1
39+
fi
40+
3641
# Create a temorary directory to hold all the artifacts we need for building the image
3742
TMP_DIR="$(mktemp -d)"
3843
cleanup() {
@@ -47,4 +52,4 @@ KIND_K8S_DIR="${TMP_DIR}/kubernetes-${KIND_K8S_TAG}"
4752
git clone --depth 1 --branch ${KIND_K8S_TAG} ${KIND_K8S_REPO} ${KIND_K8S_DIR}
4853

4954
# Build the kind base image
50-
kind build node-image --image "${KIND_IMAGE}" "${KIND_K8S_DIR}"
55+
${KIND} build node-image --image "${KIND_IMAGE}" "${KIND_K8S_DIR}"

demo/scripts/common.sh

+16-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# A reference to the current directory where this script is located
2323
SCRIPTS_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
2424

25-
# The name of the example driver
25+
# The name of the example driver
2626
: ${DRIVER_NAME:=dra-example-driver}
2727

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

58+
# Container tool, e.g. docker/podman
59+
if [[ -z "${CONTAINER_TOOL}" ]]; then
60+
if [[ -n "$(which docker)" ]]; then
61+
echo "Docker found in PATH."
62+
CONTAINER_TOOL=docker
63+
elif [[ -n "$(which podman)" ]]; then
64+
echo "Podman found in PATH."
65+
CONTAINER_TOOL=podman
66+
else
67+
echo "No container tool detected. Please install Docker or Podman."
68+
return 1
69+
fi
70+
fi
71+
72+
: ${KIND:="env KIND_EXPERIMENTAL_PROVIDER=${CONTAINER_TOOL} kind"}

demo/scripts/create-kind-cluster.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set -o pipefail
2727

2828
source "${CURRENT_DIR}/common.sh"
2929

30-
kind create cluster \
30+
${KIND} create cluster \
3131
--name "${KIND_CLUSTER_NAME}" \
3232
--image "${KIND_IMAGE}" \
3333
--config "${KIND_CLUSTER_CONFIG_PATH}"

demo/scripts/delete-kind-cluster.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ set -o pipefail
2727

2828
source "${CURRENT_DIR}/common.sh"
2929

30-
kind delete cluster \
30+
${KIND} delete cluster \
3131
--name "${KIND_CLUSTER_NAME}"

demo/scripts/load-driver-image-into-kind.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ set -o pipefail
2727

2828
source "${CURRENT_DIR}/common.sh"
2929

30-
kind load docker-image \
30+
# Work around kind not loading image with podman
31+
IMAGE_ARCHIVE=driver_image.tar
32+
${CONTAINER_TOOL} save -o "${IMAGE_ARCHIVE}" "${DRIVER_IMAGE}" && \
33+
${KIND} load image-archive \
3134
--name "${KIND_CLUSTER_NAME}" \
32-
"${DRIVER_IMAGE}"
35+
"${IMAGE_ARCHIVE}"
36+
rm "${IMAGE_ARCHIVE}"

deployments/container/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
##### Global variables #####
16-
DOCKER ?= docker
16+
CONTAINER_TOOL ?= docker
1717
MKDIR ?= mkdir
1818
DISTRIBUTIONS := ubuntu22.04
1919
DOCKERFILE := $(CURDIR)/deployments/container/Dockerfile
@@ -31,7 +31,7 @@ ubuntu22.04: BASE_IMAGE = docker.io/ubuntu:22.04
3131
# Use a generic build target to build the relevant images
3232
$(DISTRIBUTIONS):
3333
DOCKER_BUILDKIT=1 \
34-
$(DOCKER) build --pull \
34+
$(CONTAINER_TOOL) build --pull \
3535
--tag $(IMAGE) \
3636
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
3737
--build-arg BASE_IMAGE="$(BASE_IMAGE)" \

0 commit comments

Comments
 (0)