Skip to content

Commit 8558c37

Browse files
authored
Merge pull request #235 from marceloamaral/kind-prometheus
Add support to deploy prometheus operator via make cluster-up
2 parents c3f8395 + cc63915 commit 8558c37

File tree

2 files changed

+67
-17
lines changed

2 files changed

+67
-17
lines changed

.github/workflows/integration_test.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@ jobs:
1616
- uses: actions/setup-go@main
1717
with:
1818
go-version: 1.18
19+
1920
- name: install kubectl
2021
run: curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
22+
2123
- name: start local k8s cluster
2224
run: make cluster-up
2325
env:
2426
CLUSTER_PROVIDER: ${{matrix.kube_provider}}
25-
- name: Checkout kube-operator repo
26-
uses: actions/checkout@v3
27-
with:
28-
repository: prometheus-operator/kube-prometheus
29-
path: kube-prometheus
30-
- name: deploy kube operator
31-
run: ls && kubectl create -f manifests/setup && until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done && kubectl create -f manifests/
32-
working-directory: kube-prometheus
27+
PROMETHEUS_ENABLE: "true"
28+
GRAFANA_ENABLE: "false"
29+
3330
- name: simple test - deploy kepler
3431
run: make cluster-sync
3532
env:
3633
CLUSTER_PROVIDER: ${{matrix.kube_provider}}
3734
CTR_CMD: docker
35+
3836
- name: Login to Quay
3937
if: github.event_name == 'push'
4038
uses: docker/login-action@v1

cluster-up/cluster/kind/common.sh

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ set -ex pipefail
2222
_registry_port="5001"
2323
_registry_name="kind-registry"
2424

25+
CTR_CMD=${CTR_CMD-docker}
26+
2527
CONFIG_PATH="cluster-up/cluster"
2628
KIND_VERSION=${KIND_VERSION:-0.15.0}
2729
KIND_MANIFESTS_DIR="$CONFIG_PATH/${CLUSTER_PROVIDER}/manifests"
@@ -33,6 +35,11 @@ KIND_DEFAULT_NETWORK="kind"
3335
IMAGE_REPO=${IMAGE_REPO:-localhost:5001/kepler}
3436
IMAGE_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+
3643
CONFIG_OUT_DIR=${CONFIG_OUT_DIR:-"_output/manifests/${CLUSTER_PROVIDER}/generated"}
3744
rm -rf ${CONFIG_OUT_DIR}
3845
mkdir -p ${CONFIG_OUT_DIR}
@@ -55,10 +62,50 @@ aarch64* | arm64*)
5562
;;
5663
esac
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+
58105
function _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

69116
function _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

74122
function _fetch_kind() {
@@ -89,20 +137,20 @@ function _fetch_kind() {
89137
}
90138

91139
function _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

150202
function _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

Comments
 (0)