Skip to content

Commit 582d42b

Browse files
committed
server readiness
1 parent 2b960d0 commit 582d42b

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@
5252
## commands
5353

5454
```bash
55-
5655
kubectl rollout restart deployment/name # to update image
5756
kubectl get ingress # ingress exposed url
58-
59-
aws eks update-kubeconfig --region ap-south-1 --name cluster
6057
kubectl exec --stdin --tty pod/postgres-0 -- /bin/bash
58+
aws eks update-kubeconfig --region ap-south-1 --name cluster
6159
```
6260

6361
## GHCR image build and push
@@ -319,4 +317,4 @@ go-todo-api-hpa Deployment/go-todo-api 23%/30% 1 10 3
319317
go-todo-api-hpa Deployment/go-todo-api 20%/30% 1 10 3 52m
320318
go-todo-api-hpa Deployment/go-todo-api 8%/30% 1 10 3 53m
321319
go-todo-api-hpa Deployment/go-todo-api 0%/30% 1 10 3 53m
322-
```
320+
```

database/database.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ import (
88
"log"
99
)
1010

11-
var database_ready = false
1211
var Connection *pg.DB
1312

1413
func IsDtabaseReady() bool {
15-
return database_ready
14+
ctx := Connection.Context()
15+
var version string
16+
17+
_, err := Connection.QueryOneContext(ctx, pg.Scan(&version), "SELECT version()")
18+
if err != nil {
19+
log.Printf("Failed to connect to database")
20+
return false
21+
}
22+
return true
1623
}
1724

1825
func GetDatabase() **pg.DB {
@@ -49,7 +56,7 @@ func Connect() *pg.DB {
4956
}
5057

5158
log.Printf("Connected to db")
52-
database_ready = true
59+
5360
return Connection
5461
}
5562

k8s-deployments/deployment.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ spec:
1515
spec: # Spec for the container which will run in the Pod
1616
imagePullSecrets:
1717
- name: dockerconfigjson-github-com
18+
# initContainers:
19+
# - name: check-db-ready
20+
# image: postgres:latest
21+
# command: ['sh', '-c',
22+
# 'until pg_isready -h $DB_HOST -p $DB_PORT;
23+
# do echo waiting for database; sleep 2; done;']
24+
# envFrom:
25+
# - secretRef:
26+
# name: app-secret
1827
containers:
1928
- name: go-todo-api
2029
image: ghcr.io/harshsinghvi/golang-postgres-kubernetes:latest

0 commit comments

Comments
 (0)