From 3d1fb5a77fa7d39ac3e5106593b474fa06bf803b Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Thu, 18 Jun 2020 21:54:48 +0900 Subject: [PATCH] Graceful shutdown (#80) (#3) * Change readiness probe and define preStop lifecycle hook * Use the admin endpoint as the readiness probe * Increase the amount of retries for the make local-setup scripts * Reduce the amount of readyness checks Co-authored-by: Joaquim Moreno Prusi --- deploy/kourier-knative.yaml | 12 ++++++++---- pkg/generator/status_vhost.go | 16 ++++++++++------ utils/setup.sh | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/deploy/kourier-knative.yaml b/deploy/kourier-knative.yaml index be9c2d895..71047574b 100644 --- a/deploy/kourier-knative.yaml +++ b/deploy/kourier-knative.yaml @@ -103,7 +103,7 @@ spec: - /tmp/config/envoy-bootstrap.yaml command: - /usr/local/bin/envoy - image: docker.io/maistra/proxyv2-ubi8:1.0.8 + image: docker.io/maistra/proxyv2-ubi8:1.1.0 imagePullPolicy: Always name: kourier-gateway ports: @@ -116,16 +116,20 @@ spec: volumeMounts: - name: config-volume mountPath: /tmp/config + lifecycle: + preStop: + exec: + command: ["curl","-X","POST","--unix","/tmp/envoy.admin","http://localhost/healthcheck/fail"] readinessProbe: httpGet: httpHeaders: - name: Host value: internalkourier - path: /__internalkouriersnapshot + path: /ready port: 8081 scheme: HTTP - initialDelaySeconds: 5 - periodSeconds: 2 + initialDelaySeconds: 10 + periodSeconds: 5 volumes: - name: config-volume configMap: diff --git a/pkg/generator/status_vhost.go b/pkg/generator/status_vhost.go index db041cc50..cddd2a0bf 100644 --- a/pkg/generator/status_vhost.go +++ b/pkg/generator/status_vhost.go @@ -17,6 +17,8 @@ limitations under the License. package generator import ( + "time" + "knative.dev/net-kourier/pkg/config" "knative.dev/net-kourier/pkg/envoy" @@ -29,13 +31,15 @@ func statusVHost() route.VirtualHost { return envoy.NewVirtualHost( config.InternalKourierDomain, []string{config.InternalKourierDomain}, - []*route.Route{statusRoute()}, + []*route.Route{readyRoute()}, ) } -func statusRoute() *route.Route { - return envoy.NewRouteStatusOK( - config.InternalKourierDomain, - config.InternalKourierPath, - ) +func readyRoute() *route.Route { + cluster := envoy.NewWeightedCluster("service_stats", 100, map[string]string{}) + var wrs []*route.WeightedCluster_ClusterWeight + wrs = append(wrs, cluster) + route := envoy.NewRoute("gateway_ready", "/ready", wrs, 1*time.Second, 0, 5*time.Second, map[string]string{}) + + return route } diff --git a/utils/setup.sh b/utils/setup.sh index ec36902e7..80f6c02d9 100755 --- a/utils/setup.sh +++ b/utils/setup.sh @@ -53,7 +53,7 @@ retries=0 while [[ $(kubectl get pods -n ${KOURIER_NAMESPACE} -l app=3scale-kourier-gateway -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "Waiting for kourier gateway pod to be ready " sleep 10 - if [ $retries -ge 7 ]; then + if [ $retries -ge 10 ]; then echo "timedout waiting for kourier gateway pod" exit 1 fi