@@ -22,6 +22,8 @@ set -ex pipefail
2222_registry_port=" 5001"
2323_registry_name=" kind-registry"
2424
25+ CTR_CMD=${CTR_CMD-docker}
26+
2527CONFIG_PATH=" cluster-up/cluster"
2628KIND_VERSION=${KIND_VERSION:- 0.15.0}
2729KIND_MANIFESTS_DIR=" $CONFIG_PATH /${CLUSTER_PROVIDER} /manifests"
@@ -33,6 +35,11 @@ KIND_DEFAULT_NETWORK="kind"
3335IMAGE_REPO=${IMAGE_REPO:- localhost: 5001/ kepler}
3436IMAGE_TAG=${IMAGE_TAG:- devel}
3537
38+ PROMETHEUS_OPERATOR_VERSION=${PROMETHEUS_OPERATOR_VERSION:- v0.11.0}
39+ PROMETHEUS_ENABLE=${PROMETHEUS_ENABLE:- false}
40+ PROMETHEUS_REPLICAS=${PROMETHEUS_REPLICAS:- 1}
41+ GRAFANA_ENABLE=${GRAFANA_ENABLE:- false}
42+
3643CONFIG_OUT_DIR=${CONFIG_OUT_DIR:- " _output/manifests/${CLUSTER_PROVIDER} /generated" }
3744rm -rf ${CONFIG_OUT_DIR}
3845mkdir -p ${CONFIG_OUT_DIR}
@@ -55,10 +62,50 @@ aarch64* | arm64*)
5562 ;;
5663esac
5764
65+ function _get_prometheus_operator_images {
66+ grep -R " image:" kube-prometheus/manifests/* prometheus-* | awk ' {print $3}'
67+ grep -R " image:" kube-prometheus/manifests/* prometheusOperator* | awk ' {print $3}'
68+ grep -R " prometheus-config-reloader=" kube-prometheus/manifests/ | sed ' s/.*=//g'
69+ if [ ${GRAFANA_ENABLE,,} == " true" ]; then
70+ grep -R " image:" kube-prometheus/manifests/* grafana* | awk ' {print $3}'
71+ fi
72+ }
73+
74+ function _load_prometheus_operator_images_to_local_registry {
75+ for img in $( _get_prometheus_operator_images) ; do
76+ $CTR_CMD pull $img
77+ $KIND load docker-image $img
78+ done
79+ }
80+
81+ function _deploy_prometheus_operator {
82+ git clone -b ${PROMETHEUS_OPERATOR_VERSION} --depth 1 https://github.com/prometheus-operator/kube-prometheus.git
83+ sed -i -e " s/replicas: 2/replicas: ${PROMETHEUS_REPLICAS} /g" kube-prometheus/manifests/prometheus-prometheus.yaml
84+ _load_prometheus_operator_images_to_local_registry
85+ kubectl create -f kube-prometheus/manifests/setup
86+ kubectl wait \
87+ --for condition=Established \
88+ --all CustomResourceDefinition \
89+ --namespace=monitoring
90+ for file in $( ls kube-prometheus/manifests/prometheusOperator-* ) ; do
91+ kubectl create -f $file
92+ done
93+ for file in $( ls kube-prometheus/manifests/prometheus-* ) ; do
94+ kubectl create -f $file
95+ done
96+ if [ ${GRAFANA_ENABLE,,} == " true" ]; then
97+ for file in $( ls kube-prometheus/manifests/grafana-* ) ; do
98+ kubectl create -f $file
99+ done
100+ fi
101+ rm -rf kube-prometheus
102+ _wait_containers_ready monitoring
103+ }
104+
58105function _wait_kind_up {
59106 echo " Waiting for kind to be ready ..."
60107
61- while [ -z " $( docker exec --privileged ${CLUSTER_NAME} -control-plane kubectl --kubeconfig=/etc/kubernetes/admin.conf get nodes -o=jsonpath=' {.items..status.conditions[-1:].status}' | grep True) " ]; do
108+ while [ -z " $( $CTR_CMD exec --privileged ${CLUSTER_NAME} -control-plane kubectl --kubeconfig=/etc/kubernetes/admin.conf get nodes -o=jsonpath=' {.items..status.conditions[-1:].status}' | grep True) " ]; do
62109 echo " Waiting for kind to be ready ..."
63110 sleep 10
64111 done
@@ -68,7 +115,8 @@ function _wait_kind_up {
68115
69116function _wait_containers_ready {
70117 echo " Waiting for all containers to become ready ..."
71- kubectl wait --for=condition=Ready pod --all -n kube-system --timeout 12m
118+ namespace=$1
119+ kubectl wait --for=condition=Ready pod --all -n $namespace --timeout 12m
72120}
73121
74122function _fetch_kind() {
@@ -89,20 +137,20 @@ function _fetch_kind() {
89137}
90138
91139function _run_registry() {
92- until [ -z " $( docker ps -a | grep ${REGISTRY_NAME} ) " ]; do
93- docker stop ${REGISTRY_NAME} || true
94- docker rm ${REGISTRY_NAME} || true
140+ until [ -z " $( $CTR_CMD ps -a | grep ${REGISTRY_NAME} ) " ]; do
141+ $CTR_CMD stop ${REGISTRY_NAME} || true
142+ $CTR_CMD rm ${REGISTRY_NAME} || true
95143 sleep 5
96144 done
97145
98- docker run \
146+ $CTR_CMD run \
99147 -d --restart=always \
100148 -p " 127.0.0.1:${REGISTRY_PORT} :5000" \
101149 --name " ${REGISTRY_NAME} " \
102150 registry:2
103151
104152 # connect the registry to the cluster network if not already connected
105- docker network connect " ${KIND_DEFAULT_NETWORK} " " ${REGISTRY_NAME} " || true
153+ $CTR_CMD network connect " ${KIND_DEFAULT_NETWORK} " " ${REGISTRY_NAME} " || true
106154
107155 kubectl apply -f ${CONFIG_OUT_DIR} /local-registry.yml
108156}
@@ -143,8 +191,12 @@ function _setup_kind() {
143191 sleep 10
144192 done
145193
146- _wait_containers_ready
194+ _wait_containers_ready kube-system
147195 _run_registry
196+
197+ if [ ${PROMETHEUS_ENABLE,,} == " true" ]; then
198+ _deploy_prometheus_operator
199+ fi
148200}
149201
150202function _kind_up() {
@@ -166,6 +218,6 @@ function down() {
166218 fi
167219 # Avoid failing an entire test run just because of a deletion error
168220 $KIND delete cluster --name=${CLUSTER_NAME} || " true"
169- docker rm -f ${REGISTRY_NAME} >> /dev/null
221+ $CTR_CMD rm -f ${REGISTRY_NAME} >> /dev/null
170222 rm -f ${CONFIG_PATH} /${CLUSTER_PROVIDER} /kind.yml
171223}
0 commit comments