Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTSPO-18332 - Simplify onboarding to persistent preview databases #5892

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions bin/v2/postgres-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
# set -ex

NAMESPACE='${NAMESPACE}'
ENVIRONMENT='${ENVIRONMENT}'
NAMESPACE_NAME="$1"
APP_NAME="$2"
APPS_DIR="../../apps/"
CLUSTERS_DIR="../../clusters"

PASSWORD=$(openssl rand -base64 15)

function usage() {
echo 'usage: ./postgres-setup.sh <namespace> <app_name>'
}

if [ -z "${NAMESPACE_NAME}" ] || [ -z "${APP_NAME}" ]; then
usage
exit 1
fi

if [ ! -f "apps/$NAMESPACE_NAME/preview/aso" ]; then
echo "Creating aso"
mkdir -p apps/$NAMESPACE_NAME
mkdir -p apps/$NAMESPACE_NAME/preview
mkdir -p apps/$NAMESPACE_NAME/preview/aso

(
cat <<EOF
apiVersion: dbforpostgresql.azure.com/v1api20210601
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this and not v1?

kind: FlexibleServersConfiguration
metadata:
name: extensions
namespace: ${NAMESPACE}
annotations:
serviceoperator.azure.com/reconcile-policy: detach-on-delete
spec:
owner:
name: ${NAMESPACE}-${ENVIRONMENT}
azureName: azure.extensions
source: user-override
value: "btree_gin"
EOF
) >"apps/$NAMESPACE_NAME/preview/aso/$NAMESPACE_NAME-postgres-config.yaml"

(
cat <<EOF
apiVersion: dbforpostgresql.azure.com/v1api20210601
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

kind: FlexibleServer
metadata:
name: ${NAMESPACE}-${ENVIRONMENT}
namespace: ${NAMESPACE}
spec:
version: "14"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why only version 14?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would version 16 be more suitable @thomast1906?

network:
delegatedSubnetResourceReference:
armId: /subscriptions/8b6ea922-0862-443e-af15-6056e1c9b9a4/resourceGroups/cft-preview-network-rg/providers/Microsoft.Network/virtualNetworks/cft-preview-vnet/subnets/postgresql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cft?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops should be sds, changing now

privateDnsZoneArmResourceReference:
armId: /subscriptions/1baf5470-1c3e-40d3-a6f7-74bfbce4b348/resourceGroups/core-infra-intsvc-rg/providers/Microsoft.Network/privateDnsZones/privatelink.postgres.database.azure.com
EOF
) >"apps/$NAMESPACE_NAME/preview/aso/$NAMESPACE_NAME-postgres.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preview?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to dev locally, will push in a sec once i correct the other above changes

fi

if [ ! -f "apps/$NAMESPACE_NAME/preview/sops-secrets" ]; then
echo "Creating sops-secrets"
mkdir -p apps/$NAMESPACE_NAME
mkdir -p apps/$NAMESPACE_NAME/preview
mkdir -p apps/$NAMESPACE_NAME/preview/sops-secrets
fi

(
cat <<EOF
apiVersion: v1
data:
PASSWORD: $PASSWORD
kind: Secret
metadata:
creationTimestamp: null
name: postgres
namespace: $NAMESPACE_NAME
type: Opaque
EOF
) >"apps/$NAMESPACE_NAME/preview/sops-secrets/$APP_NAME-values.enc.yaml"

if ! [ -f /usr/local/bin/sops ]; then
echo "Sops is not installed... installing..."
curl -LO https://github.com/getsops/sops/releases/download/v3.9.1/sops-v3.9.1.darwin.amd64
mv sops-v3.9.1.darwin.amd64 /usr/local/bin/sops
chmod +x /usr/local/bin/sops
fi

sops --encrypt --azure-kv https://dcdcftappsdevkv.vault.azure.net/keys/sops-key/aedb9ea38954430ca1d0a46ed589c049 --encrypted-regex "^(data|stringData)$" --in-place apps/$NAMESPACE_NAME/preview/sops-secrets/$APP_NAME-values.enc.yaml

(
cat <<EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- $APP_NAME-postgres.enc.yaml
namespace: $NAMESPACE_NAME
EOF
) >"apps/$NAMESPACE_NAME/preview/sops-secrets/kustomization.yaml"
Loading