Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy prometheus #1013

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b9e2bc9
sample servicemonitor and values
HaoYang0000 Dec 24, 2024
f39bfb2
update make file
HaoYang0000 Dec 24, 2024
1c25379
update sample service monitor
HaoYang0000 Dec 25, 2024
6cf5e69
update example values
HaoYang0000 Dec 25, 2024
dd38f92
create script
HaoYang0000 Dec 26, 2024
b8b2110
update make file
HaoYang0000 Dec 26, 2024
1682e71
remove template file
HaoYang0000 Dec 26, 2024
5c3da03
remove unused content
HaoYang0000 Dec 26, 2024
4cd1754
address comments
HaoYang0000 Dec 26, 2024
593441a
add interval in scrpits and fix bug in namespace
HaoYang0000 Dec 26, 2024
b83799f
add namespace in undeploy
HaoYang0000 Dec 26, 2024
5d8c464
add vdb namespace customize
HaoYang0000 Dec 26, 2024
b0b6b88
revert change
HaoYang0000 Dec 26, 2024
aabad14
revert make file changes
HaoYang0000 Jan 2, 2025
1006b9a
update default values
HaoYang0000 Jan 2, 2025
e878ad6
move values file to prometheus directory
HaoYang0000 Jan 2, 2025
5e260c8
update file path
HaoYang0000 Jan 2, 2025
825cbbc
add e2e test
HaoYang0000 Jan 2, 2025
d1a9398
address comments
HaoYang0000 Jan 2, 2025
bbbe46b
Update Makefile
HaoYang0000 Jan 3, 2025
cabbde9
update e2e test
HaoYang0000 Jan 3, 2025
1e4d33b
rename dbname to vdbname in script
HaoYang0000 Jan 3, 2025
dd194a6
update script with cmd instead of cat f
HaoYang0000 Jan 3, 2025
4e9ca4e
add label for secret
HaoYang0000 Jan 3, 2025
9aa2428
assert service as well in e2e check
HaoYang0000 Jan 3, 2025
cfc65ca
add cr deletetion and fix namespace issue
HaoYang0000 Jan 3, 2025
1910af9
fix namespace issue
HaoYang0000 Jan 3, 2025
da6aea4
fix _
HaoYang0000 Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,17 @@ export OLM_CATALOG_IMG
MINIMAL_VERTICA_IMG ?=
# Name of the helm release that we will install/uninstall
HELM_RELEASE_NAME?=vdb-op
PROMETHEUS_HELM_NAME?=prometheus
PROMETHEUS_INTERVAL?=5s
DB_USER?=dbadmin
DB_PASSWORD?=
VDB_NAME?=verticadb-sample
VDB_NAMESPACE?=default
# Can be used to specify additional overrides when doing the helm install.
# For example to specify a custom webhook tls cert when deploying use this command:
# HELM_OVERRIDES="--set webhook.tlsSecret=custom-cert" make deploy-operator
HELM_OVERRIDES?=
PROMETHEUS_HELM_OVERRIDES?=
# Maximum number of tests to run at once. (default 2)
# Set it to any value not greater than 8 to override the default one
E2E_PARALLELISM?=2
Expand Down Expand Up @@ -246,6 +253,8 @@ DEPLOY_WAIT?=--wait
OLM_TEST_CATALOG_SOURCE=e2e-test-catalog
# Name of the namespace to deploy the operator in
NAMESPACE?=verticadb-operator
# Name of the namespace to deploy prometheus
PROMETHEUS_NAMESPACE?=prometheus

# The Go version that we will build the operator with
GO_VERSION?=1.23.2
Expand All @@ -255,6 +264,7 @@ HELM_UNITTEST_VERSION?=3.9.3-0.2.11
KUTTL_PLUGIN_INSTALLED:=$(shell kubectl krew list 2>/dev/null | grep -c '^kuttl')
STERN_PLUGIN_INSTALLED:=$(shell kubectl krew list 2>/dev/null | grep -c '^stern')
OPERATOR_CHART = $(shell pwd)/helm-charts/verticadb-operator
PROMETHEUS_CHART=prometheus-community/kube-prometheus-stack

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -634,12 +644,30 @@ endif

