Skip to content

Commit 4752fd3

Browse files
committed
refactor arg parser; e2e-helm.sh uses buildah or docker
1 parent 5a91115 commit 4752fd3

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

hack/lib/test_lib.sh

+18
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,21 @@ function parseFlag() {
5454
function parseArg() {
5555
echo "$(echo "$1" | awk '{ print gensub(/=/, " ", 1) }' | cut -d" " -f2)"
5656
}
57+
58+
function builderFromArgs() {
59+
IMAGE_BUILDER="docker"
60+
while [[ $# -gt 0 ]]; do
61+
flag="$(parseFlag "$1")"
62+
arg="$2"
63+
if echo "$1" | grep -qoE -e "--[^ =]*="; then arg="$(parseArg "$1")"; fi
64+
case $flag in
65+
--image-builder)
66+
IMAGE_BUILDER="$arg"
67+
shift
68+
;;
69+
esac
70+
shift
71+
done
72+
73+
echo "$IMAGE_BUILDER"
74+
}

hack/tests/e2e-ansible.sh

+1-16
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,10 @@
33
source hack/lib/test_lib.sh
44

55
DEST_IMAGE="quay.io/example/memcached-operator:v0.0.2"
6-
7-
IMAGE_BUILDER="docker"
8-
while [[ $# -gt 0 ]]; do
9-
flag="$(parseFlag "$1")"
10-
arg="$2"
11-
if echo "$1" | grep -qoE -e "--[^ =]*="; then arg="$(parseArg "$1")"; fi
12-
case $flag in
13-
--image-builder)
14-
IMAGE_BUILDER="$arg"
15-
shift
16-
;;
17-
esac
18-
shift
19-
done
6+
IMAGE_BUILDER="$(builderFromArgs $@)"
207

218
set -ex
229

23-
echo $IMAGE_BUILDER
24-
2510
# switch to the "default" namespace if on openshift, to match the minikube test
2611
if which oc 2>/dev/null; then oc project default; fi
2712

hack/tests/e2e-helm.sh

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
source hack/lib/test_lib.sh
44

55
DEST_IMAGE="quay.io/example/nginx-operator:v0.0.2"
6+
IMAGE_BUILDER="$(builderFromArgs $@)"
7+
8+
echo "$IMAGE_BUILDER"
9+
exit
610

711
set -ex
812

@@ -18,7 +22,14 @@ fi
1822
# build operator binary and base image
1923
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o test/helm-operator/helm-operator test/helm-operator/cmd/helm-operator/main.go
2024
pushd test/helm-operator
21-
docker build -t quay.io/water-hole/helm-operator .
25+
HELM_OP_IMAGE="quay.io/water-hole/helm-operator:latest"
26+
# Use buildah by default.
27+
if [[ "$IMAGE_BUILDER" == "buildah" ]] && command -v buildah; then
28+
buildah bud --isolation=rootless --layers=true -t "$HELM_OP_IMAGE" .
29+
buildah push "$HELM_OP_IMAGE" docker-daemon:"$HELM_OP_IMAGE"
30+
else
31+
docker build -t "$HELM_OP_IMAGE" .
32+
fi
2233
popd
2334

2435
# Make a test directory for Helm tests so we avoid using default GOPATH.
@@ -35,7 +46,10 @@ unset GOPATH GOROOT
3546
operator-sdk new nginx-operator --api-version=helm.example.com/v1alpha1 --kind=Nginx --type=helm
3647
pushd nginx-operator
3748

38-
operator-sdk build "$DEST_IMAGE"
49+
operator-sdk build "$DEST_IMAGE" --image-builder="$IMAGE_BUILDER"
50+
if [[ "$IMAGE_BUILDER" == "buildah" ]] && command -v buildah; then
51+
buildah push "$DEST_IMAGE" docker-daemon:"$DEST_IMAGE"
52+
fi
3953
sed -i "s|REPLACE_IMAGE|$DEST_IMAGE|g" deploy/operator.yaml
4054
sed -i 's|Always|Never|g' deploy/operator.yaml
4155
sed -i 's|size: 3|replicaCount: 1|g' deploy/crds/helm_v1alpha1_nginx_cr.yaml

0 commit comments

Comments
 (0)