Skip to content

Commit 3d5feb3

Browse files
committed
Merge pull request #149 from arschles/probes
fix(*): add readiness & liveness probes
2 parents f669c77 + 958e0b1 commit 3d5feb3

19 files changed

Lines changed: 510 additions & 53 deletions

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ RC := manifests/deis-${SHORT_NAME}-rc.yaml
2727
SVC := manifests/deis-${SHORT_NAME}-service.yaml
2828
IMAGE := ${DEIS_REGISTRY}${IMAGE_PREFIX}/${SHORT_NAME}:${VERSION}
2929

30-
TEST_PACKAGES := $(shell ${DEV_ENV_CMD} glide nv)
31-
3230
all:
3331
@echo "Use a Makefile to control top-level building of the project."
3432

@@ -46,7 +44,7 @@ build:
4644
@$(call check-static-binary,$(BINARY_DEST_DIR)/boot)
4745

4846
test:
49-
${DEV_ENV_CMD} go test ${TEST_PACKAGES}
47+
${DEV_ENV_CMD} sh -c 'go test $$(glide nv)'
5048

5149
docker-build:
5250
docker build --rm -t ${IMAGE} rootfs

boot.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"log"
45
"os"
56
"runtime"
67

@@ -9,8 +10,11 @@ import (
910
"github.com/deis/builder/pkg"
1011
"github.com/deis/builder/pkg/conf"
1112
"github.com/deis/builder/pkg/gitreceive"
13+
"github.com/deis/builder/pkg/gitreceive/storage"
14+
"github.com/deis/builder/pkg/healthsrv"
1215
"github.com/deis/builder/pkg/sshd"
1316
pkglog "github.com/deis/pkg/log"
17+
kcl "k8s.io/kubernetes/pkg/client/unversioned"
1418
)
1519