deploy-webhook: manifests kustomize ## Using helm, deploy just the webhook in the k8s cluster
ifeq ($(DEPLOY_WITH), helm)
helm install $(DEPLOY_WAIT) -n $(NAMESPACE) --create-namespace $(HELM_RELEASE_NAME) $(OPERATOR_CHART) --set image.repo=null --set image.name=${OPERATOR_IMG} --set image.pullPolicy=$(HELM_IMAGE_PULL_POLICY) --set imagePullSecrets[0].name=priv-reg-cred $(HELM_OVERRIDES) --set webhook.enable=true,controllers.enable=false
helm install $(DEPLOY_WAIT) -n $(NAMESPACE) --create-namespace $(HELM_RELEASE_NAME) $(OPERATOR_CHART) --set image.repo=null --set image.name=${OPERATOR_IMG} --set image.pullPolicy=$(HELM_IMAGE_PULL_POLICY) --set imagePullSecrets[0].name=priv-reg-cred --set webhook.enable=true,controllers.enable=false $(HELM_OVERRIDES)
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
scripts/wait-for-webhook.sh -n $(NAMESPACE) -t 60
else
$(error Unsupported deployment method for webhook only: $(DEPLOY_WITH))
endif

.PHONY: deploy-prometheus
deploy-prometheus:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install $(DEPLOY_WAIT) -n $(PROMETHEUS_NAMESPACE) --create-namespace $(PROMETHEUS_HELM_NAME) $(PROMETHEUS_CHART) --values helm-charts/prometheus/values.yaml $(PROMETHEUS_HELM_OVERRIDES)

.PHONY: undeploy-prometheus
undeploy-prometheus:
helm uninstall $(PROMETHEUS_HELM_NAME) -n $(PROMETHEUS_NAMESPACE)

.PHONY: deploy-prometheus-service-monitor
deploy-prometheus-service-monitor:
scripts/deploy-prometheus.sh -n $(VDB_NAMESPACE) -l $(PROMETHEUS_HELM_NAME) -i $(PROMETHEUS_INTERVAL) -a deploy -u $(DB_USER) -p '$(DB_PASSWORD)' -d $(VDB_NAME)

.PHONY: undeploy-prometheus-service-monitor
undeploy-prometheus-service-monitor:
scripts/deploy-prometheus.sh -n $(VDB_NAMESPACE) -l $(PROMETHEUS_HELM_NAME) -i $(PROMETHEUS_INTERVAL) -a undeploy -u $(DB_USER) -p '$(DB_PASSWORD)' -d $(VDB_NAME)

.PHONY: undeploy-operator
undeploy-operator: ## Undeploy operator that was previously deployed
scripts/undeploy.sh $(if $(filter false,$(ignore-not-found)),,-i)
Expand Down
24 changes: 24 additions & 0 deletions helm-charts/prometheus/values.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Given it is not a chart, let's this file from helm-charts/prometheus to prometheus
  • This file must also be generated by a script so we can parametrize a few of these fields.
  • The number of replicas must be configurable
  • We also want to be able to control the resources(cpu, mem) of prometheus pods(server.resources.requests/server.resources.limits)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is moved to prometheus.
This file meant to provide a default value for the helm, we can parameterized fields by providing PROMETHEUS_HELM_OVERRIDES=--set attribute.name=something

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defaultRules:
create: false
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
alertmanager:
enabled: true
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
grafana:
enabled: false
kubeApiServer:
enabled: true
kubelet:
enabled: false
kubeControllerManager:
enabled: true
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
coreDns:
enabled: false
kubeEtcd:
enabled: false
kubeScheduler:
enabled: false
kubeStateMetrics:
enabled: true
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
nodeExporter:
enabled: true
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
prometheus:
enabled: true
196 changes: 196 additions & 0 deletions scripts/deploy-prometheus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#!/bin/bash

