From 9bc6935ed38ee30e82af36039496e18b20bdcac1 Mon Sep 17 00:00:00 2001 From: Scott Trent Date: Wed, 21 Feb 2024 15:08:32 +0900 Subject: [PATCH 1/5] parameterization Signed-off-by: Scott Trent --- test/susqltopmon | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/susqltopmon b/test/susqltopmon index e4ccced..78ae04a 100755 --- a/test/susqltopmon +++ b/test/susqltopmon @@ -1,6 +1,8 @@ #!/usr/bin/bash -echo gathering data... Then updating every 5 seconds +INTERVAL=2 + +echo gathering data... Then updating every ${INTERVAL} seconds d=$(dirname ${0}) -watch -n 5 --no-title "${d}/susqltop ${1} ${2}" +watch -n ${INTERVAL} --no-title "${d}/susqltop ${1} ${2}" From 646e5ab45d3a86b2c7c312dd5b474248c9e2247d Mon Sep 17 00:00:00 2001 From: Scott Trent Date: Wed, 21 Feb 2024 15:10:19 +0900 Subject: [PATCH 2/5] enhance customization Signed-off-by: Scott Trent --- deployment/deploy.sh | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/deployment/deploy.sh b/deployment/deploy.sh index 125d26a..ec9fa4e 100644 --- a/deployment/deploy.sh +++ b/deployment/deploy.sh @@ -10,6 +10,10 @@ if ! command -v kubectl &> /dev/null; then exit 1 fi +if [[ ! -z ${SUSQL_ENHANCED} ]]; then + echo "Deploying enhanced SusQL configuration." +fi + # Check if there is a current context current_context=$(kubectl config current-context) if [[ -z $current_context ]]; then # exit @@ -72,9 +76,15 @@ fi # Set SusQL installation variables SUSQL_DIR=".." -SUSQL_REGISTRY="quay.io/sustainable_computing_io" -SUSQL_IMAGE_NAME="susql_operator" -SUSQL_IMAGE_TAG="latest" +if [[ -z ${SUSQL_REGISTRY} ]]; then + SUSQL_REGISTRY="quay.io/sustainable_computing_io" +fi +if [[ -z ${SUSQL_IMAGE_NAME} ]]; then + SUSQL_IMAGE_NAME="susql_operator" +fi +if [[ -z ${SUSQL_IMAGE_TAG} ]]; then + SUSQL_IMAGE_TAG="latest" +fi # Actions to perform, separated by comma actions=${1:-"kepler-check,prometheus-undeploy,prometheus-deploy,susql-undeploy,susql-deploy"} @@ -126,7 +136,9 @@ do fi elif [[ ${action} = "susql-deploy" ]]; then - kubectl apply -f ../config/rbac/susql-rbac.yaml + if [[ ! -z ${SUSQL_ENHANCED} ]]; then + kubectl apply -f ../config/rbac/susql-rbac.yaml + fi cd ${SUSQL_DIR} && make manifests && make install cd - @@ -136,7 +148,9 @@ do --set susqlPrometheusMetricsUrl="http://0.0.0.0:8082" \ --set imagePullPolicy="Always" \ --set containerImage="${SUSQL_REGISTRY}/${SUSQL_IMAGE_NAME}:${SUSQL_IMAGE_TAG}" - kubectl apply -f ../config/servicemonitor/susql-smon.yaml + if [[ ! -z ${SUSQL_ENHANCED} ]]; then + kubectl apply -f ../config/servicemonitor/susql-smon.yaml + fi elif [[ ${action} = "susql-undeploy" ]]; then echo "Undeploying SusQL controller..." @@ -149,8 +163,10 @@ do fi helm -n ${SUSQL_NAMESPACE} uninstall susql-controller - kubectl delete -f ../config/rbac/susql-rbac.yaml - kubectl delete -f ../config/servicemonitor/susql-smon.yaml + if [[ ! -z ${SUSQL_ENHANCED} ]]; then + kubectl delete -f ../config/rbac/susql-rbac.yaml + kubectl delete -f ../config/servicemonitor/susql-smon.yaml + fi else echo "Nothing to do" From 074a5f75271a0d71b9233d44e2e105e7a553ec19 Mon Sep 17 00:00:00 2001 From: Scott Trent Date: Wed, 21 Feb 2024 15:14:08 +0900 Subject: [PATCH 3/5] enhance http vs https customization Signed-off-by: Scott Trent --- internal/controller/prometheus_manager.go | 28 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/controller/prometheus_manager.go b/internal/controller/prometheus_manager.go index 4995ebc..485e52c 100644 --- a/internal/controller/prometheus_manager.go +++ b/internal/controller/prometheus_manager.go @@ -42,14 +42,20 @@ var ( // Functions to get data from the cluster func (r *LabelGroupReconciler) GetMostRecentValue(susqlPrometheusQuery string) (float64, error) { // Return the most recent value found in the table - rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} + var roundtripper http.RoundTripper = nil + if strings.HasPrefix(r.KeplerPrometheusUrl, "https://") { + rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} + roundtripper = config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls) + } client, err := api.NewClient(api.Config{ Address: r.SusQLPrometheusDatabaseUrl, - RoundTripper: config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls), + RoundTripper: roundtripper, }) if err != nil { fmt.Printf("ERROR [GetMostRecentValue]: Couldn't create HTTP client: %v\n", err) + fmt.Printf("Query: %s\n", susqlPrometheusQuery) + fmt.Printf("SusQLPrometheusDatabaseUrl: %s\n", r.SusQLPrometheusDatabaseUrl) os.Exit(1) } @@ -62,10 +68,14 @@ func (r *LabelGroupReconciler) GetMostRecentValue(susqlPrometheusQuery string) ( if len(warnings) > 0 { fmt.Printf("WARNING [GetMostRecentValue]: %v\n", warnings) + fmt.Printf("Query: %s\n", susqlPrometheusQuery) + fmt.Printf("SusQLPrometheusDatabaseUrl: %s\n", r.SusQLPrometheusDatabaseUrl) } if err != nil { fmt.Printf("ERROR [GetMostRecentValue]: Querying Prometheus didn't work: %v\n", err) + fmt.Printf("Query: %s\n", susqlPrometheusQuery) + fmt.Printf("SusQLPrometheusDatabaseUrl: %s\n", r.SusQLPrometheusDatabaseUrl) return 0.0, err } @@ -77,14 +87,20 @@ func (r *LabelGroupReconciler) GetMostRecentValue(susqlPrometheusQuery string) ( } func (r *LabelGroupReconciler) GetMetricValuesForPodNames(metricName string, podNames []string) (map[string]float64, error) { - rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} + var roundtripper http.RoundTripper = nil + if strings.HasPrefix(r.KeplerPrometheusUrl, "https://") { + rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} + roundtripper = config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls) + } client, err := api.NewClient(api.Config{ Address: r.KeplerPrometheusUrl, - RoundTripper: config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls), + RoundTripper: roundtripper, }) if err != nil { fmt.Printf("ERROR [GetMetricValuesForPodNames]: Couldn't created an HTTP client: %v\n", err) + fmt.Printf("metricName: %s\n", metricName) + fmt.Printf("KeplerPrometheusUrl: %s\n", r.KeplerPrometheusUrl) os.Exit(1) } @@ -97,11 +113,15 @@ func (r *LabelGroupReconciler) GetMetricValuesForPodNames(metricName string, pod if err != nil { fmt.Printf("ERROR [GetMetricValuesForPodNames]: Querying Prometheus didn't work: %v\n", err) + fmt.Printf("metricName: %s\n", metricName) + fmt.Printf("KeplerPrometheusUrl: %s\n", r.KeplerPrometheusUrl) return nil, err } if len(warnings) > 0 { fmt.Printf("WARNING [GetMetricValuesForPodNames]: %v\n", warnings) + fmt.Printf("metricName: %s\n", metricName) + fmt.Printf("KeplerPrometheusUrl: %s\n", r.KeplerPrometheusUrl) } metricValues := make(map[string]float64, len(results.(model.Vector))) From 26a1b0b5c377c04ef579ca323cea22c2cb9abdf4 Mon Sep 17 00:00:00 2001 From: Scott Trent Date: Wed, 21 Feb 2024 17:00:15 +0900 Subject: [PATCH 4/5] update usage Signed-off-by: Scott Trent --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7e1a644..fa9c768 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ SusQL is an operator that can be deployed in a Kubernetes/OpenShift cluster. You ### Prerequisites -Kepler is assumed to be installed in the cluster. `go`, `helm`, and `kubectl` are used to for deployment. +Kepler is assumed to be installed in the cluster. `helm` and `kubectl` are also required to deploy. ### Installation @@ -31,16 +31,10 @@ To install SusQL go to the `deployment` directory and run the command `$ bash de $ PROMETHEUS_SERVICE= PROMETHEUS_NAMESPACE= PROMETHEUS_DOMAIN= bash deploy.sh ``` - Alternatively, with a unique cluster such as a single node OpenShift local cluster, it may be necessary to set KEPLER_PROMETHEUS_URL directly such as: + Or for example, the following works for a 4.12 single node OpenShift local cluster: ``` - $ KEPLER_PROMETHEUS_URL=http://prometheus-k8s-openshift-monitoring.apps-crc.testing/api:9091 bash deploy.sh - ``` - - Alternatively, with a very unusual cluster such as a single node OpenShift local cluster, it may be necessary to set KEPLER_PROMETHEUS_URL directly such as: - - ``` - $ KEPLER_PROMETHEUS_URL=http://prometheus-k8s-openshift-monitoring.apps-crc.testing/api:9091 bash deploy.sh + $ PROMETHEUS_PROTOCOL=https PROMETHEUS_PORT=9091 PROMETHEUS_NAMESPACE=openshift-monitoring PROMETHEUS_SERVICE=thanos-querier SUSQL_ENHANCED=true bash deploy.sh ``` * Create the namespace `openshift-kepler-operator` From 7feb404cf4add898d8ec153adfd26b19a7ef7a5c Mon Sep 17 00:00:00 2001 From: Scott Trent Date: Wed, 21 Feb 2024 17:01:29 +0900 Subject: [PATCH 5/5] fix grammar Signed-off-by: Scott Trent --- internal/controller/prometheus_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/prometheus_manager.go b/internal/controller/prometheus_manager.go index 485e52c..bb3e1c2 100644 --- a/internal/controller/prometheus_manager.go +++ b/internal/controller/prometheus_manager.go @@ -98,7 +98,7 @@ func (r *LabelGroupReconciler) GetMetricValuesForPodNames(metricName string, pod }) if err != nil { - fmt.Printf("ERROR [GetMetricValuesForPodNames]: Couldn't created an HTTP client: %v\n", err) + fmt.Printf("ERROR [GetMetricValuesForPodNames]: Couldn't create an HTTP client: %v\n", err) fmt.Printf("metricName: %s\n", metricName) fmt.Printf("KeplerPrometheusUrl: %s\n", r.KeplerPrometheusUrl) os.Exit(1)