Skip to content

Commit 19d1043

Browse files
committed
Wire up persistent-drainable annotation.
This currently behaves exactly like `persistent` after this commit.
1 parent e77e082 commit 19d1043

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

internal/ingress/annotations/annotations_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func TestAffinitySession(t *testing.T) {
197197
}{
198198
{map[string]string{annotationAffinityType: "cookie", annotationAffinityMode: "balanced", annotationAffinityCookieName: "route", annotationAffinityCanaryBehavior: ""}, "cookie", "balanced", "route", ""},
199199
{map[string]string{annotationAffinityType: "cookie", annotationAffinityMode: "persistent", annotationAffinityCookieName: "route1", annotationAffinityCanaryBehavior: "sticky"}, "cookie", "persistent", "route1", "sticky"},
200+
{map[string]string{annotationAffinityType: "cookie", annotationAffinityMode: "persistent-drainable", annotationAffinityCookieName: "route1", annotationAffinityCanaryBehavior: "sticky"}, "cookie", "persistent-drainable", "route1", "sticky"},
200201
{map[string]string{annotationAffinityType: "cookie", annotationAffinityMode: "balanced", annotationAffinityCookieName: "", annotationAffinityCanaryBehavior: "legacy"}, "cookie", "balanced", "INGRESSCOOKIE", "legacy"},
201202
{map[string]string{}, "", "", "", ""},
202203
{nil, "", "", "", ""},

internal/ingress/annotations/sessionaffinity/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ var sessionAffinityAnnotations = parser.Annotation{
7777
Documentation: `This annotation enables and sets the affinity type in all Upstreams of an Ingress. This way, a request will always be directed to the same upstream server. The only affinity type available for NGINX is cookie`,
7878
},
7979
annotationAffinityMode: {
80-
Validator: parser.ValidateOptions([]string{"balanced", "persistent"}, true, true),
80+
Validator: parser.ValidateOptions([]string{"balanced", "persistent", "persistent-drainable"}, true, true),
8181
Scope: parser.AnnotationScopeIngress,
8282
Risk: parser.AnnotationRiskMedium,
8383
Documentation: `This annotation defines the stickiness of a session.
8484
Setting this to balanced (default) will redistribute some sessions if a deployment gets scaled up, therefore rebalancing the load on the servers.
85-
Setting this to persistent will not rebalance sessions to new servers, therefore providing maximum stickiness.`,
85+
Setting this to persistent will not rebalance sessions to new servers, therefore providing greater stickiness. Sticky sessions will continue to be routed to the same server as long as its Endpoint's condition remains Ready. If the Endpoint stops being Ready, such when a server pod receives a deletion timestamp, sessions will be rebalanced to another server.
86+
Setting this to persistent-drainable behaves like persistent, but sticky sessions will continue to be routed to the same server as long as its Endpoint's condition remains Serving, even after the server pod receives a deletion timestamp. This allows graceful session draining during the preStop lifecycle hook. New sessions will *not* be directed to these draining servers and will only be routed to a server whose Endpoint is Ready, except potentially when all servers are draining.`,
8687
},
8788
annotationAffinityCanaryBehavior: {
8889
Validator: parser.ValidateOptions([]string{"sticky", "legacy"}, true, true),

rootfs/etc/nginx/lua/balancer.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ local function get_implementation(backend)
4747

4848
if backend["sessionAffinityConfig"] and
4949
backend["sessionAffinityConfig"]["name"] == "cookie" then
50-
if backend["sessionAffinityConfig"]["mode"] == "persistent" then
50+
local mode = backend["sessionAffinityConfig"]["mode"]
51+
if mode == "persistent" or mode == "persistent-drainable" then
5152
name = "sticky_persistent"
5253
else
5354
name = "sticky_balanced"

0 commit comments

Comments
 (0)