# (c) Copyright [2021-2024] Open Text.
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# A script that will deploy the prometheus service monitor and secret. It assumes the prometheus operator is deployed.


SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_DIR=$(dirname $SCRIPT_DIR)
LABEL=''
ACTION=''
NAMESPACE=''
USERNAME=''
PASSWORD=''
DBNAME=''
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
INTERVAL='5s'

function usage() {
echo "usage: $(basename $0) [-n <namespace>] [-l <label>] [-a <action>] [-u <username>] [-p <password>] [-d <dbname>] [-i <interval>]"
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
echo
echo "Options:"
echo " -n <namespace> The namespace used for prometheus service."
echo " -l <label> The label monitored by prometheus service."
echo " -a <action> The action to run in this script, deploy or undeploy."
echo " -u <username> The database username, should have access to the Vertica server metrics."
echo " -p <password> The database user password."
echo " -d <dbname> The database name."
echo " -i <interval> The scraping interval of prometheus update for metrics."
echo " -h <usage> Print help message."
exit 1
}

while getopts "n:l:a:u:p:d:i:h" opt
do
case $opt in
n)
NAMESPACE=$OPTARG
;;
l)
LABEL=$OPTARG
;;
a)
ACTION=$OPTARG
;;
u)
USERNAME=$OPTARG
;;
p)
PASSWORD=$OPTARG
;;
d)
DBNAME=$OPTARG
;;
i)
INTERVAL=$OPTARG
;;
h)
usage
exit 0
;;
\?)
echo "ERROR: unrecognized option: -$opt"
usage
exit 0
;;
esac
done

if [ -z "$NAMESPACE" ]
then
NAMESPACE=default
fi


function deploy(){
# Create an secret to store prometheus service monitor database username and password.
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
namespace: $NAMESPACE
name: prometheus-$DBNAME
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
data:
username: '$(echo -n $USERNAME | base64)'
password: '$(echo -n $PASSWORD | base64)'
type: Opaque
EOF

# Create a service monitor to allow prometheus to discover vertica pods
cat <<EOF | kubectl apply -f -
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: k8s-vertica-prometheus-$DBNAME
namespace: $NAMESPACE
labels:
release: $LABEL
spec:
selector:
matchLabels:
app.kubernetes.io/instance: $DBNAME
namespaceSelector:
matchNames:
- $NAMESPACE
endpoints:
- basicAuth:
password:
key: password
name: prometheus-$DBNAME
username:
key: username
name: prometheus-$DBNAME
optional: true
interval: $INTERVAL
path: /v1/metrics
port: vertica-http
scheme: https
tlsConfig:
insecureSkipVerify: true
EOF
}

function undeploy(){
# Delete the service monitor for prometheus service monitor.
cat <<EOF | kubectl delete -f -
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: k8s-vertica-prometheus-$DBNAME
namespace: $NAMESPACE
labels:
release: $LABEL
spec:
selector:
matchLabels:
app.kubernetes.io/instance: $DBNAME
namespaceSelector:
matchNames:
- $NAMESPACE
endpoints:
- basicAuth:
password:
key: password
name: prometheus-$DBNAME
username:
key: username
name: prometheus-$DBNAME
optional: true
interval: $INTERVAL
path: /v1/metrics
port: vertica-http
scheme: https
tlsConfig:
insecureSkipVerify: true
EOF
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved

# delete secret for prometheus service monitor.
cat <<EOF | kubectl delete -f -
apiVersion: v1
kind: Secret
metadata:
namespace: $NAMESPACE
name: prometheus-$DBNAME
data:
username: '$(echo -n $USERNAME | base64)'
password: '$(echo -n $PASSWORD | base64)'
type: Opaque
EOF
HaoYang0000 marked this conversation as resolved.
Show resolved Hide resolved
}

# ACTION deploy and undeploy
case $ACTION in
deploy)
echo "Running task: $ACTION"
deploy
;;
undeploy)
echo "Running task: $ACTION"
undeploy
;;
*)
echo "Invalid action: '$ACTION'"
usage
;;
esac
Loading