From 701b43a22a2c5d99c95c15a0ed9c09f1a8d83f88 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Sun, 17 Mar 2024 21:44:55 -0500 Subject: [PATCH] healthz --- hello-world/Dockerfile | 1 + hello-world/app.py | 86 ++++++++++++++++++++++++- hello-world/deployments/deployment.yaml | 4 ++ rollouts-app/rollouts.yaml | 6 -- 4 files changed, 89 insertions(+), 8 deletions(-) diff --git a/hello-world/Dockerfile b/hello-world/Dockerfile index 0e7e56a..42b49dc 100644 --- a/hello-world/Dockerfile +++ b/hello-world/Dockerfile @@ -4,5 +4,6 @@ WORKDIR /app COPY hello-world/app.py . ENV FLASK_APP=app.py ENV FLASK_RUN_HOST=0.0.0.0 +HEALTHCHECK CMD curl --fail http://localhost:5000/healthz || exit 1 CMD ["flask", "run"] diff --git a/hello-world/app.py b/hello-world/app.py index 0bbe140..35a8868 100644 --- a/hello-world/app.py +++ b/hello-world/app.py @@ -1,8 +1,90 @@ -from flask import Flask +from pathlib import Path + +from flask import Flask, request app = Flask(__name__) +LIVE = Path("livez") +LIVE.write_text("ok") + @app.route("/") def hello_world(): - return "Hello, V2" + version = "v3" + if "5000" in request.base_url: + mode = "local" + header_color = "#a0dfa0" + elif "30001" in request.base_url: + mode = "active" + header_color = "#a0c0df" + elif "30002" in request.base_url: + mode = "preview" + header_color = "#dfa0df" + else: + mode = "unknown" + header_color = "#dfc0a0" + import time + + LIVE.write_text("no") + time.sleep(10) + LIVE.write_text("ok") + + return f""" + + + {mode}: Hello, World! + + + + +
+

{mode}: Hello, World! {version}

+
+
+

Hello, World!

+

Mode: {mode}

+

Version: {version}

+
+ + +""" + + +@app.route("/healthz") +def healthz(): + # return "failed", 500 + return "I'm still here.", 200 + + +@app.route("/livez") +def livez(): + if LIVE.read_text() == "ok": + return "All done working here." + return "I'm working here!", 500 diff --git a/hello-world/deployments/deployment.yaml b/hello-world/deployments/deployment.yaml index 5b80135..5d76da0 100644 --- a/hello-world/deployments/deployment.yaml +++ b/hello-world/deployments/deployment.yaml @@ -31,6 +31,10 @@ spec: image: docker.io/waylonwalker/learn-rollouts:v1 ports: - containerPort: 5000 + livenessProbe: + httpGet: + path: /-/healthz + port: 5000 strategy: blueGreen: # activeService specifies the service to update with the new template hash at time of promotion. diff --git a/rollouts-app/rollouts.yaml b/rollouts-app/rollouts.yaml index 6fd6543..289428b 100644 --- a/rollouts-app/rollouts.yaml +++ b/rollouts-app/rollouts.yaml @@ -1,9 +1,3 @@ -# create argo-rollouts namespace -apiVersion: v1 -kind: Namespace -metadata: - name: argo-rollouts - # This is an auto-generated file. DO NOT EDIT apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition