Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.

Commit b67739c

Browse files
committed
Remove terminating pods from endpoints
The standard endpoint controller removes, by default, terminating pods from an endpoint: kubernetes/kubernetes@2aaf8bd#diff-a1a9c0efe93384ed9a010e65e8ad4604R316 This behaviour let the service clients time to react to stop sending traffic to the terminating pods while finishing processing current requests, as pods in "terminating" state are technically still able to accept connections and handle requests. It allows to smoothly replace the pods by the activator when all pods are entering the terminating state, for the reason described above.
1 parent 2bf13af commit b67739c

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

pkg/endpoints/controller/endpoints_manager.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"encoding/json"
77
"fmt"
8+
"strconv"
89
"sync"
910

1011
"github.com/deislabs/osiris/pkg/kubernetes"
@@ -18,6 +19,23 @@ import (
1819
endpointsv1 "k8s.io/kubernetes/pkg/api/v1/endpoints"
1920
)
2021

22+
const (
23+
24+
// TolerateUnreadyEndpointsAnnotation is an annotation on the Service denoting if the endpoints
25+
// controller should go ahead and create endpoints for unready pods. This annotation is
26+
// currently only used by StatefulSets, where we need the pod to be DNS
27+
// resolvable during initialization and termination. In this situation we
28+
// create a headless Service just for the StatefulSet, and clients shouldn't
29+
// be using this Service for anything so unready endpoints don't matter.
30+
// Endpoints of these Services retain their DNS records and continue
31+
// receiving traffic for the Service from the moment the kubelet starts all
32+
// containers in the pod and marks it "Running", till the kubelet stops all
33+
// containers and deletes the pod from the apiserver.
34+
// This field is deprecated. v1.Service.PublishNotReadyAddresses will replace it
35+
// subsequent releases. It will be removed no sooner than 1.13.
36+
TolerateUnreadyEndpointsAnnotation = "service.alpha.kubernetes.io/tolerate-unready-endpoints"
37+
)
38+
2139
// endpointsManager is a controller responsible for the on-going management of
2240
// the endpoints resource corresponding to a single Osiris-enabled service
2341
type endpointsManager struct {
@@ -127,6 +145,27 @@ func (e *endpointsManager) syncAppPod(obj interface{}) {
127145
break
128146
}
129147
}
148+
149+
// If the user specified the older (deprecated) annotation,
150+
// we have to respect it.
151+
tolerateUnreadyEndpoints := e.service.Spec.PublishNotReadyAddresses
152+
v, ok := e.service.Annotations[TolerateUnreadyEndpointsAnnotation]
153+
if ok {
154+
b, err := strconv.ParseBool(v)
155+
if err == nil {
156+
tolerateUnreadyEndpoints = b
157+
} else {
158+
glog.Errorf(
159+
"Failed to parse annotation %v: %v",
160+
TolerateUnreadyEndpointsAnnotation,
161+
err,
162+
)
163+
}
164+
}
165+
166+
if !tolerateUnreadyEndpoints && pod.DeletionTimestamp != nil {
167+
ready = false
168+
}
130169
glog.Infof(
131170
"Informed about pod %s for service %s in namespace %s; its IP is %s and "+
132171
"its ready condition is %t",

0 commit comments

Comments
 (0)