Skip to content

Commit

Permalink
Initial viable POC
Browse files Browse the repository at this point in the history
Deploys, requires genesis cf deployment to integrate with.

A couple of smoke tests aren't working, but it may be a security group
issue
  • Loading branch information
dennisjbell committed May 11, 2020
1 parent 0ad5c3b commit 6266d51
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 69 deletions.
72 changes: 72 additions & 0 deletions hooks/addon
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
set -u
#Version check
min_version="2.7.8-rc1"
genesis_version="$(genesis -v 2>&1 | grep '^Genesis v' | sed -e 's/Genesis v\(.*\) (.*$/\1/')"
if ! [[ "$genesis_version" =~ -dev$ ]] && ! new_enough "$genesis_version" "$min_version" ; then
describe >&2 "" "#R{[ERROR]} This kit needs Genesis $min_version. Please upgrade before continuing" ""
exit 1
fi
set -e

list() {
describe "" "$(cat <<EOF
The following addons are defined:
#G{bind-autoscaler} Binds the Autoscaler service broker to your
deployed CF.
EOF
)"
}

cf_login() {
cf_deployment_env="$(exodus cf_deployment_env)"
cf_deployment_type="$(exodus cf_deployment_type)"
cf_exodus="${GENESIS_EXODUS_MOUNT}${cf_deployment_env}/${cf_deployment_type}"
if ! cf plugins | grep -q '^cf-targets'; then
describe "#Y{The cf-targets plugin does not seem to be installed}"
echo "Install it first, via 'genesis do $GENESIS_ENVIRONMENT -- setup-cli'"
echo "from your $cf_deployment_env environment in your CF deployment repo."
exit 1
fi

system_domain="$(safe get "${cf_exodus}:system_domain")"
api_url=https://api.$system_domain
username="$(safe get "${cf_exodus}:admin_username")"
password="$(safe get "${cf_exodus}:admin_password")"

#TODO enfoce ssl validation
cf api "$api_url" --skip-ssl-validation
cf auth "$username" "$password"
cf save-target -f "$cf_deployment_env"
echo ; echo
cf target
}


bind_autoscaler() {
cf_login
username="$(exodus service_broker_username)"
password="$(exodus service_broker_password)"
domain=$(exodus service_broker_domain)
url="https://$domain"
cf create-service-broker autoscaler "$username" "$password" "$url"
cf enable-service-access autoscaler
echo "Successfully created the service broker."
exit 0
}


case $GENESIS_ADDON_SCRIPT in
list)
list
exit 0
;;

bind-autoscaler)
bind_autoscaler
exit 0
;;
esac

60 changes: 11 additions & 49 deletions hooks/blueprint
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,35 @@ set -eu

declare -a manifests

validate_features v1 v1-small external-db postgres-ssl

if want_feature external-db && want_feature postgres-ssl ; then
bail "Cannot specify both external-db and postgres-ssl features"
fi

if want_feature v1 ; then
want_feature v1-small && bail "Cannot specify both v1 and v1-small features"
manifests=( upstream/templates/app-autoscaler-deployment-v1.yml upstream/operations/bosh-dns-v1.yml)
for feature in external-db postgres-ssl ; do
want_feature $feature && manifests+=( "upstream/operations/$feature-v1.yml" )
done

elif want_feature v1-small ; then
manifests=( upstream/templates/app-autoscaler-deployment-fewer-v1.yml upstream/operations/bosh-dns-fewer-v1.yml)
for feature in external-db postgres-ssl ; do
want_feature $feature && manifests+=( "upstream/operations/$feature-fewer-v1.yml" )
done

else
manifests=( upstream/templates/app-autoscaler-deployment.yml )
want_feature external-db && manifests+=( "upstream/operations/external-db.yml" )

fi
validate_features external-db

manifests=( upstream/templates/app-autoscaler-deployment.yml )
want_feature external-db && manifests+=( \
"upstream/operations/external-db.yml" \
"overlay/exernal-db.yml" \
)

# Do features => opsfiles stuff here

