Skip to content

Commit

Permalink
Rename the namespace from namespace-demo to namespace. Remove the cod…
Browse files Browse the repository at this point in the history
…e to create or delete PV, Storageclass as we will use rancher local-path dynamic profisioning. Test if postgresl folder exists. #20
  • Loading branch information
cmoulliard committed Jun 9, 2022
1 parent cc55c39 commit d721f99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 64 deletions.
75 changes: 18 additions & 57 deletions scripts/install_postgresql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# - REGISTRY_SERVER: Tanzu image registry hostname
# - REGISTRY_USERNAME: user to be used to be authenticated against the Tanzu image registry
# - REGISTRY_PASSWORD: password to be used to be authenticated against the Tanzu image registry
# - NAMESPACE_DEMO: Namespace where the postgresql instance should be created
# - NAMESPACE: Namespace where the postgresql instance should be created

set -e

Expand Down Expand Up @@ -45,7 +45,7 @@ REGISTRY_SERVER=${REGISTRY_SERVER:-registry.pivotal.io}
REGISTRY_USERNAME=${REGISTRY_USERNAME}
REGISTRY_PASSWORD=${REGISTRY_PASSWORD}

NAMESPACE_DEMO=${NAMESPACE_DEMO:-tap-demo}
NAMESPACE=${NAMESPACE:-tap-demo}

POSTGRESQL_VERSION=1.5.0
POSTGRES_API_GROUP=sql.tanzu.vmware.com
Expand All @@ -62,62 +62,23 @@ helm registry login $REGISTRY_SERVER \
--username=$REGISTRY_USERNAME \
--password=$REGISTRY_PASSWORD

helm pull oci://registry.pivotal.io/tanzu-sql-postgres/postgres-operator-chart --version v$POSTGRESQL_VERSION --untar --untardir ./postgresql

log "CYAN" "Create the secret to allow to pull images from pivotal registry within the $NAMESPACE_DEMO"
kubectl -n $NAMESPACE_DEMO create secret docker-registry regsecret --docker-server=$REGISTRY_SERVER --docker-username=$REGISTRY_USERNAME --docker-password=$REGISTRY_PASSWORD

log "CYAN" "Install the tanzu postgresql chart"
helm install tanzu-postgresql ./postgresql/postgres-operator --namespace $NAMESPACE_DEMO --wait

log "CYAN" "Create the kubernetes storageclass and needed PV"
cat << 'EOF' | kubectl apply -f -
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: standard
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv100
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
hostPath:
path: /tmp/pv100
type: ""
persistentVolumeReclaimPolicy: Recycle
volumeMode: Filesystem
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv101
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
hostPath:
path: /tmp/pv101
type: ""
persistentVolumeReclaimPolicy: Recycle
volumeMode: Filesystem
EOF

log "CYAN" "Change the permissions to 777 for the PV"
sudo mkdir -p /tmp/pv100 && sudo chmod -R 777 /tmp/pv100
sudo mkdir -p /tmp/pv101 && sudo chmod -R 777 /tmp/pv101
if [[ -d "$HOME/postgresql" ]]; then
echo "$HOME/postgresql already exists on the machine."
else
log "CYAN" "Helm pulling"
helm pull oci://registry.pivotal.io/tanzu-sql-postgres/postgres-operator-chart --version v$POSTGRESQL_VERSION --untar --untardir $HOME/postgresql
log "CYAN" "Install the tanzu postgresql chart"
helm install tanzu-postgresql $HOME/postgresql/postgres-operator --namespace $NAMESPACE --wait
fi

log "CYAN" "Create the secret to allow to pull images from pivotal registry within the $NAMESPACE"
kubectl -n $NAMESPACE create secret docker-registry regsecret \
--docker-server=$REGISTRY_SERVER \
--docker-username=$REGISTRY_USERNAME \
--docker-password=$REGISTRY_PASSWORD

log "CYAN" "Create an instance of the postgres DB"
cat << 'EOF' | kubectl apply -n $NAMESPACE_DEMO -f -
cat << 'EOF' | kubectl apply -n $NAMESPACE -f -
apiVersion: sql.tanzu.vmware.com/v1
kind: Postgres
metadata:
Expand All @@ -126,7 +87,7 @@ spec:
storageSize: 800M
cpu: "0.8"
memory: 800Mi
monitorStorageClassName: standard
monitorStorageClassName: local-path
monitorStorageSize: 1G
resources:
monitor:
Expand Down
7 changes: 0 additions & 7 deletions scripts/uninstall_postgresql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ kubectl -n $NAMESPACE_DEMO delete secret regsecret --ignore-not-found
log "YELLOW" "Delete the postgresql instance"
kubectl delete Postgres/postgres-db -n $NAMESPACE_DEMO --ignore-not-found

log "YELLOW" "Delete the PV100, PV101"
kubectl delete pv/pv100 --ignore-not-found
kubectl delete pv/pv101 --ignore-not-found
kubectl delete sc/standard --ignore-not-found

log "YELLOW" "Uninstalling the Helm chart of postgresql"
helm uninstall tanzu-postgresql -n $NAMESPACE_DEMO
if [ $? -eq 0 ]; then
Expand All @@ -61,8 +56,6 @@ fi

log "YELLOW" "Removing the installation folder of posgresql & pv100, pv101"
rm -rf $HOME/postgresql
sudo rm -rf /tmp/pv100
sudo rm -rf /tmp/pv101

log "YELLOW" "Removing RBAC"
kubectl delete ClusterRoleBinding/postgres-operator-cluster-role-binding
Expand Down

0 comments on commit d721f99

Please sign in to comment.