Skip to content

Commit b6c4963

Browse files
authored
dev env: fix secret creation for external secret (#226)
also defaults VPN IP assignment to 201 when nonexistent
1 parent a6ff8de commit b6c4963

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

templates/scripts/add-vpn-user.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ CLUSTER=$(kubectl config current-context | cut -d"/" -f2)
77
NAMESPACE=<% .Name %>
88
REGION=<% index .Params `region` %>
99

10+
if [[ "$CLUSTER" = *"-stage-"* ]]; then
11+
DEFAULT_IP="10.10.199.200"
12+
else
13+
DEFAULT_IP="10.10.99.200"
14+
fi
15+
1016
# get pod id for execution
1117
POD=$(kubectl -n vpn get pods --selector=app=wireguard -o jsonpath='{.items[0].metadata.name}')
1218

@@ -16,7 +22,7 @@ if [ -z "$POD" ]; then
1622
fi
1723

1824
function k8s_exec() {
19-
kubectl -n vpn exec -it $POD -- /bin/bash -c "$1"
25+
kubectl -n vpn exec $POD wireguard --container wireguard -- /bin/bash -c "$1"
2026
}
2127

2228
# get name
@@ -32,6 +38,8 @@ client_public_key=$(k8s_exec "echo -n $client_private_key | wg pubkey | tr -d \"
3238

3339
# get next available IP
3440
existing_ips=$(k8s_exec "cat /etc/wireguard/wg0.conf | grep AllowedIPs| cut -d\" \" -f3 | cut -d\"/\" -f1 | sort")
41+
# Default start at 201 if no existing IPs are found
42+
existing_ips=${existing_ips:-$DEFAULT_IP}
3543
last_ip=$(echo "$existing_ips" | tr -cd "[:alnum:].\n" | tail -1)
3644
next_ip=$last_ip
3745
while [[ "$existing_ips" =~ "$next_ip" ]]; do

templates/scripts/create-db-user.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ DOCKER_IMAGE_TAG=commitdev/zero-k8s-utilities:0.0.3
3535
# database info preparation
3636
# this script will run both before and after make-apply-k8s, therefore the database service is not always available
3737
DB_ENDPOINT=$(aws rds describe-db-instances --region=$REGION --db-instance-identifier "${PROJECT_NAME}-${ENVIRONMENT}" --query "DBInstances[0].Endpoint.Address" | jq -r '.')
38-
DB_NAME_LIST=$(echo ${DATABASE_NAME} | tr -dc 'A-Za-z0-9 ') # used by job
38+
DB_NAME_LIST=$(echo ${DATABASE_NAME} | tr -dc 'A-Za-z0-9_ ') # used by job
3939
DB_NAME=$(echo ${DB_NAME_LIST} | cut -d" " -f1) # used by db-pod
4040
DB_TYPE=${DATABASE_TYPE}
4141
## get rds master

templates/scripts/create-dev-env.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
PROJECT=<% .Name %>
44
AWS_DEFAULT_REGION=<% index .Params `region` %>
55
RANDOM_SEED="<% index .Params `randomSeed` %>"
6+
DATABASE_TYPE=<% index .Params `database` %>
67
ENVIRONMENT=stage # only apply to Staging environment
78

8-
DEV_DB_LIST=$(aws iam get-group --group-name ${PROJECT}-developer-${ENVIRONMENT} | jq -r '"dev" + .Users[].UserName' | tr '\n' ' ')
9+
## Creating each member in developer IAM group a dev-database
10+
## name: john-doe -> dbname: dev_johndoe
11+
DEV_DB_LIST=$(aws iam get-group --group-name ${PROJECT}-developer-${ENVIRONMENT} | jq -r '"dev_" + .Users[].UserName' | tr '\n' ' ')
912
if [[ -z "${DEV_DB_LIST}" ]]; then
1013
echo "$0: No developers available yet, skip."
1114
exit 0
@@ -20,11 +23,11 @@ if [[ $? -eq 0 ]]; then
2023
PROJECT_NAME=${PROJECT} \
2124
ENVIRONMENT=${ENVIRONMENT} \
2225
NAMESPACE=${PROJECT} \
23-
DATABASE_TYPE=<% index .Params `database` %> \
26+
DATABASE_TYPE=${DATABASE_TYPE} \
2427
DATABASE_NAME="${DEV_DB_LIST}" \
25-
SECRET_NAME=devenv${PROJECT} \
28+
SECRET_NAME=devenv-${PROJECT} \
2629
USER_NAME=dev${PROJECT} \
2730
USER_PASSWORD=${DEV_DB_SECRET} \
28-
CREATE_SECRET=secret-application.yml.tpl \
31+
CREATE_SECRET=secret-application.json.tpl \
2932
sh ./create-db-user.sh
3033
fi

0 commit comments

Comments
 (0)