Skip to content

Commit 233fdbe

Browse files
authored
Merge pull request kroxylicious#1967 from robobario/safer-local-operator
run-operator.sh tags operator with git commit sha
2 parents f53ce07 + e2a2b6f commit 233fdbe

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

scripts/run-operator.sh

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,69 @@
99
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" || exit
1010
cd .. || exit
1111

12+
GREEN='\033[0;32m'
13+
RED='\033[0;31m'
14+
NC='\033[0m' # No Color
15+
function info {
16+
printf "${GREEN}run-operator.sh: ${1}${NC}\n"
17+
}
18+
function error {
19+
printf "${RED}run-operator.sh: ${1}${NC}\n"
20+
}
21+
1222
if ! minikube status
1323
then
14-
echo "starting minikube"
24+
info "starting minikube"
1525
minikube start
1626
fi
1727

18-
echo "building operator image in minikube"
28+
GIT_HASH="$(git rev-parse HEAD)"
29+
TMP_INSTALL_DIR="$(mktemp -d)"
30+
trap 'rm -rf -- "$TMP_INSTALL_DIR"' EXIT
31+
32+
info "building operator image in minikube for commit ${GIT_HASH}"
33+
IMAGE_TAG="dev-git-${GIT_HASH}"
1934
KROXYLICIOUS_VERSION=${KROXYLICIOUS_VERSION:-$(mvn org.apache.maven.plugins:maven-help-plugin:3.4.0:evaluate -Dexpression=project.version -q -DforceStdout)}
20-
minikube image build . -f Dockerfile.operator -t quay.io/kroxylicious/operator:latest --build-opt=build-arg=KROXYLICIOUS_VERSION="${KROXYLICIOUS_VERSION}"
35+
minikube image build . -f Dockerfile.operator -t quay.io/kroxylicious/operator:${IMAGE_TAG} --build-opt=build-arg=KROXYLICIOUS_VERSION="${KROXYLICIOUS_VERSION}"
2136

2237
cd kroxylicious-operator || exit
23-
echo "installing kafka (no-op if already installed)"
38+
info "installing kafka (no-op if already installed)"
2439
kubectl create namespace kafka
2540
kubectl create -n kafka -f 'https://strimzi.io/install/latest?namespace=kafka'
2641
kubectl wait -n kafka deployment/strimzi-cluster-operator --for=condition=Available=True --timeout=300s
2742
kubectl apply -n kafka -f https://strimzi.io/examples/latest/kafka/kraft/kafka-single-node.yaml
2843
kubectl wait -n kafka kafka/my-cluster --for=condition=Ready --timeout=300s
2944

30-
echo "deleting example"
45+
info "deleting example"
3146
kubectl delete -f examples/simple/ --ignore-not-found=true --timeout=30s --grace-period=1
3247

33-
echo "deleting kroxylicious-operator installation"
48+
info "deleting kroxylicious-operator installation"
3449
kubectl delete -n kroxylicious-operator all --all --timeout=30s --grace-period=1
3550
kubectl delete -f install --ignore-not-found=true --timeout=30s --grace-period=1
3651

37-
echo "deleting all kroxylicious.io resources and crds"
52+
info "deleting all kroxylicious.io resources and crds"
3853
for crd in $(kubectl get crds -oname | grep kroxylicious.io | awk -F / '{ print $2 }');
3954
do
4055
export crd
41-
echo "deleting resources for crd: $crd"
56+
info "deleting resources for crd: $crd"
4257
kubectl delete -A --all "$(kubectl get crd "${crd}" -o=jsonpath='{.spec.names.singular}')" --timeout=30s --grace-period=1
43-
echo "deleting crd: ${crd}"
58+
info "deleting crd: ${crd}"
4459
kubectl delete crd "${crd}"
4560
done
4661

47-
echo "installing crds"
62+
info "installing crds"
4863
kubectl apply -f src/main/resources/META-INF/fabric8
49-
echo "installing kroxylicious-operator"
50-
kubectl apply -f install
51-
echo "installing simple proxy"
64+
info "installing kroxylicious-operator"
65+
cp install/* ${TMP_INSTALL_DIR}
66+
sed -i "s|quay.io/kroxylicious/operator:latest|quay.io/kroxylicious/operator:${IMAGE_TAG}|g" ${TMP_INSTALL_DIR}/03.Deployment.kroxylicious-operator.yaml
67+
kubectl apply -f ${TMP_INSTALL_DIR}
68+
info "installing simple proxy"
5269
kubectl apply -f examples/simple/
5370

5471
if kubectl wait -n my-proxy kafkaproxy/simple --for=condition=Ready=True --timeout=300s
5572
then
56-
echo "simple proxy should now be available in-cluster at my-cluster.my-proxy.svc.cluster.local:9292"
73+
info "simple proxy should now be available in-cluster at my-cluster.my-proxy.svc.cluster.local:9292"
5774
else
58-
echo "something went wrong!"
75+
error "something went wrong waiting for proxy to become ready!"
5976
exit 1
6077
fi

0 commit comments

Comments
 (0)