Skip to content

Commit

Permalink
Fixed ordering of credential binding and app start
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJCross committed Aug 12, 2022
1 parent f3b45b7 commit 14f9cbe
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 45 deletions.
42 changes: 36 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ DBURL := $(shell case "${db_type}" in\
MYSQL_TAG := 8
POSTGRES_TAG := 12

ACCEPTANCE_SUITES?=broker api app
AUTOSCALER_DIR?=${PWD}
CI_DIR?=${PWD}/ci
CI?=false

$(shell mkdir -p target)

list-modules:
Expand Down Expand Up @@ -190,12 +194,6 @@ integration: build init-db test-certs
@echo " - using DBURL=${DBURL} OPTS=${OPTS}"
make -C src/autoscaler integration DBURL="${DBURL}" OPTS="${OPTS}"

.PHONY: acceptance-tests
BBL_STATE_PATH ?= ../app-autoscaler-env-bbl-state/bbl-state
acceptance-tests:
@echo " - Running acceptance tests";\
[ -d ${BBL_STATE_PATH} ] || { echo "Did not find bbl-state folder at ${BBL_STATE_PATH}, make sure you have checked out the app-autoscaler-env-bbl-state repository next to the app-autoscaler-release repository to run this target or indicate its location via BBL_STATE_PATH"; exit 1; };\
BBL_STATE_PATH="${BBL_STATE_PATH}" AUTOSCALER_DIR="${PWD}" ./ci/autoscaler/scripts/run-acceptance-tests.sh

.PHONY:lint $(addprefix lint_,$(go_modules))
lint: $(addprefix lint_,$(go_modules)) eslint rubocop
Expand Down Expand Up @@ -250,3 +248,35 @@ fakes:
workspace:
[ -e go.work ] || go work init
go work use $(addprefix ./src/,$(go_modules))

.PHONY: update
update:
./scripts/update

.PHONY: deploy
uaac:
which uaac || gem install cf-uaac

DEPLOYMENT_NAME?=app-autoscaler-test
.PHONY: deploy
deploy: update uaac
cd scripts;\
export DEPLOYMENT_NAME="${DEPLOYMENT_NAME}";\
source pr-vars.source.sh;\
${CI_DIR}/autoscaler/scripts/deploy-autoscaler.sh;\
${CI_DIR}/autoscaler/scripts/register-broker.sh

.PHONY: acceptance-tests
BBL_STATE_PATH ?= ../app-autoscaler-env-bbl-state/bbl-state
acceptance-tests:
@echo " - Running acceptance tests SUITES=${ACCEPTANCE_SUITES}"
[ -d ${BBL_STATE_PATH} ] || { echo "Did not find bbl-state folder at ${BBL_STATE_PATH}, make sure you have checked out the app-autoscaler-env-bbl-state repository next to the app-autoscaler-release repository to run this target or indicate its location via BBL_STATE_PATH"; exit 1; }
NAME_PREFIX="autoscaler-test"\
BBL_STATE_PATH="${BBL_STATE_PATH}"\
AUTOSCALER_DIR="${PWD}"\
SUITES="${ACCEPTANCE_SUITES}"\
SKIP_TEARDOWN=true\
NODES=1\
DEPLOYMENT_NAME="${DEPLOYMENT_NAME}"\
GINKGO_OPTS="${OPTS}"\
./ci/autoscaler/scripts/run-acceptance-tests.sh
10 changes: 9 additions & 1 deletion ci/autoscaler/scripts/deploy-autoscaler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ bbl_state_path="${BBL_STATE_PATH:-bbl-state/bbl-state}"
deployment_name="${DEPLOYMENT_NAME:-app-autoscaler}"
autoscaler_dir="${AUTOSCALER_DIR:-app-autoscaler-release}"
deployment_manifest="${script_dir}/../../../templates/app-autoscaler.yml"
ops_files="${OPS_FILES:-''}"
ops_files=${OPS_FILES:-"${autoscaler_dir}/operations/add-releases.yml\
${autoscaler_dir}/operations/instance-identity-cert-from-cf.yml\
${autoscaler_dir}/operations/add-postgres-variables.yml\
${autoscaler_dir}/operations/enable-nats-tls.yml\
${autoscaler_dir}/operations/loggregator-certs-from-cf.yml\
${autoscaler_dir}/operations/add-extra-plan.yml\
${autoscaler_dir}/operations/set-release-version.yml\
${autoscaler_dir}/operations/enable-log-cache.yml\
${autoscaler_dir}/operations/log-cache-syslog-server.yml"}
CURRENT_COMMIT_HASH=$(cd "${autoscaler_dir}"; git log -1 --pretty=format:"%H")
bosh_release_version=${RELEASE_VERSION:-${CURRENT_COMMIT_HASH}-${deployment_name}}

Expand Down
2 changes: 1 addition & 1 deletion ci/autoscaler/scripts/run-acceptance-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ done
echo "Running $suites_to_run"

if [ "${suites_to_run}" != "" ]; then
SKIP_TEARDOWN=$skip_teardown CONFIG=$PWD/acceptance_config.json ./bin/test "$gingko_opts" -race -nodes="${nodes}" --slow-spec-threshold=120s -trace "${suites_to_run}"
SKIP_TEARDOWN=$skip_teardown CONFIG=$PWD/acceptance_config.json ./bin/test -race -nodes="${nodes}" --slow-spec-threshold=120s -trace "$gingko_opts" "${suites_to_run}"
else
echo "Nothing to run!"
fi
Expand Down
8 changes: 2 additions & 6 deletions scripts/pr-vars.source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
# shellcheck disable=SC2155
export script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
pr_number=${PR_NUMBER:-44}
export DEPLOYMENT_NAME="app-autoscaler-${pr_number}"
export SERVICE_BROKER_NAME="app-autoscaler-${pr_number}servicebroker"
export DEPLOYMENT_NAME=${DEPLOYMENT_NAME:-"app-autoscaler-${pr_number}"}
export SERVICE_BROKER_NAME="${DEPLOYMENT_NAME}servicebroker"
export BBL_STATE_PATH="${script_dir}/../../app-autoscaler-env-bbl-state/bbl-state"
export SYSTEM_DOMAIN="autoscaler.ci.cloudfoundry.org"
export AUTOSCALER_DIR="${script_dir}/../"
export CI_DIR="${script_dir}/../ci"
export OPS_FILES="${AUTOSCALER_DIR}/example/operation/loggregator-certs-from-cf.yml\
${AUTOSCALER_DIR}/example/operation/add-extra-plan.yml\
${AUTOSCALER_DIR}/example/operation/set-release-version.yml\
${AUTOSCALER_DIR}/example/operation/enable-name-based-deployments.yml"
export SERVICE_OFFERING_ENABLED=true
export SKIP_SSL_VALIDATION=true
export NAME_PREFIX=${NAME_PREFIX:-"${DEPLOYMENT_NAME}-TESTS"}
Expand Down
20 changes: 10 additions & 10 deletions scripts/update
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

set -euo pipefail

pushd src/autoscaler
pushd src/autoscaler > /dev/null
go mod tidy
go mod vendor
popd
popd > /dev/null

pushd src/changeloglockcleaner
pushd src/changeloglockcleaner > /dev/null
go mod tidy
go mod vendor
popd
popd > /dev/null

pushd src/acceptance
pushd src/acceptance > /dev/null
go mod tidy
go mod vendor
popd
popd > /dev/null

pushd src/db
pushd src/db > /dev/null
mvn --no-transfer-progress package -DskipTests
popd
popd > /dev/null

pushd src/scheduler
pushd src/scheduler > /dev/null
mvn --no-transfer-progress package -DskipTests
popd
popd > /dev/null
2 changes: 1 addition & 1 deletion src/acceptance/app/recurring_schedule_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ var _ = Describe("AutoScaler recurring schedule policy", func() {
Context("when scaling by recurring schedule", func() {

JustBeforeEach(func() {
StartApp(appName, cfg.CfPushTimeoutDuration())
startTime, endTime = getStartAndEndTime(time.UTC, 70*time.Second, time.Duration(interval+120)*time.Second)
policy = GenerateDynamicAndRecurringSchedulePolicy(1, 4, 80, "UTC", startTime, endTime, daysOfMonthOrWeek, 2, 5, 3)
instanceName = CreatePolicy(cfg, appName, appGUID, policy)
StartApp(appName, cfg.CfPushTimeoutDuration())
})

scaleDown := func() {
Expand Down
1 change: 1 addition & 0 deletions src/acceptance/app/specificdate_schedule_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var _ = Describe("AutoScaler specific date schedule policy", func() {
Context("when scaling by specific date schedule", func() {

JustBeforeEach(func() {
//TODO the start app needs to be after the binding but the timings require the app been up already.
StartApp(appName, cfg.CfPushTimeoutDuration())
startDateTime = time.Now().In(time.UTC).Add(1 * time.Minute)
endDateTime = startDateTime.Add(time.Duration(interval+120) * time.Second)
Expand Down
30 changes: 16 additions & 14 deletions src/acceptance/assets/app/nodeApp/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,34 @@ function getCredentials () {
// for service offering
console.log('Getting credentials...')
if (process.env.VCAP_SERVICES) {
console.log(` - found vcap looking for ${serviceName}`)
const vcapServices = JSON.parse(process.env.VCAP_SERVICES)
const service = vcapServices[serviceName]

if (service && service[0] && service[0].credentials) {
credentials = service[0].credentials
metricsForwarderURL = credentials.custom_metrics.url
mfUsername = credentials.custom_metrics.username
mfPassword = credentials.custom_metrics.password
console.log('consumed VCAP_SERVICES env variable (service_offering)')
if (service && service[0]) {
console.log(` - found service ${serviceName}`)
if (service[0].credentials) {
console.log(' - found credentials')
credentials = service[0].credentials
metricsForwarderURL = credentials.custom_metrics.url
mfUsername = credentials.custom_metrics.username
mfPassword = credentials.custom_metrics.password
} else {
const err = 'ERROR: no credentials in bound service env variable'
console.error(err)
throw err
}
}
} else {
const err = 'ERROR: no VCAP_SERVICES env variable'
console.error(err)
throw err
}

// for build-in offering
if (metricsForwarderURL === '' || mfUsername === '' || mfPassword === '') {
console.log(' - looking for creds in env (built in case)')
if (process.env.AUTO_SCALER_CUSTOM_METRIC_ENV) {
console.log(' - found credentials in AUTO_SCALER_CUSTOM_METRIC_ENV')
credentials = JSON.parse(process.env.AUTO_SCALER_CUSTOM_METRIC_ENV)
metricsForwarderURL = credentials.url
mfUsername = credentials.username
mfPassword = credentials.password
console.log(
'consumed AUTO_SCALER_CUSTOM_METRIC_ENV env variable (use_buildin_mode)'
)
} else {
console.error('ERROR: not all credentials were provided.')
console.log(
Expand Down
4 changes: 3 additions & 1 deletion src/acceptance/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func CheckServiceExists(cfg *config.Config, spaceName, serviceName string) {
Expect(spaceCmd).To(Exit(0), fmt.Sprintf("Space, %s, does not exist", spaceName))
spaceGuid := strings.TrimSpace(strings.Trim(string(spaceCmd.Out.Contents()), "\n"))

serviceCmd := cf.Cf("curl", "-f", ServicePlansUrl(cfg, spaceGuid)).Wait(cfg.DefaultTimeoutDuration())
serviceCmd := cf.CfSilent("curl", "-f", ServicePlansUrl(cfg, spaceGuid)).Wait(cfg.DefaultTimeoutDuration())
if serviceCmd.ExitCode() != 0 {
Fail(fmt.Sprintf("Failed get broker information for serviceName=%s spaceName=%s", cfg.ServiceName, spaceName))
}
Expand All @@ -151,11 +151,13 @@ func CheckServiceExists(cfg *config.Config, spaceName, serviceName string) {
if err != nil {
AbortSuite(fmt.Sprintf("Failed to parse service plan json: %s\n\n'%s'", err.Error(), string(contents)))
}
GinkgoWriter.Printf("\nFound services: %s\n", services.Included.ServiceOfferings)
for _, service := range services.Included.ServiceOfferings {
if service.Name == serviceName {
return
}
}

cf.Cf("marketplace", "-e", cfg.ServiceName).Wait(cfg.DefaultTimeoutDuration())
Fail(fmt.Sprintf("Could not find service %s in space %s", serviceName, spaceName))
}
Expand Down
6 changes: 4 additions & 2 deletions src/acceptance/helpers/org_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"strings"

"github.com/onsi/ginkgo/v2"

"github.com/KevinJCross/cf-test-helpers/v2/cf"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -33,7 +35,7 @@ type cfSpaces struct {
}

func GetTestOrgs(cfg *config.Config) []string {
rawOrgs := cf.Cf("curl", "/v3/organizations").Wait(cfg.DefaultTimeoutDuration())
rawOrgs := cf.CfSilent("curl", "/v3/organizations").Wait(cfg.DefaultTimeoutDuration())
Expect(rawOrgs).To(Exit(0), "unable to get orgs")

var orgs cfOrgs
Expand All @@ -46,7 +48,7 @@ func GetTestOrgs(cfg *config.Config) []string {
orgNames = append(orgNames, org.Name)
}
}

ginkgo.GinkgoWriter.Printf("\nGot orgs: %s\n", orgNames)
return orgNames
}

Expand Down
3 changes: 1 addition & 2 deletions src/acceptance/pre_upgrade/pre_custom_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ var _ = Describe("AutoScaler custom metrics policy", func() {
policy = helpers.GenerateDynamicScaleOutAndInPolicy(1, 2, "test_metric", 500, 500)
appName = helpers.CreateTestApp(cfg, "node-custom-metric", 1)
appGUID = helpers.GetAppGuid(cfg, appName)
helpers.StartApp(appName, cfg.CfPushTimeoutDuration())
_ = helpers.CreatePolicy(cfg, appName, appGUID, policy)
helpers.CreateCustomMetricCred(cfg, appName, appGUID)
helpers.WaitForNInstancesRunning(appGUID, 1, cfg.DefaultTimeoutDuration())
helpers.StartApp(appName, cfg.CfPushTimeoutDuration())
})

Context("when scaling by custom metrics", func() {
Expand Down
2 changes: 1 addition & 1 deletion src/acceptance/pre_upgrade/pre_dynamic_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var _ = Describe("AutoScaler dynamic policy", func() {
JustBeforeEach(func() {
appName = helpers.CreateTestApp(cfg, "nodeapp-cpu", initialInstanceCount)
appGUID = helpers.GetAppGuid(cfg, appName)
helpers.StartApp(appName, cfg.CfPushTimeoutDuration())
_ = helpers.CreatePolicy(cfg, appName, appGUID, policy)
helpers.StartApp(appName, cfg.CfPushTimeoutDuration())
})

Context("when scaling by cpu", func() {
Expand Down

0 comments on commit 14f9cbe

Please sign in to comment.