Skip to content

Commit 5fbdac6

Browse files
committed
Modifying html output and periodSeconds for liveness probe
1 parent 24a468f commit 5fbdac6

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

k8s/k8s.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,48 @@ func getServerIP() string {
1919
return conn.LocalAddr().(*net.UDPAddr).IP.String()
2020
}
2121

22-
func getHTML(image string) string {
23-
message := "TechSupport, Mr. Cat speaking, how can I help you?"
22+
func getHTML(status string) string {
23+
message := "DevOps, Mr. Cat speaking, how can I help you?"
24+
image := "1.3.0"
2425
color := "orange"
25-
if image == "1.3.1" {
26+
if status == "alive" {
2627
message = "High five budy, I'm healthy as ever!"
28+
image = "1.3.1"
2729
color = "green"
2830
}
29-
if image == "1.3.2" {
30-
message = "I don't want to die Mr. Stark ( x_x ) ..."
31+
if status == "dead" {
32+
message = "I don't want to die Mr. Stark..."
33+
image = "1.3.2"
3134
color = "red"
3235
}
3336
return `<!DOCTYPE html><html><body><center>
34-
<img src="https://raw.githubusercontent.com/twogg-git/k8s-workshop/master/src/` + image + `.png">
35-
<h1 style="color:` + color + `">` + message + `</h3>
36-
<h2 style="color:green">Playing with Kubernetes</h1>
37-
<h2 style="color:blue">Server IP ` + getServerIP() + `</h2>
38-
<h3 style="color:blue">Version twogghub/k8s-workshop:1.3-liveness</h3>
39-
</center></body></html>`
37+
<img src="https://raw.githubusercontent.com/twogg-git/k8s-workshop/1.3-liveness/src/` + image + `.png">
38+
<h1 style="color:` + color + `">` + message + `</h3>
39+
<h2 style="color:green">Playing with Kubernetes</h1>
40+
<h2 style="color:blue">Server IP ` + getServerIP() + `</h2>
41+
<h3 style="color:blue">Version twogghub/k8s-workshop:1.3-liveness</h3>
42+
</center></body></html>`
4043
}
4144

4245
func playHome(w http.ResponseWriter, r *http.Request) {
43-
if getServerIP() == bannedIp {
44-
fmt.Fprintf(w, getHTML("1.3.2"))
46+
if bannedIp == getServerIP() {
47+
fmt.Fprintf(w, getHTML("dead"))
4548
} else {
46-
fmt.Fprintf(w, getHTML("1.3.0"))
49+
fmt.Fprintf(w, getHTML("home"))
4750
}
4851
}
4952

5053
func playHealth(w http.ResponseWriter, r *http.Request) {
5154
if getServerIP() == bannedIp {
5255
w.WriteHeader(http.StatusServiceUnavailable)
5356
} else {
54-
fmt.Fprintf(w, getHTML("1.3.1"))
57+
fmt.Fprintf(w, getHTML("alive"))
5558
}
5659
}
5760

5861
func playKillMe(w http.ResponseWriter, r *http.Request) {
5962
bannedIp = getServerIP()
60-
fmt.Fprintf(w, getHTML("1.3.2"))
63+
fmt.Fprintf(w, getHTML("dead"))
6164
}
6265

6366
func main() {

yamls/k8sdp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ spec:
2828
port: 8080
2929
initialDelaySeconds: 5
3030
timeoutSeconds: 1
31-
periodSeconds: 5
31+
periodSeconds: 2
3232
failureThreshold: 1
3333
ports:
3434
- name: http

0 commit comments

Comments
 (0)