for __feature in $GENESIS_REQUESTED_FEATURES; do
if [[ $__feature =~ operations/.* ]] ; then
if [[ -f "$__feature.yml" ]] ; then
manifests+=( "$__feature.yml" )
if [[ -f "upstream/$__feature.yml" ]] ; then
manifests+=( "upstream/$__feature.yml" )
else
__bail "GENESIS_KIT_NAME/$GENESIS_KIT_VERSION does not support the $__feature feature"
__bail "$GENSIS_KIT_ID does not support the $__feature feature"
fi
elif [[ -f $GENESIS_ROOT/ops/$__feature.yml ]] ; then
mkdir -p "$(dirname "local_ops/$__feature.yml")"
cp "$GENESIS_ROOT/ops/$__feature.yml" "local_ops/$__feature.yml"
manifests+=( "local_ops/$__feature.yml" )
else
__bail "GENESIS_KIT_NAME/$GENESIS_KIT_VERSION does not support the $__feature feature"
__bail "$GENESIS_KIT_ID does not support the $__feature feature"
fi
done

mkdir -p "generated"
bosh_dep="$(lookup "params.bosh-deployment")"
if [[ -z "$bosh_dep" ]] ; then
bosh_dep="$(lookup "params.bosh")"
[[ -n "$bosh_dep" ]] || bosh_dep="$GENESIS_ENVIRONMENT"
bosh_dep="${bosh_dep}-bosh"
fi
cf_dep="$(lookup "params.cf-deployment")"
if [[ -z "$cf_dep" ]] ; then
cf_dep="${GENESIS_ENVIRONMENT}-cf"
fi
cf_client_secret="$(credhub get -n "/$bosh_dep/$cf_dep/uaa_clients_app_autoscaler_client_secret" -q)"

cat > generated/passwords.yml <<EOF
---
params:
bosh-variables:
cf_client_secret: "$cf_client_secret"
EOF
manifests+=( \
overlay/base.yml \
overlay/change_deployment_and_network.yml \
overlay/releases.yml \
generated/passwords.yml \
)

echo "${manifests[@]}"
61 changes: 61 additions & 0 deletions hooks/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
set -u
#Version check
min_version="2.7.0"
genesis_version="$(genesis -v 2>&1 | grep '^Genesis v' | sed -e 's/Genesis v\(.*\) (.*$/\1/')"
if ! [[ "$genesis_version" =~ -dev$ ]] && ! new_enough "$genesis_version" "$min_version" ; then
describe >&2 "" "#R{[ERROR]} This kit needs Genesis $min_version. Please upgrade before continuing" ""
exit 1
fi
set -e

cc_ok=yes
# Cloud Config checks
if [[ -n "$GENESIS_CLOUD_CONFIG" ]] ; then
for t in minimal small; do
cloud_config_needs vm_type "$t"
done

# Check if there were any errors reported from the above checks.
if check_cloud_config ; then
describe " cloud config [#G{OK}]"
else
describe " cloud config [#R{FAILED}]"
cc_ok=no
fi
fi


# Runtime config checks
runtime_ok=yes

# Check for BOSH DNS
if [[ $(bosh rc | spruce json | jq -r '.addons[] | select(.name == "bosh-dns")') == "" ]]; then
runtime_ok=no
describe " #R{Errors were found} in your runtime-config:"
describe " - #R{BOSH DNS is not in the runtime-config, which is required. Refer to}"
describe " #R{'genesis man $GENESIS_ENVIRONMENT' for more info.}"
describe ""
fi

# Check if there were any errors reported from runtime config checks
if [[ "$runtime_ok" == "yes" ]]; then
describe " runtime config [#G{OK}]"
else
describe " runtime config [#R{FAILED}]"
fi

env_ok=yes
# Environment Parameter checks - none yet!

if [[ "$env_ok" == "yes" ]]; then
describe " environment files [#G{OK}]"
else
describe " environment files [#R{FAILED}]"
fi

if [[ "$env_ok" == "no" || "$cc_ok" == "no" || "$runtime_ok" == no ]] ; then
exit 1
fi


58 changes: 47 additions & 11 deletions hooks/new
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,51 @@ set -eu
#
# Genesis Kit `new' Hook
#
declare -a features
features=()

