Skip to content

Commit

Permalink
feat(sidecar): added sidecar readiness probe
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Jun 17, 2021
1 parent b395ffe commit 04fe2f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/v1alpha1/step_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func (in Step) GetPodSpec(req GetPodSpecReq) corev1.PodSpec {
Ports: []corev1.ContainerPort{
{ContainerPort: 3569},
},
ReadinessProbe: &corev1.Probe{
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{Path: "/ready", Port: intstr.FromInt(3569)},
},
},
Lifecycle: &corev1.Lifecycle{
PreStop: &corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/step_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func TestStep_GetPodSpec(t *testing.T) {
Ports: []corev1.ContainerPort{{ContainerPort: 3569}},
Resources: SmallResourceRequirements,
VolumeMounts: mounts,
ReadinessProbe: &corev1.Probe{
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{Path: "/ready", Port: intstr.FromInt(3569)},
},
},
},
{
Args: []string{"cat"},
Expand Down
12 changes: 11 additions & 1 deletion runner/sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
namespace = os.Getenv(dfv1.EnvNamespace)
step = dfv1.Step{} // this is updated on start, and then periodically as we update the status
lastStep = dfv1.Step{}
ready = false // we are ready to serve HTTP requests, also updates pod status condition
)

func Exec(ctx context.Context) error {
Expand Down Expand Up @@ -87,6 +88,13 @@ func Exec(ctx context.Context) error {
}

http.Handle("/metrics", promhttp.Handler())
http.HandleFunc("/ready", func(w http.ResponseWriter, r *http.Request) {
if ready {
w.WriteHeader(200)
} else {
w.WriteHeader(503)
}
})

if leadReplica() {
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Expand Down Expand Up @@ -128,8 +136,10 @@ func Exec(ctx context.Context) error {

go wait.JitterUntil(func() { patchStepStatus(ctx) }, updateInterval, 1.2, true, ctx.Done())

ready = true
logger.Info("ready")
<-ctx.Done()
ready = false
logger.Info("done")
return nil
}
Expand Down Expand Up @@ -161,7 +171,7 @@ func patchStepStatus(ctx context.Context) {
v.Status.SourceStatuses = dfv1.SourceStatuses{}
}
if v.Status.SinkStatues == nil {
v.Status.SourceStatuses = dfv1.SourceStatuses{}
v.Status.SinkStatues = dfv1.SourceStatuses{}
}
step = v
lastStep = *v.DeepCopy()
Expand Down

0 comments on commit 04fe2f8

Please sign in to comment.