Skip to content

Commit

Permalink
configurable healthcheck hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
erulabs committed Jun 18, 2024
1 parent fbafab7 commit eae8764
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/buckit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions k8s/prod/buckit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eae8764

Please sign in to comment.