cat <<EOF >$GENESIS_ROOT/$GENESIS_ENVIRONMENT.yml
kit:
name: $GENESIS_KIT_NAME
version: $GENESIS_KIT_VERSION
features:
- (( replace ))
params:
env: $GENESIS_ENVIRONMENT
EOF
exit 0
(
echo "---"
echo "kit:"
echo " name: $GENESIS_KIT_NAME"
echo " version: $GENESIS_KIT_VERSION"
echo " features:"
for feature in "${features[@]}" ; do
echo " - $feature"
done

genesis_config_block

echo
echo "params:"
echo " # Cloud Foundry base domain"
echo " base_domain: $base_domain"

case $use_db in
mysql-db)
echo
echo " # External MySQL configuration"
echo " external_db_host: $db_host"
;;

postgres-db)
echo
echo " # External PostgreSQL configuration"
echo " external_db_host: $db_host"
;;

local-ha-db)
echo
echo " # VIP for the HA Postgres DB"
echo " postgres_vip: $postgres_vip"
esac

if [[ -z $use_provided_cert ]]; then
echo " # Skip SSL validation since we use self-signed certs"
echo " skip_ssl_validation: true"
fi
) >$GENESIS_ROOT/$GENESIS_ENVIRONMENT.yml

offer_environment_editor

# vim:foldmethod=marker
3 changes: 2 additions & 1 deletion kit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ docs: https://github.com/cloudfoundry-community/cf-app-autoscaler-boshrelease
code: https://github.com/genesis-community/cf-app-autoscaler-genesis-kit

# 2.6.0 was our last big feature bump
genesis_version_min: 2.6.0
genesis_version_min: 2.7.8-rc1
secrets_store: credhub
42 changes: 34 additions & 8 deletions overlay/base.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
---
meta:
cf:
bosh: (( grab params.cf-bosh || params.bosh || genesis.env ))
env: (( grab params.cf-env || genesis.env ))
exodus: (( concat $GENESIS_EXODUS_MOUNT params.cf_deployment_env "/" params.cf_deployment_type ))
deployment_name: (( concat params.cf_deployment_env "-" params.cf_deployment_type ))

params:
cf_system_domain: (( param "Please specify the CF system domain in params.cf_system_domain" ))
bosh-variables:
cf_client_id: app_autoscaler_client
cf_client_secret: (( concat "((/" meta.cf.bosh "-bosh/" meta.cf.env "-cf/uaa_clients_app_autoscaler_client_secret))" ))
system_domain: (( grab params.cf_system_domain ))
skip_ssl_validation: (( grab params.skip_ssl_validation || "true" ))
network: (( grab params.cf_core_network ))
cf_deployment_env: (( grab genesis.env )) # assumes same name as cf env
cf_deployment_type: cf # for crazy people using an "non-cf" cf deployment named something else
cf_core_network: (( vault meta.cf.exodus ":core_network" ))
cf_system_domain: (( vault meta.cf.exodus ":system_domain" ))

bosh-variables:
system_domain: (( grab params.cf_system_domain ))
cf_client_id: (( vault meta.cf.exodus ":app_autoscaler_client" ))
cf_client_secret: (( vault meta.cf.exodus ":app_autoscaler_secret" ))
loggregator_ca:
certificate: (( vault meta.cf.exodus ":loggregator_ca" ))
loggregator_tls_agent:
ca: (( grab bosh-variables.loggregator_ca.certificate ))
certificate: (( vault meta.cf.exodus ":loggregator_tls_rlp_cert" ))
private_key: (( vault meta.cf.exodus ":loggregator_tls_rlp_key" ))
loggregator_tls_rlp:
certificate: (( vault meta.cf.exodus ":loggregator_tls_agent_cert" ))
private_key: (( vault meta.cf.exodus ":loggregator_tls_agent_key" ))

skip_ssl_validation: (( grab params.skip_ssl_validation || "true" ))

exodus:
autoscaler_api_domain: (( concat "autoscaler." params.cf_system_domain ))
autoscaler_metrics_domain: (( concat "autoscalermetrics." params.cf_system_domain ))
service_broker_domain: (( concat "autoscalerservicebroker." params.cf_system_domain ))

service_broker_username: autoscaler_service_broker_user
service_broker_password: ((autoscaler_service_broker_password))

cf_deployment_env: (( grab params.cf_deployment_env ))
cf_deployment_type: (( grab params.cf_deployment_type ))
Loading

0 comments on commit 6266d51

Please sign in to comment.