Skip to content

Commit

Permalink
server readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
harshsinghvi committed Nov 17, 2023
1 parent 2b960d0 commit 582d42b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@
## commands

```bash

kubectl rollout restart deployment/name # to update image
kubectl get ingress # ingress exposed url

aws eks update-kubeconfig --region ap-south-1 --name cluster
kubectl exec --stdin --tty pod/postgres-0 -- /bin/bash
aws eks update-kubeconfig --region ap-south-1 --name cluster
```

## GHCR image build and push
Expand Down Expand Up @@ -319,4 +317,4 @@ go-todo-api-hpa Deployment/go-todo-api 23%/30% 1 10 3
go-todo-api-hpa Deployment/go-todo-api 20%/30% 1 10 3 52m
go-todo-api-hpa Deployment/go-todo-api 8%/30% 1 10 3 53m
go-todo-api-hpa Deployment/go-todo-api 0%/30% 1 10 3 53m
```
```
13 changes: 10 additions & 3 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import (
"log"
)

var database_ready = false
var Connection *pg.DB

func IsDtabaseReady() bool {
return database_ready
ctx := Connection.Context()
var version string

_, err := Connection.QueryOneContext(ctx, pg.Scan(&version), "SELECT version()")
if err != nil {
log.Printf("Failed to connect to database")
return false
}
return true
}

func GetDatabase() **pg.DB {
Expand Down Expand Up @@ -49,7 +56,7 @@ func Connect() *pg.DB {
}

log.Printf("Connected to db")
database_ready = true

return Connection
}

Expand Down
9 changes: 9 additions & 0 deletions k8s-deployments/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ spec:
spec: # Spec for the container which will run in the Pod
imagePullSecrets:
- name: dockerconfigjson-github-com
# initContainers:
# - name: check-db-ready
# image: postgres:latest
# command: ['sh', '-c',
# 'until pg_isready -h $DB_HOST -p $DB_PORT;
# do echo waiting for database; sleep 2; done;']
# envFrom:
# - secretRef:
# name: app-secret
containers:
- name: go-todo-api
image: ghcr.io/harshsinghvi/golang-postgres-kubernetes:latest
Expand Down

0 comments on commit 582d42b

Please sign in to comment.