1620
const (
@@ -26,8 +30,8 @@ func main() {
2630
if os.Getenv("DEBUG") == "true" {
2731
pkglog.DefaultLogger.SetDebug(true)
2832
cookoolog.Level = cookoolog.LogDebug
33+
log.Printf("Running in debug mode")
2934
}
30-
pkglog.Debug("Running in debug mode")
3135

3236
app := cli.NewApp()
3337

@@ -42,8 +46,40 @@ func main() {
4246
pkglog.Err("getting config for %s [%s]", serverConfAppName, err)
4347
os.Exit(1)
4448
}
45-
pkglog.Info("starting SSH server on %s:%d", cnf.SSHHostIP, cnf.SSHHostPort)
46-
os.Exit(pkg.Run(cnf.SSHHostIP, cnf.SSHHostPort, "boot"))
49+
circ := sshd.NewCircuit()
50+
51+
s3Client, err := storage.GetClient(cnf.HealthSrvTestStorageRegion)
52+
if err != nil {
53+
log.Printf("Error getting s3 client (%s)", err)
54+
os.Exit(1)
55+
}
56+
kubeClient, err := kcl.NewInCluster()
57+
if err != nil {
58+
log.Printf("Error getting kubernetes client [%s]", err)
59+
os.Exit(1)
60+
}
61+
log.Printf("Starting health check server on port %d", cnf.HealthSrvPort)
62+
healthSrvCh := make(chan error)
63+
go func() {
64+
if err := healthsrv.Start(cnf.HealthSrvPort, kubeClient.Namespaces(), s3Client, circ); err != nil {
65+
healthSrvCh <- err
66+
}
67+
}()
68+
69+
log.Printf("Starting SSH server on %s:%d", cnf.SSHHostIP, cnf.SSHHostPort)
70+
sshCh := make(chan int)
71+
go func() {
72+
sshCh <- pkg.RunBuilder(cnf.SSHHostIP, cnf.SSHHostPort, circ)
73+
}()
74+
75+
select {
76+
case err := <-healthSrvCh:
77+
log.Printf("Error running health server (%s)", err)
78+
os.Exit(1)
79+
case i := <-sshCh:
80+
log.Printf("Unexpected SSH server stop with code %d", i)
81+
os.Exit(i)
82+
}
4783
},
4884
},
4985
{
@@ -53,13 +89,13 @@ func main() {
5389
Action: func(c *cli.Context) {
5490
cnf := new(gitreceive.Config)
5591
if err := conf.EnvConfig(gitReceiveConfAppName, cnf); err != nil {
56-
pkglog.Err("Error getting config for %s [%s]", gitReceiveConfAppName, err)
92+
log.Printf("Error getting config for %s [%s]", gitReceiveConfAppName, err)
5793
os.Exit(1)
5894
}
5995
cnf.CheckDurations()
6096

6197
if err := gitreceive.Run(cnf); err != nil {
62-
pkglog.Err("running git receive hook [%s]", err)
98+
log.Printf("Error running git receive hook [%s]", err)
6399
os.Exit(1)
64100
}
65101
},

glide.lock

Lines changed: 19 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import:
2222
version: eca94c41d994ae2215d455ce578ae6e2dc6ee516
2323
- package: github.com/pborman/uuid
2424
- package: github.com/deis/pkg
25+
version: b8679a4d7fe2fe0393c66c620eff7df86c9f7982
2526
subpackages:
2627
- time
2728
- log
@@ -35,3 +36,5 @@ import:
3536
- service/s3
3637
- package: k8s.io/kubernetes
3738
version: ~1.1
39+
- package: github.com/arschles/assert
40+
version: 6882f85ccdc7c1822b146d1a6b0c2c48f91b5140

manifests/deis-builder-rc.yaml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: v1
22
kind: ReplicationController
33
metadata:
44
name: deis-builder
5+
namespace: deis
56
labels:
67
heritage: deis
78
spec:
@@ -15,43 +16,50 @@ spec:
1516
spec:
1617
containers:
1718
- name: deis-builder
18-
imagePullPolicy: Always
1919
image: quay.io/deisci/builder:v2-beta
20+
imagePullPolicy: Always
2021
ports:
2122
- containerPort: 2223
22-
- containerPort: 3000
23+
name: ssh
24+
- containerPort: 8092
25+
name: healthsrv
2326
env:
24-
- name: BUILDER_FETCHER_PORT
25-
value: "3000"
26-
- name: BUILDER_SSH_HOST_IP
27-
value: "0.0.0.0"
28-
- name: BUILDER_SSH_HOST_PORT
29-
value: "2223"
27+
- name: "HEALTH_SERVER_PORT"
28+
value: "8092"
3029
- name: "EXTERNAL_PORT"
3130
value: "2223"
32-
- name: POD_NAMESPACE
31+
# This var needs to be passed so that the minio client (https://github.com/minio/mc) will work in Alpine linux
32+
- name: "DOCKERIMAGE"
33+
value: "1"
34+
- name: "DEBUG"
35+
value: "true"
36+
- name: "POD_NAMESPACE"
3337
valueFrom:
3438
fieldRef:
3539
fieldPath: metadata.namespace
40+
livenessProbe:
41+
httpGet:
42+
path: /healthz
43+
port: 8092
44+
initialDelaySeconds: 2
45+
timeoutSeconds: 1
46+
readinessProbe:
47+
httpGet:
48+
path: /healthz
49+
port: 8092
50+
initialDelaySeconds: 2
51+
timeoutSeconds: 1
3652
volumeMounts:
3753
- name: minio-user
3854
mountPath: /var/run/secrets/object/store
3955
readOnly: true
4056
- name: builder-key-auth
4157
mountPath: /var/run/secrets/api/auth
4258
readOnly: true
43-
# not currently running minio with SSL support. see https://github.com/deis/minio/pull/22 for more detail
44-
# - name: minio-ssl
45-
# mountPath: /var/run/secrets/object/ssl
46-
# readOnly: true
4759
volumes:
4860
- name: minio-user
4961
secret:
5062
secretName: minio-user
5163
- name: builder-key-auth
5264
secret:
5365
secretName: builder-key-auth
54-
# not currently running minio with SSL support. see https://github.com/deis/minio/pull/22 for more detail
55-
# - name: minio-ssl
56-
# secret:
57-
# secretName: minio-ssl

manifests/deis-builder-service.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
name: deis-builder
5+
namespace: deis
56
labels:
67
heritage: deis
7-
release: 2.0.0
88
spec:
99
ports:
10-
- port: 2222
10+
- name: ssh
11+
port: 2222
1112
targetPort: 2223
12-
name: ssh
13-
protocol: TCP
14-
- port: 3000
15-
name: fetcher
16-
protocol: TCP
1713
selector:
1814
app: deis-builder

pkg/builder.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ package pkg
55

66
import (
77
"fmt"
8+
"log"
9+
"os"
810

911
"github.com/Masterminds/cookoo"
1012
clog "github.com/Masterminds/cookoo/log"
1113
"github.com/deis/builder/pkg/sshd"
12-
13-
"log"
14-
"os"
1514
)
1615

1716
// Return codes that will be sent to the shell.
@@ -28,7 +27,7 @@ const (
2827
// Git.
2928
//
3029
// Run returns on of the Status* status code constants.
31-
func Run(sshHostIP string, sshHostPort int, cmd string) int {
30+
func RunBuilder(sshHostIP string, sshHostPort int, sshServerCircuit *sshd.Circuit) int {
3231
reg, router, ocxt := cookoo.Cookoo()
3332
log.SetFlags(0) // Time is captured elsewhere.
3433

@@ -59,7 +58,7 @@ func Run(sshHostIP string, sshHostPort int, cmd string) int {
5958
// Start the SSH service.
6059
// TODO: We could refactor Serve to be a command, and then run this as
6160
// a route.
62-
if err := sshd.Serve(reg, router, cxt); err != nil {
61+
if err := sshd.Serve(reg, router, sshServerCircuit, cxt); err != nil {
6362
clog.Errf(cxt, "SSH server failed: %s", err)
6463
return StatusLocalError
6564
}

0 commit comments

Comments
 (0)