From eae87641f95ef890c0303c673e886077e4a97623 Mon Sep 17 00:00:00 2001 From: Seandon Mooy Date: Tue, 18 Jun 2024 17:40:35 +0000 Subject: [PATCH] configurable healthcheck hostname --- cmd/buckit.go | 14 ++++++++++++-- k8s/prod/buckit.yaml | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/cmd/buckit.go b/cmd/buckit.go index 2cc3cd1..009d028 100644 --- a/cmd/buckit.go +++ b/cmd/buckit.go @@ -3,12 +3,14 @@ package cmd import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws/credentials" - "gocloud.dev/blob/s3blob" "log" "net/http" + "os" "time" + "github.com/aws/aws-sdk-go/aws/credentials" + "gocloud.dev/blob/s3blob" + _ "gocloud.dev/blob/s3blob" "github.com/aws/aws-sdk-go/aws" @@ -57,6 +59,14 @@ func (a *App) handlerFunc() http.HandlerFunc { http.Error(w, "method not supported", http.StatusMethodNotAllowed) return } + + // Health check handler + healthCheckHost := os.Getenv("HEALTH_CHECK_HOSTNAME") + if len(healthCheckHost) > 0 && r.Host == healthCheckHost && r.URL.Path == "/healthz" { + w.WriteHeader(http.StatusOK) + return + } + for _, b := range a.Config.Buckits { if b.HostName == r.Host { fetchResource(w, r, b) diff --git a/k8s/prod/buckit.yaml b/k8s/prod/buckit.yaml index 0cc6c43..54d039c 100644 --- a/k8s/prod/buckit.yaml +++ b/k8s/prod/buckit.yaml @@ -56,11 +56,38 @@ spec: image: 347708466071.dkr.ecr.us-east-1.amazonaws.com/classdojo/buckit imagePullPolicy: IfNotPresent env: + - name: HEALTH_CHECK_HOSTNAME + value: buckit-health-check.internal.classdojo.com - name: CONSUL_LOCAL_IP valueFrom: { fieldRef: { fieldPath: status.hostIP } } volumeMounts: - mountPath: /mnt/buckit-init name: buckit-init + readinessProbe: + failureThreshold: 2 + httpGet: + path: /healthz + port: http + scheme: HTTP + httpHeaders: + - name: Host + value: buckit-health-check.internal.classdojo.com + initialDelaySeconds: 10 + periodSeconds: 5 + livenessProbe: + failureThreshold: 2 + httpGet: + path: /healthz + port: http + scheme: HTTP + httpHeaders: + - name: Host + value: buckit-health-check.internal.classdojo.com + initialDelaySeconds: 10 + periodSeconds: 5 + httpHeaders: + - name: Host + value: buckit-health-check.internal.classdojo.com resources: limits: memory: 120Mi