Skip to content

Commit

Permalink
Merge pull request #3137 from cloudfoundry/autoscaler-775/dynamic-pos…
Browse files Browse the repository at this point in the history
…tgres-tcp-port

Sets postgres port to current pr number if open pr exists
  • Loading branch information
bonzofenix authored Aug 17, 2024
2 parents acf4f0c + 4652627 commit fcf023f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions ci/autoscaler/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ jobs:
file: ci/ci/autoscaler/tasks/cleanup-autoscaler.yml
params: &acceptance-log-cache-syslog-cf-params
DEPLOYMENT_NAME: ((acceptance_deployment_name_logcache_syslog_cf))
PR_NUMBER: ((pr_number))
plan:
- in_parallel:
- get: bbl-state
Expand Down
9 changes: 9 additions & 0 deletions ci/autoscaler/scripts/deploy-autoscaler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,20 @@ function setup_autoscaler_uaac(){
--secret "$autoscaler_secret" > /dev/null
fi
}
function get_postgres_external_port(){
if [ -z "${PR_NUMBER}" ]; then
echo "5432"
else
echo "${PR_NUMBER}"
fi
}

function create_manifest(){
# Set the local tmp_dir depending on if we run on github-actions or not, see:
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
local tmp_dir
local perform_as_gh_action

perform_as_gh_action="${GITHUB_ACTIONS:-false}"
if "${perform_as_gh_action}" != 'false'
then
Expand Down Expand Up @@ -102,6 +110,7 @@ function create_manifest(){
-v metricscollector_ca_cert="$(credhub get -n /bosh-autoscaler/cf/log_cache --key ca --quiet)"\
-v metricscollector_client_cert="$(credhub get -n /bosh-autoscaler/cf/log_cache --key certificate --quiet)"\
-v metricsforwarder_host="${metricsforwarder_host}"\
-v postgres_external_port="$(get_postgres_external_port)"\
-v metricscollector_client_key="$(credhub get -n /bosh-autoscaler/cf/log_cache --key private_key --quiet)"\
-v skip_ssl_validation=true \
> "${tmp_manifest_file}"
Expand Down
2 changes: 2 additions & 0 deletions ci/autoscaler/set-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ function set_pipeline(){
local pipeline_name="$1"
add_var branch_name "${CURRENT_BRANCH}"
if [[ -z $PR_NUMBER ]]; then
add_var pr_number "${PR_NUMBER}"
add_var acceptance_deployment_name "acceptance"
add_var acceptance_deployment_name_logcache_metron "acceptance-lc"
add_var acceptance_deployment_name_logcache_syslog "acceptance-lc-sl"
add_var acceptance_deployment_name_logcache_syslog_cf "acceptance-lc-sl-cf"
else
add_var pr_number "${PR_NUMBER}"
add_var acceptance_deployment_name "${PR_NUMBER}-acceptance"
add_var acceptance_deployment_name_logcache_metron "${PR_NUMBER}-acceptance-lc"
add_var acceptance_deployment_name_logcache_syslog "${PR_NUMBER}-acceptance-lc-sl"
Expand Down
2 changes: 1 addition & 1 deletion operations/use-cf-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- name: autoscaler_postgres
registration_interval: 20s
port: 5432
external_port: 5432
external_port: ((postgres_external_port))
type: tcp
router_group: default-tcp
tags:
Expand Down
4 changes: 3 additions & 1 deletion src/autoscaler/metricsforwarder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ METIRCSFORWARDER_VM := $(shell bosh -d $(DEPLOYMENT_NAME) vms --json | jq '.Tabl
POSTGRES_ADDRESS := $(DEPLOYMENT_NAME)-postgres.tcp.$(SYSTEM_DOMAIN)
LOG_CACHE_IP := $(shell bosh -d cf vms --json | jq -r '.Tables | .[] | .Rows | .[] | select(.instance|test("log-cache")) | .ips' )
MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
POSTGRES_EXTERNAL_PORT := $(or $(PR_NUMBER),5432)


.PHONY: fetch-config
fetch-config: start-metricsforwarder-vm
Expand Down Expand Up @@ -36,7 +38,7 @@ fetch-config: start-metricsforwarder-vm
cp build/assets/metricsforwarder.yml build/metricsforwarder.yml

sed -i'' -e 's|\/var\/vcap\/jobs\/metricsforwarder\/config|\/home\/vcap\/app/assets|g' build/metricsforwarder.yml
sed -i'' -e 's|$(DEPLOYMENT_NAME).autoscalerpostgres.service.cf.internal|$(POSTGRES_ADDRESS)|g' build/metricsforwarder.yml
sed -i'' -e 's|$(DEPLOYMENT_NAME).autoscalerpostgres.service.cf.internal:5432|$(POSTGRES_ADDRESS):$(POSTGRES_EXTERNAL_PORT)|g' build/metricsforwarder.yml



Expand Down

0 comments on commit fcf023f

Please sign in to comment.