Skip to content

Commit daedba1

Browse files
authored
Merge pull request #6 from bramlak/refactor/server
Refactor/server
2 parents 1dde840 + 7d4e712 commit daedba1

File tree

6 files changed

+24
-37
lines changed

6 files changed

+24
-37
lines changed

kubernetes/deployment.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ spec:
1818
- name: server
1919
image: bramlak/origoss-task-server:latest
2020
imagePullPolicy: Always
21+
env:
22+
- name: PORT
23+
value: "8080"
2124
ports:
2225
- containerPort: 8080
2326
resources:
@@ -30,13 +33,8 @@ spec:
3033

3134
livenessProbe:
3235
httpGet:
33-
path: /
36+
path: /healthz
3437
port: 8080
3538
initialDelaySeconds: 10
3639
periodSeconds: 10
37-
readinessProbe:
38-
httpGet:
39-
path: /
40-
port: 8080
41-
initialDelaySeconds: 5
42-
periodSeconds: 5
40+

minikube-infra/deployment.tf

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ resource "kubernetes_deployment" "origoss_task_server" {
2828
image = var.image
2929
name = "server"
3030
image_pull_policy = "Always"
31+
env {
32+
name = "PORT"
33+
value = "8080"
34+
}
3135

3236
port {
3337
container_port = 8080
@@ -46,21 +50,12 @@ resource "kubernetes_deployment" "origoss_task_server" {
4650

4751
liveness_probe {
4852
http_get {
49-
path = "/"
53+
path = "/healthz"
5054
port = 8080
5155
}
5256
initial_delay_seconds = 10
5357
period_seconds = 10
5458
}
55-
56-
readiness_probe {
57-
http_get {
58-
path = "/"
59-
port = 8080
60-
}
61-
initial_delay_seconds = 5
62-
period_seconds = 5
63-
}
6459
}
6560
}
6661
}

server/.env.example

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module server
22

33
go 1.25.4
4-
5-
require github.com/joho/godotenv v1.5.1

server/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
2-
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

server/main.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"io"
66
"net/http"
77
"os"
8-
"github.com/joho/godotenv"
98
"log"
109
)
1110

@@ -15,25 +14,25 @@ func getRoot(w http.ResponseWriter, r *http.Request) {
1514
io.WriteString(w, message)
1615
}
1716

18-
func loadPortFromEnvFile() string {
19-
err := godotenv.Load()
20-
port := ""
21-
if err != nil {
22-
log.Println("Error loading .env file: ", err)
23-
} else {
24-
port = os.Getenv("PORT")
25-
}
26-
if port == ""{
27-
port = "8080"
28-
log.Println("Using default port 8080")
29-
}
17+
func getHealth(w http.ResponseWriter, r *http.Request) {
18+
w.WriteHeader(http.StatusOK)
19+
log.Println("Health check requested")
20+
}
21+
3022

31-
return port
23+
func loadPort() string {
24+
port := os.Getenv("PORT")
25+
if port == "" {
26+
port = "8080"
27+
log.Println("Using default port 8080")
28+
}
29+
return port
3230
}
3331

3432
func main() {
35-
var port string = loadPortFromEnvFile();
33+
var port string = loadPort();
3634
http.HandleFunc("/", getRoot)
35+
http.HandleFunc("/healthz", getHealth)
3736
address := net.JoinHostPort("", port)
3837
log.Println("Server is running on port", port)
3938
http.ListenAndServe(address, nil)

0 commit comments

Comments
 (0)