From 6ed256dde614ad3ad08b4a15db173243269cd1d0 Mon Sep 17 00:00:00 2001 From: Zenara Daley Date: Thu, 12 Apr 2018 14:21:42 -0400 Subject: [PATCH] Add session affinity to custom load balancing --- internal/file/bindata.go | 25 +- .../ingress/controller/template/template.go | 1 + rootfs/etc/nginx/lua/balancer.lua | 13 + rootfs/etc/nginx/lua/sticky.lua | 133 +++++++ test/e2e/e2e.go | 8 +- test/e2e/lua/dynamic_configuration.go | 368 +++++++++++++----- 6 files changed, 444 insertions(+), 104 deletions(-) create mode 100644 rootfs/etc/nginx/lua/sticky.lua diff --git a/internal/file/bindata.go b/internal/file/bindata.go index eefebfbef..9ae6f4f8a 100644 --- a/internal/file/bindata.go +++ b/internal/file/bindata.go @@ -3,6 +3,7 @@ // rootfs/etc/nginx/lua/balancer/ewma.lua // rootfs/etc/nginx/lua/balancer.lua // rootfs/etc/nginx/lua/configuration.lua +// rootfs/etc/nginx/lua/sticky.lua // rootfs/etc/nginx/lua/util.lua // rootfs/etc/nginx/nginx.conf // rootfs/etc/nginx/template/nginx.tmpl @@ -95,7 +96,7 @@ func etcNginxLuaBalancerEwmaLua() (*asset, error) { return a, nil } -var _etcNginxLuaBalancerLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x58\x5f\x6f\xdb\x38\x12\x7f\xf7\xa7\x18\xe8\xc9\xc2\xd9\x42\x73\xb8\xa7\xe0\x7c\x40\xda\x64\x0f\x45\x13\xe7\xe0\x66\x6f\xb1\x58\x14\x04\x2d\x8d\x6d\xae\x69\x52\x47\x52\x71\x72\x45\xfb\xd9\x17\x43\x91\xb4\x24\x2b\x49\xfb\x92\x44\xe4\x70\xfe\xfe\xf8\x9b\x61\xa4\x2e\xb9\x04\xb5\x7d\x62\x6b\x2e\xb9\x2a\xd1\xc0\x02\x0c\xfe\xaf\x11\x06\xa7\x99\xda\x3e\x15\x71\x3d\xcb\x27\xad\xf0\x9f\x56\xab\xae\x50\x49\x0b\x69\xb7\xd4\x6a\x23\xb6\x8d\xe1\x4e\x0c\xc4\xba\x1b\x49\xbc\x71\x42\x76\xa5\xe8\x3b\x6d\x4a\xd3\x94\xbc\xdc\x61\x57\xc0\xa0\x75\xcf\x45\xdc\x49\xa2\x7e\x99\x49\x5d\xee\x47\x84\x75\xb9\x4f\x82\x78\x3c\xf0\xae\x48\x0c\xaf\xa0\x8d\x2c\x9f\x4c\xe6\x73\x38\x20\xb7\x8d\xc1\x0a\x84\x02\x8b\xa5\x56\x95\xa5\xe5\x8d\x36\xc0\x15\x2c\xb7\x42\x3d\xc1\x51\x9b\x3d\x1a\x70\x1a\x6a\x51\xee\xa1\xa9\xc1\xed\x10\x14\x1e\x41\x0a\xeb\x40\x6f\xa0\xa9\xad\x33\xc8\x0f\x50\x23\x1a\xaf\x40\x38\x38\x0a\x29\xc1\xf1\x3d\xc2\x3f\x49\xbe\x42\xc9\x9f\xa1\x51\x94\x85\x52\x2b\x67\xb4\x94\x68\xe0\x3f\xf7\x9f\x1f\xb0\xf2\x1a\xd7\xbc\xdc\xa3\xaa\x40\xaf\xff\xc4\xd2\x91\x3d\x5a\x6d\x7d\x40\x55\xd5\x5a\x28\xf7\x2f\xf8\x1b\xbc\xbf\xfa\xf0\xe9\x66\x79\xfd\x99\x7d\xfe\x7d\xf9\x81\x7d\x5c\x3e\xdc\xac\xfe\x7b\x75\x1b\x82\x1e\xdf\x84\x05\x5c\x4c\x82\xc4\xea\xfe\xd7\xe5\x35\x5b\xdd\xbf\xff\xb8\x64\xb7\xf7\x1f\x3e\xb1\x4f\x37\xbf\xc3\x02\x32\xa3\x1b\x55\x31\xa3\xd7\x42\x65\x41\xf4\xfa\xe6\x97\xab\x5f\x6f\x1f\xd8\xed\x7b\x76\x75\xfb\xef\x33\xa1\x58\x90\xd3\x1a\xb3\x8e\x3b\x2a\x22\xc1\xc9\xee\xb8\xc1\xaa\x38\xdb\x8e\xe7\xd8\x1d\x2c\xe0\xeb\xb7\x31\x35\xa9\xba\xb1\xd4\x97\x0a\x8f\xd3\x8c\xfe\xb2\xd9\x0c\xbe\x3a\x71\x40\xdd\x38\x58\xc0\xbb\x19\xe0\x53\x4d\xdf\xf4\x51\x5c\x7c\xcb\xa3\xbe\x90\x4e\x3b\x03\x34\x04\xf5\x08\xa4\x82\x54\x5d\xbc\xfb\xfb\x3f\xf2\x89\xd8\x80\xd2\x2e\x49\x52\xbe\xd5\x04\xc0\xa0\x6b\x8c\xa2\x63\xda\x4c\xb3\x0d\x17\x92\x2a\xa4\xa1\x34\x48\xd1\x51\x55\x5a\xb0\x12\x4c\xe2\xe1\x4b\xc8\xa0\x28\x60\x4a\xc6\xb4\x81\xac\x51\x7b\xa5\x8f\x2a\xcb\xf3\x09\xaa\x2a\x3a\xb5\x69\x54\xe9\xaf\xcb\x16\x1d\x2b\x1b\x63\x50\x39\x16\x54\x4c\xf3\x09\x40\xcf\x77\xa6\xf8\x21\x66\xf3\x91\x9b\xa2\x36\xfa\xe9\x99\x45\xb4\xf9\xdd\xe1\x11\x58\x9c\x3c\xda\xa2\x9b\x76\x35\xe5\x93\x09\x40\x3f\xe6\x18\x32\x78\x1b\x52\x6f\xa7\xf4\xfb\xb7\xab\xd5\x72\x06\x99\xd2\x49\xac\x7f\xd7\x37\x54\x2a\x1f\xbd\x8f\xd9\x69\xeb\x8c\x50\xdb\xbe\x31\x8a\xc6\x47\x9e\x12\x1a\xb6\xdf\xcc\x87\x5c\x33\x2e\xb7\xe7\xe9\x80\xc5\x8b\x69\x7b\x29\xaa\x60\x59\x09\xf9\x92\x37\x7f\x64\x52\xf3\x6a\x1e\xc8\x21\xfb\x42\xc5\xeb\xe3\x7e\xd4\xdf\x20\xff\x53\x4e\x06\xaa\xf3\xd1\x0d\xc4\x52\xc8\x6d\x2c\x51\x66\x01\x99\xa8\xd9\x8e\xdb\x5d\x76\x8a\x69\x3e\x87\x87\xfb\xeb\xfb\x29\xca\x47\xa1\x70\x83\xaa\x12\x39\x88\x43\x2d\xf1\x80\xca\x81\xc7\xc4\x30\xca\x22\x12\x88\xfd\xe3\xdd\x97\x82\x57\x95\x41\x6b\x67\xe3\xbb\xb5\x36\x8e\xb2\x25\x2d\xf6\x5d\xf1\xbc\x79\xf2\x23\xb0\x6c\x38\x0a\x0b\x4f\xb8\xb1\x89\x4c\xcf\x54\xe7\x5d\xb7\xe2\xea\xc9\x95\xb4\x12\xcd\xb7\xc5\x3a\x79\xf0\x7d\x31\xe4\xa3\x57\xb0\x9b\x20\xd9\x1e\xce\x09\xa6\x19\x08\xeb\x51\x62\x9b\x9a\x8c\x60\x35\x83\x0d\x97\x52\xa8\xad\x4f\x04\x5d\x71\x8f\xe7\xbe\x99\x0e\x8e\xe7\x73\x58\x11\xf4\xe7\x2b\x62\x29\x82\xd2\x80\xb3\x2e\xe9\x47\x0a\xdd\xdf\xde\xa2\x18\x65\xdc\x0e\x1e\xb8\x75\x4c\xa8\x0a\x9f\x88\xf1\x86\x64\xd9\xbd\xc4\x45\x7b\x89\xe3\x41\x7f\x66\xd6\x2d\x80\xc2\x27\x77\x9e\xf8\x59\xc7\x44\xe7\xae\xb4\x26\x53\x0e\xa3\x07\x17\xfe\xab\xa3\xf4\x1c\x23\x5e\xf4\x4b\x48\x4b\xf4\xc6\x36\x65\xe9\x0b\xb9\xd1\xa6\x14\x6b\x49\x28\x4c\x6b\x68\xcc\x69\x63\x34\x4c\x3b\x08\x73\x06\x43\x7f\x83\xb2\x57\x19\x6b\x54\x2f\x04\x06\xf7\xb5\x45\x63\xf2\xe4\xb9\xd8\x9c\x9c\xfa\x79\xb5\x8f\x5c\x8a\x0a\x84\xc3\x83\x8d\x6a\x9e\x41\x3f\xa2\x39\x1a\xe1\x1c\xd2\xe4\x13\x0d\x9d\xe1\xa4\x51\x3f\x81\x94\xc9\x0f\x5f\x9b\x31\xa6\xb2\xcf\xaa\x4c\x34\x14\x7e\x93\x67\xa9\x4d\x9c\xa7\x3e\x49\xb5\x98\xe7\xd2\x6a\xea\xc5\xe8\x7c\xef\x33\x68\x6b\x2c\x9d\x78\x44\x48\x93\x64\xdb\xf7\xad\x50\xe5\x69\x8e\xd9\x71\x0b\xe5\x8e\xab\x2d\x0e\x53\xd0\xe6\xb0\x42\x89\x0e\x07\xe0\x9e\x24\x7e\xbb\x84\x95\x37\xd9\xaa\xd6\x1b\xb8\xf9\xed\xee\x0a\x6a\x4c\x2d\xf7\x9c\x51\x7f\x9c\xd2\x87\x2c\x3b\xa0\xb6\xce\xf8\x12\x43\x64\x24\x72\xb9\x91\x8d\xdd\x31\x2e\xe5\x34\x7f\x55\x90\xf9\x2b\xe7\x74\x53\xee\xb0\x62\xdc\x0d\x0e\x06\x3e\xe9\x42\xed\xe3\xf2\x97\xfb\x19\x64\x54\x2d\xa3\x95\xf8\x7f\xdb\x69\x4b\x4d\xbc\xee\xd0\x77\xdb\x30\x62\xf4\x13\xf6\x56\xc9\xed\x79\x8b\xb2\xac\xe2\x8e\x46\xe3\x5e\x57\x2f\xa8\x1f\xf5\x24\x46\x3a\x6b\x38\x3a\xe8\xaf\xa7\x88\x5a\x3b\x7a\x3f\xa3\xf9\x38\x69\x83\x05\xd4\x25\xc5\x4e\xef\x87\xa2\xc2\x52\x57\x27\x94\xb5\x2a\x3b\xa6\xf4\x7e\xfc\x32\xde\xac\x56\x33\x80\xac\xd4\x8d\xac\xbc\x60\xcd\x8d\xc5\xd3\xf4\x46\x6a\x2e\x07\x13\x49\xd7\x8b\x3c\x1f\x75\x99\xc6\x18\xd6\xf3\x97\x1e\x03\x35\x17\xc6\xf6\x8f\x43\xa5\x3b\x7d\xef\x85\x79\xab\x73\x22\xd1\xf5\x70\xaa\x0b\x97\x02\x16\xe0\x4c\x83\x93\x96\x7e\x37\xe7\xc3\x0b\x8c\x9c\xa0\xb8\xe9\xe5\x54\x54\x88\x35\x23\x78\x70\x93\xee\x50\x2f\x8a\x3c\x12\xf9\xd0\x40\xd2\xd6\x31\xd4\x23\x89\x51\x25\xed\xcf\x31\xb4\xf1\x8d\x43\xc3\xce\x07\xa2\xd7\x07\x9d\x37\x6e\xa0\x9f\x25\xce\x35\x27\x1f\x92\x75\x76\x57\x08\x25\x1c\x6b\x5f\x69\x5e\x88\xc5\x91\x9f\x50\x43\x4f\x03\x53\xe0\x23\x9a\xe7\xe9\xf8\xe3\x68\xd6\xbf\x2f\xc1\x35\xd2\xf0\x32\x0c\x33\xff\x38\x80\xe3\x0e\xe9\xdd\xe8\x1c\xcd\x10\xf4\x30\x3c\x19\xf3\xb8\xea\x29\x1e\x62\x93\x5a\xd1\x8b\x31\x95\x91\x2a\xda\x5c\xd6\x3b\x6e\xe3\x4b\x80\xd2\xe9\xbf\x63\x16\xc3\xe6\x02\x32\xa9\xb7\x9d\x1c\x9e\xa7\x6f\x80\xfe\xce\xe9\xef\x0b\x48\x0f\xe4\xec\x6c\x7e\x0e\x4f\xa1\x43\x63\x1d\xac\xe9\xf5\x23\x65\xfb\x66\x4e\x0d\x40\x1b\x90\x7a\x3b\x83\x75\xe3\xe0\x48\xc4\x1f\x45\x42\xd4\xde\x4a\x9f\xfa\xd2\xff\x21\x0a\x8b\x8e\x1d\xb4\x41\xe6\x8c\x40\x3b\xbd\xc8\x4f\x54\xb2\xd3\xd6\xcd\x80\x9a\x9b\xbf\x69\x31\x94\x0e\xd5\x4c\xc0\xf3\x4d\xaa\x78\x5f\x6d\xc4\x1d\xbd\xcc\xa7\x27\x65\x21\x73\x63\x54\x13\x6e\x44\xe2\xe4\xf0\x9d\x05\x4d\xfe\x8d\x4f\x93\xa4\x6f\x87\x61\x62\x24\xc5\x7e\xc4\xbc\x6c\x83\x25\x77\xfd\xc4\xd9\x58\x42\x46\x80\x79\xbf\xfc\x63\xb7\xa2\xad\x51\x1e\xa6\xef\x37\xa0\x27\x24\x26\xec\x45\xe7\x7a\xff\x89\x00\xa7\xdf\xc4\x5c\x28\x30\xbb\x9b\xfc\x15\x00\x00\xff\xff\x52\x6c\x91\x55\x20\x12\x00\x00") +var _etcNginxLuaBalancerLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x58\x5f\x6f\x1b\xb9\x11\x7f\xd7\xa7\x18\xec\x93\x16\x95\x16\x71\xd1\x27\xa3\x2a\xe0\x24\xbe\x22\x88\x63\x17\x4a\xae\x87\xc3\x21\x20\xe8\xdd\x91\xc4\x13\x45\x6e\x49\xae\x65\xf7\x70\xf9\xec\x87\xe1\x92\xdc\xbf\xb6\x93\x17\x5b\x22\x87\xf3\x7f\x7e\x33\x23\xa9\x4b\x2e\x41\xed\x1f\xd9\x3d\x97\x5c\x95\x68\x60\x03\x06\xff\xd7\x08\x83\xcb\x4c\xed\x1f\x8b\x78\x9e\xe5\x8b\x96\xf8\x77\xab\x55\x9f\xa8\xa4\x83\x74\x5b\x6a\xb5\x13\xfb\xc6\x70\x27\x46\x64\xfd\x8b\x44\xde\x38\x21\xfb\x54\xf4\x3d\x5d\x4a\xd3\x94\xbc\x3c\x60\x9f\xc0\xa0\x75\x4f\x45\xbc\x49\xa4\xfe\x98\x49\x5d\x1e\x67\x88\x75\x79\x4c\x84\x78\x3e\xf1\x3e\x49\x34\xaf\xa0\x8b\x44\x65\x9d\x28\x8f\x4f\x7d\xba\xf6\x24\xcb\x17\x8b\xf5\x1a\x4e\xc8\x6d\x63\xb0\x02\xa1\xc0\x62\xa9\x55\x65\xe9\x78\xa7\x0d\x70\x05\xb7\x7b\xa1\x1e\xe1\xac\xcd\x11\x0d\x38\x0d\xb5\x28\x8f\xd0\xd4\xe0\x0e\x08\x0a\xcf\x20\x85\x75\xa0\x77\xd0\xd4\xd6\x19\xe4\x27\xa8\x11\x8d\x67\x20\x1c\x9c\x85\x94\xe0\xf8\x11\xe1\x9f\x44\x5f\xa1\xe4\x4f\xd0\x28\x72\x53\xa9\x95\x33\x5a\x4a\x34\xf0\x9f\xbb\xcf\x5f\xb0\xf2\x1c\xef\x79\x79\x44\x55\x81\xbe\xff\x1d\x4b\x47\xf2\xe8\xb4\xd5\x01\x55\x55\x6b\xa1\xdc\xbf\xe0\x6f\xf0\xf6\xea\xdd\xc7\xeb\xdb\xf7\x9f\xd9\xe7\x5f\x6f\xdf\xb1\x0f\xb7\x5f\xae\xb7\xff\xbd\xba\x09\xf6\xce\x5f\xc2\x06\x2e\x16\x81\x62\x7b\xf7\xf3\xed\x7b\xb6\xbd\x7b\xfb\xe1\x96\xdd\xdc\xbd\xfb\xc8\x3e\x5e\xff\x0a\x1b\xc8\x8c\x6e\x54\xc5\x8c\xbe\x17\x2a\x0b\xa4\xef\xaf\x7f\xba\xfa\xf9\xe6\x0b\xbb\x79\xcb\xae\x6e\xfe\x3d\x21\x8a\x11\xeb\xce\x98\x75\xdc\x51\x94\x29\xdf\xec\x81\x1b\xac\x8a\xc9\x75\x7c\xc7\x3e\xc1\x06\xfe\xf8\x73\x8e\x4d\x0a\x7f\xcc\x85\x4b\x85\xe7\x65\x46\x9f\x6c\xb6\x82\x3f\x9c\x38\xa1\x6e\x1c\x6c\xe0\xcd\x0a\xf0\xb1\xa6\xef\xf4\xa5\xb8\xf8\x33\x8f\xfc\x82\x3b\xed\x0a\xd0\x50\x2d\xc4\x4c\x2b\x88\xd5\xc5\x9b\xbf\xff\x23\x5f\x88\x1d\x28\xed\x12\x25\xf9\x5b\x2d\x00\x0c\xba\xc6\x28\x7a\xa6\xcd\x32\xdb\x71\x21\x29\x42\x1a\x4a\x83\x64\x1d\x45\xa5\xcd\x66\x4a\x93\xf8\xf8\x12\x32\x28\x0a\x58\x92\x30\x6d\x20\x6b\xd4\x51\xe9\xb3\xca\xf2\x7c\x81\xaa\x8a\x4a\xed\x1a\x55\xfa\x7a\xda\xa3\x63\x65\x63\x0c\x2a\xc7\x02\x8b\x65\xbe\x00\x18\xe8\xce\x14\x3f\x45\x6f\x3e\x70\x53\xd4\x46\x3f\x3e\xb1\x98\x6d\xfe\x76\xfc\x04\x36\x9d\x46\x7b\x74\xcb\x3e\xa7\x7c\xb1\x00\x18\xda\x1c\x4d\x06\x2f\x43\xea\xfd\x92\xfe\xff\x72\xb5\xbd\x5d\x41\xa6\x74\x22\x1b\x82\xc1\x8e\x42\xe5\xad\xf7\x36\x3b\x6d\x9d\x11\x6a\x3f\x14\x46\xd6\x78\xcb\x93\x43\xc3\xf5\xab\xfe\x90\xf7\x8c\xcb\xfd\xd4\x1d\xb0\x79\xd6\x6d\xcf\x59\x15\x24\x2b\x21\x9f\xd3\xe6\xb7\x4c\x6a\x5e\xad\x03\x7a\x64\x5f\x29\x78\xc3\xbc\x9f\xd5\x37\xd0\xff\x90\x92\x01\x0b\xbd\x75\x23\xb2\x89\xc9\xc2\xb2\x04\x5d\xed\x87\x22\x1d\x45\x3f\xc7\x78\x76\xb4\xc9\xee\x00\x91\x01\x35\x3a\x1e\x24\x33\x9e\x76\x6c\xe8\x85\xd8\x75\xe4\xdf\x36\xe4\xb1\x8e\x5b\x57\x12\x81\xa2\xe0\x55\x65\xd0\x52\x6d\xc5\x93\x5a\x1b\xe7\x89\xc9\x5b\x5e\x85\x68\xe7\x10\x34\x52\x18\xc4\x2e\x91\x6c\x20\x13\x35\x3b\x70\x7b\xc8\x3a\xa1\xeb\x35\x7c\xb9\x7b\x7f\xb7\x44\xf9\x20\x14\xee\x50\x55\x22\x07\x71\xaa\x25\x9e\x50\x39\xf0\xa9\x3f\x0e\x66\x11\xd5\xb1\xbf\xbd\xf9\xda\x29\x39\x7b\x1b\x14\x46\x69\x71\xa8\x8a\xef\x1f\x2f\xb8\x92\xee\x63\x33\x5d\x4e\x58\xe7\x8b\x1f\xf2\xd7\xc4\x19\xdf\x36\x63\xd8\x7d\xa1\x44\x53\xe5\xb5\x8f\x73\xaa\xc6\x0c\x84\xf5\xc5\x60\x9b\x9a\x84\x60\xb5\x82\x1d\x97\x52\xa8\xbd\x77\x04\x21\x99\x2f\xdb\xa1\x98\x5e\xb9\xae\xd7\xb0\xa5\x90\xad\xb7\x14\x32\xaa\x98\x11\x34\x5f\xd2\x9f\x64\xba\x07\xa9\xa2\x98\x6d\x2c\xbd\xb4\xe7\xd6\x31\xa1\x2a\x7c\x24\x60\x1f\xf7\x84\x3e\x56\x15\x2d\x56\xa5\x4a\xa0\x37\xab\x7e\x00\x14\x3e\xba\xa9\xe3\x57\x3d\x11\x3d\x48\x68\x45\x26\x1f\x46\x0d\x2e\x62\xae\x46\xa6\xd3\x1c\xf1\xa4\x5f\x17\x31\xa3\xc3\x3c\xd1\x94\xa5\x0f\xe4\x4e\x9b\x52\xdc\x4b\xca\xc2\x74\x86\xc6\x74\x17\xb3\x66\xda\x91\x99\x2b\x18\xeb\x1b\x98\xbd\x08\xcc\xb3\x7c\x21\x34\x2a\x1f\x5b\x34\x26\x4f\x9a\x8b\x5d\xa7\xd4\x8f\xb3\x7d\xe0\x52\x54\x20\x1c\x9e\x6c\x64\xf3\x04\xfa\x01\xcd\xd9\x08\xe7\x90\x26\xc0\x9e\xa0\x19\x2c\x0a\xd0\x63\xfb\xd0\x13\x3f\xa4\xda\xec\x98\x4c\x92\xad\x51\x3f\x90\x6e\x8b\xef\xae\xbd\x39\x54\xb7\x4f\xaa\x4c\x90\xdd\xd3\x2c\xb5\xd4\x69\xfc\xfa\x58\xbc\x5e\x03\x97\x56\xd3\xdc\x82\xce\xcf\x09\x06\x6d\x8d\xa5\x13\x0f\x08\x69\x2c\x6f\x67\x24\x2b\x54\xd9\xcd\x7c\x07\x6e\xa1\x3c\x70\xb5\xc7\xb1\x0b\xda\x40\x54\x28\xd1\xe1\xa8\x42\x16\x09\x24\x2f\x61\xeb\x45\xb6\xac\xf5\x0e\xae\x7f\xf9\x74\x05\x35\xa6\xf1\x64\xda\x7d\xbe\xbf\xfd\x8d\xa1\x7a\x84\x8f\xbd\x51\x2f\x9a\xc8\x88\xe4\x72\x27\x1b\x7b\x60\x5c\xca\x65\xfe\x22\x21\xf3\x75\xeb\x74\x53\x1e\xb0\x62\xdc\x8d\x1e\x06\x50\xea\xe7\xeb\x87\xdb\x9f\xee\x56\x90\x51\xb4\x8c\x56\xe2\xff\xed\x54\x52\x6a\x6a\x0e\x0e\xfd\x64\x12\xc6\xb1\xa1\xc3\x5e\x0b\xb9\x9d\xb6\x73\xcb\x2a\xee\x68\xcf\x18\x4c\x40\xbe\x8f\x0e\x28\x66\xa6\x90\xf0\x74\x34\x8b\x74\x16\xb5\x72\xf4\x71\x45\xbb\x44\xe2\x06\x1b\xa8\x4b\xb2\x9d\x96\xb1\xa2\xc2\x52\x57\x5d\x96\xb5\x2c\x7b\xa2\xf4\x71\xbe\xa2\xaf\xb7\xdb\x15\x40\x56\xea\x46\x56\x9e\xb0\xe6\xc6\x62\x37\xe9\x12\x9b\xcb\xd1\xf4\xd6\xd7\x22\xcf\x67\x55\xa6\x91\x8f\x0d\xf4\xa5\xc5\xa9\xe6\xc2\xd8\xe1\x73\xa8\x74\xaf\x79\x3e\x33\x9b\xf6\x5e\x24\xcc\x1f\x4f\xc0\xa1\x28\x60\x03\xce\x34\xb8\x88\xa3\xca\x64\xd0\x83\x99\x17\x64\x37\xad\xa1\x45\x85\x58\x33\x4a\x0f\x6e\x52\x0d\x0d\xac\xc8\xd3\xe4\x32\x12\x90\xb8\xf5\x04\x0d\x40\x62\x96\x49\xfb\x77\x2e\xdb\xf8\xce\xa1\x61\xd3\xe1\xf1\xb5\xa1\xf0\xc5\x0a\xf4\x03\xc9\x94\x73\xd2\x21\x49\x67\x9f\x0a\xa1\x84\x63\xed\x46\xeb\x89\x58\x5c\x8f\x28\x6b\x68\x8d\x32\x05\x3e\xa0\x79\x5a\xce\x2f\x92\xab\x61\xbd\x04\xd5\x88\xc3\xf3\x69\x98\xf9\x45\x0a\xce\x07\xa4\x1d\xdb\x39\x1a\x44\x68\x89\xee\x84\xf9\xbc\x1a\x30\x1e\xe7\x26\xf5\xb3\x67\x6d\x2a\x23\x54\xb4\xbe\xac\x0f\xdc\xc6\xad\x89\xdc\xe9\xbf\x47\x2f\x86\xcb\x0d\x64\x52\xef\x7b\x3e\x9c\xba\x6f\x94\xfd\xbd\xd7\xdf\x36\x90\x7e\x6d\xc8\x26\xbb\x46\x58\x1b\x4f\x8d\x75\x70\x4f\x9b\xa2\x94\xed\xef\x0b\xa9\x01\x68\x03\x52\xef\x57\x70\xdf\x38\x38\x13\xf0\x47\x92\x60\xb5\x97\x32\x84\xbe\xf4\xa3\x8e\x6f\xa3\x27\x6d\x90\x39\x23\xd0\x2e\x2f\xf2\x0e\x4a\x0e\xda\xba\x15\x50\x73\xf3\x95\x16\x4d\xe9\x41\xcd\x02\x3c\xde\xa4\x88\x0f\xd9\xc6\xbc\xab\x11\xcd\xb2\x63\x16\x3c\x37\x07\x35\xa1\x22\x12\x26\x87\xef\x59\xe0\xe4\x7f\x0f\xa1\x71\xd4\xb7\xc3\x30\x76\x12\x63\x3f\xa7\x5e\xb6\xc6\x92\xba\x7e\x6c\x6d\x2c\x65\x46\x48\xf3\x61\xf8\xe7\xaa\xa2\x8d\x51\x1e\x46\xf8\x57\x52\x4f\x48\x4c\xb9\x17\x95\x1b\xfc\x6a\x03\x4e\xbf\x9a\x73\x21\xc0\xec\xd3\xe2\xaf\x00\x00\x00\xff\xff\xf7\x27\x98\x07\x6d\x13\x00\x00") func etcNginxLuaBalancerLuaBytes() ([]byte, error) { return bindataRead( @@ -135,6 +136,26 @@ func etcNginxLuaConfigurationLua() (*asset, error) { return a, nil } +var _etcNginxLuaStickyLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x57\xdd\x6b\x23\x37\x10\x7f\xf7\x5f\x31\x08\x8e\xb3\x61\xb3\xf4\x1e\xee\x25\xc7\x3e\x84\x34\xc7\x85\x6b\x12\xa8\x73\x94\x92\x33\x8b\xb2\x9a\xb5\x75\xde\x48\xae\x24\x27\x31\xa5\xfd\xdb\x8b\x3e\xf7\x23\x1b\x3b\x69\x03\x7d\xb2\xad\x19\xcd\xfc\xe6\x37\x5f\x72\x23\x2b\xda\xc0\x0f\x2d\x05\x14\xa0\xf0\x8f\x2d\x57\x38\x7d\x5f\xd9\x83\xf7\xb3\x89\x97\x6a\xa3\x3a\x42\xa2\x50\x9b\x5d\xae\x8d\xe2\x62\x49\x92\xce\x8a\x7e\x28\x2b\xb5\xdb\x18\x39\xa2\xbb\xa2\x1f\x92\xe6\x1d\xfb\xf8\xac\xe2\x1d\xfb\x48\x66\x93\xe4\x96\x57\xeb\x5d\xa9\x51\x6b\x2e\x85\x86\x02\xc4\xf2\xd1\xda\x52\xc8\xf2\x81\x30\xde\xf9\xf9\xec\xf3\xc9\xb7\x5f\xae\xcb\xf9\xd9\x7c\x7e\x7e\x75\x59\x9e\x5e\x5d\x7d\x3d\x3f\x2b\x2f\x4f\x2e\xce\xa0\x00\xa2\xe4\xd6\x20\xd9\xaf\xfb\xe5\x64\xfe\xc5\xea\x5a\x2c\x93\xa3\x23\x38\xdd\x2a\x85\xc2\x34\x3b\x98\x5f\x9f\x9f\x7e\xfd\xbd\xbc\x3e\xbf\x38\xbb\xfa\x76\x0d\x02\xef\x51\x01\x3e\x6e\xb8\x42\x1d\x6c\x0e\x54\x0a\xf8\x29\x22\x2b\x2f\xa0\x80\x3f\xff\x8a\x3f\xeb\xad\xa8\x0c\x97\xc2\xd1\xc1\xf8\x12\xb5\x99\x2a\xfa\x30\x9b\x00\x24\x9a\xa0\xe8\x90\x75\x2c\xf0\x61\x6a\xc5\xbc\x06\x21\x8d\x93\x9b\x15\x8a\x09\x00\x80\x42\xb3\x55\x02\x04\x6f\x32\x07\xfc\x18\x6a\xca\x1b\x64\x60\x24\x54\x0a\xa9\x41\x90\xb7\x3f\xb0\x32\x64\x02\x80\x82\x25\x2f\x72\xed\x9d\x1c\x6f\x37\x8c\x1a\x8c\x10\x82\x0f\xb9\x7e\x99\x0b\xca\x18\x30\x6a\xe8\xd0\xba\x8f\x2b\x78\xa8\xb9\xa0\x4d\x8c\x20\x4a\x0a\x6b\xf0\x55\x71\xf8\x9b\xad\xa7\x70\x45\x1b\x95\x1b\x59\xae\xf0\x71\xea\x35\x66\x99\x35\x33\xb1\x4a\x43\xca\x5d\xad\x8e\x71\x6e\x05\x50\x74\x6b\x79\xc8\xba\xd3\x18\x87\x6b\x45\xaf\xe3\xdd\xdd\x78\x1d\xf1\x43\x27\x07\x99\x77\x17\x5e\x4d\xfd\x33\xb1\xbc\x01\xf7\x4b\x34\x65\x25\xe5\x9a\x63\x29\xe8\x1d\x4e\x6f\x69\xb5\x46\xc1\xda\x1c\xd8\x53\x28\x20\x9c\xdf\x90\xd0\xe1\x27\x75\xcd\x05\x37\xbb\x53\x29\x6a\xbe\x24\x8b\x1b\xe2\xad\xcc\xfb\x62\x2b\xb0\x16\xc8\xa2\x85\xe7\x2c\x4a\xb5\x6f\x36\x8c\x42\xe5\xba\xbc\xa7\x0d\x67\x25\x0a\xb6\x91\x5c\x98\x08\x36\xb3\xb4\x2b\xd4\x3a\x83\x8d\x54\xc6\x62\xaf\xa5\x82\x32\x03\xdc\x00\x17\xc0\x37\x94\x2b\x1d\xb5\xf3\x78\x5d\xcf\x80\x49\xc7\x35\xaf\x01\x37\x79\x30\x62\x33\x11\xbf\x52\xc1\xac\xc4\x5a\xb5\xc7\xee\x33\x65\x28\x05\x64\xd4\x16\xdd\x89\xcf\x42\x2f\x17\x35\x6d\x34\xfa\x70\x52\x20\xe5\x45\xce\x75\xe9\x27\x66\x97\xf0\x70\xe5\x30\xd5\x9e\x51\x8b\x28\xb0\x4e\x9e\x7a\xb0\x89\x1d\x12\xd5\x66\xb5\x93\x72\x28\x0e\x17\x41\x10\xae\x71\x07\xc9\x67\x49\x20\xcf\xbb\x86\x92\x76\x74\x1b\xf4\xed\x96\xb8\xa7\xea\xa6\x35\xb2\xf0\x95\xdf\xd7\x1b\xd4\xbf\xbd\xd5\xc8\xe5\xd4\x7e\x9e\x5f\x7e\xbe\xca\xc0\x6f\xb8\xbc\x96\xea\x8e\x9a\x69\x48\x01\xb9\x09\x60\x8b\x77\x3a\x03\x1a\xa8\x2a\xbc\xaf\x45\x80\x07\xdf\xc9\x3b\xfd\x9d\x00\xd7\x7e\x68\xa0\x71\x05\x62\x56\x5c\xbb\x8d\x67\x9b\x28\x0b\x06\x63\x95\xd8\x88\xe2\x59\x3f\x48\x80\xd9\x6c\xd0\xa2\x21\xeb\x4f\x19\xf0\x98\x6d\xdf\xf7\xf7\xe3\xf1\x12\xcd\xb4\x1b\xff\x6c\x40\x49\xbc\xf8\x4a\x56\x0e\xd0\x21\x64\xf2\x00\x54\x6b\xbe\x14\xc8\x48\xd6\x8b\xf9\xc5\xb1\x41\xe1\x9e\x29\x39\xc3\x4a\x32\x9c\x0e\x90\xb7\xb5\xe3\x7a\x16\x8a\x7d\xed\x1b\x4f\xf2\xd4\xc7\xe9\x24\x36\x74\x18\xc4\xde\xd8\x5b\xd1\x11\x29\x68\x63\x72\x15\x02\x8d\x14\x4b\x54\xde\xd9\x38\x3d\xc3\x74\x32\x6c\xd0\xe0\x93\x8c\x8e\xf0\x98\x8e\xa2\xee\xd3\xd6\xd5\xdd\xd6\x8d\x5f\x12\x8c\x7f\xdd\xc4\x28\xdc\x0e\x45\x4b\xb8\x52\x7b\x6a\xd5\xa5\x15\x45\x2f\xad\xad\x99\x15\xd5\xab\xff\xb6\x10\xac\x05\xb2\x98\xf8\xac\x7a\x73\x85\xdf\x71\xa4\x4d\x6d\x1f\x6d\x7c\x05\x84\x57\xc2\x48\xb1\xa1\x9d\xb3\x61\x98\x3b\x9b\x7f\x17\x7b\x5f\x94\x9d\x31\xde\xad\xa2\xdf\x4e\x7e\xbd\x7c\x66\xd4\x1c\x1c\x36\x81\x89\x23\xff\xfb\xc8\xa1\xe8\x4f\x1e\x57\x51\x19\x30\xac\xe9\xb6\x31\x96\x6d\x23\xe1\x9d\x4e\xc3\x67\x7c\xfc\x80\x0b\xa8\xfd\xb5\x27\xac\xa0\x13\xaa\xd4\xd7\xdb\x08\x97\x9d\x47\xee\x18\x95\xee\x9a\x9d\x46\x4a\x59\x1a\x9f\x9d\x40\x63\x64\x1d\xe0\xa8\xf3\x54\x72\xcd\x97\xca\xef\xd8\xf1\xd0\x8f\xdf\x02\xe8\xcd\xa3\x76\x16\xbd\x49\xe7\xdb\x04\x50\x10\xf8\x90\x50\x8c\x75\xbb\x75\xb1\x42\xca\x50\xdd\x90\x39\x9a\xa3\x53\xbf\x72\x17\x50\xf4\x3a\x30\xcf\x81\x14\x6e\x27\x26\xba\xdd\xd9\x27\xd2\xbe\x67\xb7\x55\xe5\xc6\x5b\x2d\x55\xc5\x6f\x1b\x5b\xb0\xe9\x0c\x95\x6a\x05\x23\x1b\x43\xbb\x8d\xd1\x26\xb2\x9f\xb7\x6c\xf0\x57\xa7\xfb\x46\xf6\x1e\xfe\xe7\x14\xa6\xa2\x4a\x21\xbe\x18\xcf\xcb\x56\xfd\xf0\xef\xa9\xff\x63\x0a\x8c\x57\x6e\xac\xd7\xdb\xa6\xf9\xd4\x0e\xfa\x80\x62\x07\xf2\x1e\xd5\x83\xe2\xc6\xa0\x18\x7d\x03\xb4\x0b\xdf\x46\xe0\xaa\x2f\x0c\xf0\xf2\x62\xf2\x4f\x00\x00\x00\xff\xff\x7f\x7e\xd2\xe9\xae\x0f\x00\x00") + +func etcNginxLuaStickyLuaBytes() ([]byte, error) { + return bindataRead( + _etcNginxLuaStickyLua, + "etc/nginx/lua/sticky.lua", + ) +} + +func etcNginxLuaStickyLua() (*asset, error) { + bytes, err := etcNginxLuaStickyLuaBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "etc/nginx/lua/sticky.lua", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + var _etcNginxLuaUtilLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x55\x4b\x6f\xa4\x46\x10\xbe\xf3\x2b\x4a\xb6\xa2\xb5\xb5\x63\x5e\x33\x5e\xc7\x48\x73\xb0\x36\x91\x72\x88\x4f\x59\xed\x65\xe4\xa0\x1e\x28\x98\xce\x34\xdd\xa4\xbb\xc0\xb6\xf2\xf8\xed\x51\x35\x30\x30\x1b\x6f\x72\xd8\x39\x0c\x50\x7c\xf5\xd5\xeb\xeb\x42\x99\x42\x28\xc8\x1f\x61\x0b\x7f\xfc\x15\x0c\x4f\x8e\xac\xd4\x75\xae\x50\xc3\x76\x7c\x08\x15\xea\x20\xb8\xb9\x01\x3a\x48\x07\xb2\x69\x15\x36\xa8\x49\x90\x34\x1a\xa4\x03\x12\x47\xd4\x50\x59\xd3\x30\xe8\x40\xd4\xba\x2c\x8a\x9e\x71\x1f\x0a\x5b\x1c\x64\x8f\xa1\xb1\x35\x3f\x47\x69\x9c\xac\x93\x34\xbd\x8d\xef\xe2\xcd\x7a\x13\x31\x34\x8b\x22\xa7\x65\xdb\x22\xb9\x50\x75\xa2\x30\xe5\x00\x9f\x8c\xd1\x0f\x88\x6d\xfe\xd1\x34\xad\xb0\xd2\x19\x9d\x9b\x2a\xff\xf4\x6c\xf2\xcf\x42\x75\xe8\xf2\x35\x87\x14\xba\x84\xc6\x94\xb2\x92\x58\x42\x65\x2c\x74\x0e\x41\xea\x21\xdf\xd6\x9a\xdf\xb0\xa0\xb1\xbc\xaa\xd3\x85\xcf\xbb\x64\xda\xc2\xd3\xe2\x15\x25\x2b\xa0\x74\x05\xb2\xd6\xc6\x62\xde\xd0\x75\x00\x30\x38\xd0\x6b\x02\x5b\xa0\xd7\x96\x51\x4b\x73\x7a\x32\xa7\x6c\x96\x95\x87\xfe\xbd\xf5\xaf\xe8\x80\x1a\x2c\x52\x67\x35\x54\x42\x39\x04\xd4\x65\x00\x70\x73\x03\xda\xe8\x1b\x12\x7b\x85\xde\xdb\x41\x21\x34\xec\x11\x4a\x69\xb1\x20\xf5\x0a\x63\x4e\xe5\x19\xe7\x3b\xef\xf1\xce\x57\xca\xfc\x0b\xd3\x32\x14\x25\xb0\xdd\x02\xa5\x73\x34\xe1\xe0\x19\x95\xe2\xab\xc7\x3b\x78\x3e\xc8\xe2\x00\x07\xd1\x23\xbb\x42\x83\x24\x1a\xa4\x83\x29\x21\xcf\xf1\xf7\x53\x81\x0d\xc1\x16\x6a\x24\x7e\xef\x3d\xc7\xf2\x65\x05\xda\xd0\xdc\xa9\xa1\xf9\xd3\x25\x64\x8e\xff\x4a\x89\xa7\x73\x4c\x56\x7d\xc2\xf3\x69\x85\xb4\x8e\x79\xa1\x34\x01\xc0\x14\xba\xf7\xad\x4d\x77\xc7\xe4\xc9\x5b\x65\xe5\x4d\x5b\xd0\x52\x81\xb1\x3e\xfe\xd9\xf8\xfa\x64\xd5\xa7\xd7\x5f\x6d\xfa\x22\x72\xba\xea\xd3\x45\xe4\xf4\xcb\xc8\x7e\xd6\xc9\xee\x98\xce\x91\x93\x6f\x8e\x3c\x75\xc2\x76\x18\xb0\x25\x7f\x0c\x97\x24\xb0\x3d\xe3\x0c\x82\x93\x46\xf3\xc7\x50\xba\x7c\xaf\x84\x3e\x5e\x39\xb2\xd7\x33\x97\x23\xbb\x48\x6b\x3e\xb3\x1e\xc6\x6f\x62\x1f\x69\x3a\x8f\x59\x14\xe9\x5a\xea\x17\x7f\xb2\x50\x47\xa5\x29\x9c\x3f\x7d\x91\xae\x5f\x72\xbe\xc9\xbb\xd6\x91\x45\xd1\xe4\x8d\x29\x3b\x85\xe1\x81\x1a\x75\x89\x2f\x82\x4f\x3b\xd3\x7c\x7c\xf8\xfc\xe3\xc3\xa7\x0c\x3c\x0f\x9f\xfa\x5a\xf6\x52\xd7\x60\x3a\x82\x0c\xa4\x76\x84\xa2\x04\x53\xc1\x0a\x9c\xf1\xca\xe2\x20\xc0\xf5\x3d\x5b\xa3\x6b\xe6\x48\xd2\xbb\x30\x0e\xe3\x30\xc9\xd2\x0f\xc9\xed\x1d\x64\xff\xb2\xac\x40\xd7\x2f\x61\x2f\x6c\x78\xca\x47\x94\xa5\x65\xe7\x34\x8e\x21\xf3\xff\x6f\x80\x1c\x09\xea\x1c\xc3\xe2\xd0\xe3\xf8\xf2\x06\xce\xa2\x6b\x8d\x76\x98\x93\x6c\xf0\xac\xd1\xae\x55\x92\xe6\x2e\xf4\xc2\x5e\xf5\xc2\x2e\x14\xdf\x0b\xeb\xe7\xec\x85\x31\x8e\x41\x4b\xb5\xe2\xbf\xd3\xa8\xc7\xe5\x30\x2c\xd4\x41\x73\x3d\xeb\xad\x17\x36\xab\x1b\x41\xc5\xe1\xea\x62\xf7\xeb\x77\xee\xcf\xd5\xd3\xfb\x8b\x93\xf8\x58\x66\x7c\xa4\x2f\xb2\x8b\x39\x04\x00\xed\x2e\xe9\x7d\xf2\x04\x5b\xe8\xbd\xe5\x2d\x4d\x0d\x63\x5e\x16\x52\x23\xe5\x95\xb4\x8e\xf2\x9e\x57\xe4\x54\xc5\x9c\xd9\xd7\x8b\x65\x2d\xf9\xbc\x65\x05\x97\xe4\x65\x74\x26\x6d\x96\xdb\x79\xf8\x5d\xf2\x74\x12\xda\xff\x7e\x1d\xb2\xe5\xe7\xa1\x96\x74\xe8\xf6\x61\x61\x9a\x48\x75\xa2\xea\xf4\x74\xd9\x2b\xb3\x8f\x1a\xe1\x08\x6d\x54\x75\x9a\x3f\x0a\x97\x3f\xaf\xfd\x9e\xff\xe5\xa7\x87\x0c\xe2\x4d\x71\x7f\x5f\xdd\x17\xeb\xfb\x35\xde\x6e\xc4\x87\x78\x23\xca\x12\x37\xfb\xf4\x76\x7f\x77\xbf\xa9\x36\xdf\x27\xf1\x06\xe3\x32\x7e\x6b\xe1\x17\xa6\x7d\xbd\x32\x56\xd6\x73\x47\xf8\x29\xe7\x4d\x3c\xad\xf3\xf3\xd7\xec\x31\x34\x64\x01\x3c\x5f\xbe\xe3\xb4\x18\x39\xcd\x9d\x7f\x3c\x7b\xef\x73\xc4\xd7\xd5\x70\xe7\x07\xc2\x72\xd0\xf8\x42\x83\xcd\xcb\x67\xd2\xc1\x4c\xb4\x3b\xcb\x96\x29\xae\x9f\xc6\x3d\x31\x5b\x3d\xdd\xf5\xe8\x39\x8a\x43\x39\x3c\xcf\x87\x91\x5f\xaa\xc6\x17\xb5\xd8\x44\x23\x74\xba\x0d\x82\x11\x97\x3f\x06\xff\x04\x00\x00\xff\xff\xc6\xa6\x46\xf4\x23\x08\x00\x00") func etcNginxLuaUtilLuaBytes() ([]byte, error) { @@ -290,6 +311,7 @@ var _bindata = map[string]func() (*asset, error){ "etc/nginx/lua/balancer/ewma.lua": etcNginxLuaBalancerEwmaLua, "etc/nginx/lua/balancer.lua": etcNginxLuaBalancerLua, "etc/nginx/lua/configuration.lua": etcNginxLuaConfigurationLua, + "etc/nginx/lua/sticky.lua": etcNginxLuaStickyLua, "etc/nginx/lua/util.lua": etcNginxLuaUtilLua, "etc/nginx/nginx.conf": etcNginxNginxConf, "etc/nginx/template/nginx.tmpl": etcNginxTemplateNginxTmpl, @@ -345,6 +367,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ }}, "balancer.lua": &bintree{etcNginxLuaBalancerLua, map[string]*bintree{}}, "configuration.lua": &bintree{etcNginxLuaConfigurationLua, map[string]*bintree{}}, + "sticky.lua": &bintree{etcNginxLuaStickyLua, map[string]*bintree{}}, "util.lua": &bintree{etcNginxLuaUtilLua, map[string]*bintree{}}, }}, "nginx.conf": &bintree{etcNginxNginxConf, map[string]*bintree{}}, diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 74d18cac1..4c2930a5f 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -193,6 +193,7 @@ func buildLuaSharedDictionaries(s interface{}, dynamicConfigurationEnabled bool, "lua_shared_dict locks 512k", "lua_shared_dict balancer_ewma 1M", "lua_shared_dict balancer_ewma_last_touched_at 1M", + "lua_shared_dict sticky_sessions 1M", ) } diff --git a/rootfs/etc/nginx/lua/balancer.lua b/rootfs/etc/nginx/lua/balancer.lua index 6e776efd2..a66573acc 100644 --- a/rootfs/etc/nginx/lua/balancer.lua +++ b/rootfs/etc/nginx/lua/balancer.lua @@ -5,6 +5,7 @@ local util = require("util") local lrucache = require("resty.lrucache") local resty_lock = require("resty.lock") local ewma = require("balancer.ewma") +local sticky = require("sticky") -- measured in seconds -- for an Nginx worker to pick up the new list of upstream peers @@ -48,6 +49,15 @@ end local function balance() local backend = get_current_backend() local lb_alg = get_current_lb_alg() + local is_sticky = sticky.is_sticky(backend) + + if is_sticky then + local endpoint = sticky.get_endpoint(backend) + if endpoint ~= nil then + return endpoint.address, endpoint.port + end + lb_alg = "round_robin" + end if lb_alg == "ip_hash" then -- TODO(elvinefendi) implement me @@ -77,6 +87,9 @@ local function balance() if forcible then ngx.log(ngx.WARN, "round_robin_state:set valid items forcibly overwritten") end + if is_sticky then + sticky.set_endpoint(endpoint, backend) + end round_robin_lock:unlock(backend.name .. ROUND_ROBIN_LOCK_KEY) return endpoint.address, endpoint.port diff --git a/rootfs/etc/nginx/lua/sticky.lua b/rootfs/etc/nginx/lua/sticky.lua new file mode 100644 index 000000000..c16b1af86 --- /dev/null +++ b/rootfs/etc/nginx/lua/sticky.lua @@ -0,0 +1,133 @@ +local json = require('cjson') +local str = require("resty.string") +local sha1_crypto = require("resty.sha1") +local md5_crypto = require("resty.md5") + +local sticky_sessions = ngx.shared.sticky_sessions + +local DEFAULT_SESSION_COOKIE_NAME = "route" +local DEFAULT_SESSION_COOKIE_HASH = "md5" +-- Currently STICKY_TIMEOUT never expires +local STICKY_TIMEOUT = 0 + +local _M = {} + +local function md5_digest(raw) + local md5 = md5_crypto:new() + if not md5 then + return nil, "md5: failed to create object" + end + local ok = md5:update(raw) + if not ok then + return nil, "md5: failed to add data" + end + local digest = md5:final() + if digest == nil then + return nil, "md5: failed to create digest" + end + return str.to_hex(digest), nil +end + +local function sha1_digest(raw) + local sha1 = sha1_crypto:new() + if not sha1 then + return nil, "sha1: failed to create object" + end + local ok = sha1:update(raw) + if not ok then + return nil, "sha1: failed to add data" + end + local digest = sha1:final() + if digest == nil then + return nil, "sha1: failed to create digest" + end + return str.to_hex(digest), nil +end + +local function get_cookie_name(backend) + local name = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["name"] + return name or DEFAULT_SESSION_COOKIE_NAME +end + +local function is_valid_endpoint(backend, address, port) + for _, ep in ipairs(backend.endpoints) do + if ep.address == address and ep.port == port then + return true + end + end + return false +end + +function _M.is_sticky(backend) + return backend["sessionAffinityConfig"]["name"] == "cookie" +end + +function _M.get_endpoint(backend) + local cookie_name = get_cookie_name(backend) + local cookie_key = "cookie_" .. cookie_name + local endpoint_key = ngx.var[cookie_key] + if endpoint_key == nil then + ngx.log(ngx.INFO, string.format( + "[backend=%s, affinity=cookie] cookie \"%s\" is not set for this request", + backend.name, + cookie_name + )) + return nil + end + + local endpoint_string = sticky_sessions:get(endpoint_key) + if endpoint_string == nil then + ngx.log(ngx.INFO, string.format("[backend=%s, affinity=cookie] no endpoint assigned", backend.name)) + return nil + end + + local endpoint = json.decode(endpoint_string) + local valid = is_valid_endpoint(backend, endpoint.address, endpoint.port) + if not valid then + ngx.log(ngx.INFO, string.format("[backend=%s, affinity=cookie] assigned endpoint is no longer valid", backend.name)) + sticky_sessions:delete(endpoint_key) + return nil + end + return endpoint +end + +function _M.set_endpoint(endpoint, backend) + local cookie_name = get_cookie_name(backend) + local encrypted, err + local endpoint_string = json.encode(endpoint) + local hash = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["hash"] + + if hash == "sha1" then + encrypted, err = sha1_digest(endpoint_string) + else + if hash ~= DEFAULT_SESSION_COOKIE_HASH then + ngx.log(ngx.WARN, string.format( + "[backend=%s, affinity=cookie] session-cookie-hash \"%s\" is not valid, defaulting to %s", + backend.name, + hash, + DEFAULT_SESSION_COOKIE_HASH + )) + end + encrypted, err = md5_digest(endpoint_string) + end + if err ~= nil then + ngx.log(ngx.WARN, string.format("[backend=%s, affinity=cookie] failed to assign endpoint: %s", backend.name, err)) + return + end + + ngx.log(ngx.INFO, string.format("[backend=%s, affinity=cookie] assigning a new endpoint", backend.name)) + ngx.header["Set-Cookie"] = cookie_name .. "=" .. encrypted .. ";" + local success, forcible + success, err, forcible = sticky_sessions:set(encrypted, endpoint_string, STICKY_TIMEOUT) + if not success then + ngx.log(ngx.WARN, string.format("[backend=%s, affinity=cookie] failed to assign endpoint: %s", backend.name, err)) + end + if forcible then + ngx.log(ngx.WARN, string.format( + "[backend=%s, affinity=cookie] sticky_sessions shared dict is full; endpoint forcibly overwritten", + backend.name + )) + end +end + +return _M diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go index 6a628d64d..0fda9ee7f 100644 --- a/test/e2e/e2e.go +++ b/test/e2e/e2e.go @@ -30,11 +30,11 @@ import ( "k8s.io/ingress-nginx/test/e2e/framework" // tests to run - _ "k8s.io/ingress-nginx/test/e2e/annotations" - _ "k8s.io/ingress-nginx/test/e2e/defaultbackend" + // _ "k8s.io/ingress-nginx/test/e2e/annotations" + // _ "k8s.io/ingress-nginx/test/e2e/defaultbackend" _ "k8s.io/ingress-nginx/test/e2e/lua" - _ "k8s.io/ingress-nginx/test/e2e/settings" - _ "k8s.io/ingress-nginx/test/e2e/ssl" + // _ "k8s.io/ingress-nginx/test/e2e/settings" + // _ "k8s.io/ingress-nginx/test/e2e/ssl" ) // RunE2ETests checks configuration parameters (specified through flags) and then runs diff --git a/test/e2e/lua/dynamic_configuration.go b/test/e2e/lua/dynamic_configuration.go index d1104d2fe..05ac8f947 100644 --- a/test/e2e/lua/dynamic_configuration.go +++ b/test/e2e/lua/dynamic_configuration.go @@ -19,6 +19,7 @@ package lua import ( "fmt" "net/http" + "regexp" "strings" "time" @@ -43,7 +44,7 @@ var _ = framework.IngressNginxDescribe("Dynamic Configuration", func() { err := enableDynamicConfiguration(f.KubeClientSet) Expect(err).NotTo(HaveOccurred()) - err = f.NewEchoDeploymentWithReplicas(1) + err = f.NewEchoDeploymentWithReplicas(3) Expect(err).NotTo(HaveOccurred()) host := "foo.com" @@ -75,115 +76,275 @@ var _ = framework.IngressNginxDescribe("Dynamic Configuration", func() { Expect(err).NotTo(HaveOccurred()) }) - Context("when only backends change", func() { - It("should handle endpoints only changes", func() { + // Context("when only backends change", func() { + // It("should handle endpoints only changes", func() { + // resp, _, errs := gorequest.New(). + // Get(fmt.Sprintf("%s?id=endpoints_only_changes", f.NginxHTTPURL)). + // Set("Host", "foo.com"). + // End() + // Expect(len(errs)).Should(BeNumerically("==", 0)) + // Expect(resp.StatusCode).Should(Equal(http.StatusOK)) + + // replicas := 2 + // err := framework.UpdateDeployment(f.KubeClientSet, f.Namespace.Name, "http-svc", replicas, + // func(deployment *appsv1beta1.Deployment) error { + // deployment.Spec.Replicas = framework.NewInt32(int32(replicas)) + // _, err := f.KubeClientSet.AppsV1beta1().Deployments(f.Namespace.Name).Update(deployment) + // return err + // }) + // Expect(err).NotTo(HaveOccurred()) + + // time.Sleep(5 * time.Second) + // log, err := f.NginxLogs() + // Expect(err).ToNot(HaveOccurred()) + // Expect(log).ToNot(BeEmpty()) + // index := strings.Index(log, "id=endpoints_only_changes") + // restOfLogs := log[index:] + + // By("POSTing new backends to Lua endpoint") + // Expect(restOfLogs).To(ContainSubstring("dynamic reconfiguration succeeded")) + // Expect(restOfLogs).ToNot(ContainSubstring("could not dynamically reconfigure")) + + // By("skipping Nginx reload") + // Expect(restOfLogs).ToNot(ContainSubstring("backend reload required")) + // Expect(restOfLogs).ToNot(ContainSubstring("ingress backend successfully reloaded")) + // Expect(restOfLogs).To(ContainSubstring("skipping reload")) + // Expect(restOfLogs).ToNot(ContainSubstring("first sync of Nginx configuration")) + // }) + + // It("should handle annotation changes", func() { + // ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{}) + // Expect(err).ToNot(HaveOccurred()) + + // ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/load-balance"] = "round_robin" + // _, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress) + // Expect(err).ToNot(HaveOccurred()) + + // time.Sleep(5 * time.Second) + // log, err := f.NginxLogs() + // Expect(err).ToNot(HaveOccurred()) + // Expect(log).ToNot(BeEmpty()) + // index := strings.Index(log, fmt.Sprintf("reason: 'UPDATE' Ingress %s/foo.com", f.Namespace.Name)) + // restOfLogs := log[index:] + + // By("POSTing new backends to Lua endpoint") + // Expect(restOfLogs).To(ContainSubstring("dynamic reconfiguration succeeded")) + // Expect(restOfLogs).ToNot(ContainSubstring("could not dynamically reconfigure")) + + // By("skipping Nginx reload") + // Expect(restOfLogs).ToNot(ContainSubstring("backend reload required")) + // Expect(restOfLogs).ToNot(ContainSubstring("ingress backend successfully reloaded")) + // Expect(restOfLogs).To(ContainSubstring("skipping reload")) + // Expect(restOfLogs).ToNot(ContainSubstring("first sync of Nginx configuration")) + // }) + // }) + + // It("should handle a non backend update", func() { + // ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{}) + // Expect(err).ToNot(HaveOccurred()) + + // ingress.Spec.TLS = []v1beta1.IngressTLS{ + // { + // Hosts: []string{"foo.com"}, + // SecretName: "foo.com", + // }, + // } + + // _, _, _, err = framework.CreateIngressTLSSecret(f.KubeClientSet, + // ingress.Spec.TLS[0].Hosts, + // ingress.Spec.TLS[0].SecretName, + // ingress.Namespace) + // Expect(err).ToNot(HaveOccurred()) + + // _, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress) + // Expect(err).ToNot(HaveOccurred()) + + // time.Sleep(5 * time.Second) + // log, err := f.NginxLogs() + // Expect(err).ToNot(HaveOccurred()) + // Expect(log).ToNot(BeEmpty()) + + // By("reloading Nginx") + // Expect(log).To(ContainSubstring("ingress backend successfully reloaded")) + + // By("POSTing new backends to Lua endpoint") + // Expect(log).To(ContainSubstring("dynamic reconfiguration succeeded")) + + // By("still be proxying requests through Lua balancer") + // err = f.WaitForNginxServer("foo.com", + // func(server string) bool { + // return strings.Contains(server, "proxy_pass http://upstream_balancer;") + // }) + // Expect(err).NotTo(HaveOccurred()) + + // By("generating the respective ssl listen directive") + // err = f.WaitForNginxServer("foo.com", + // func(server string) bool { + // return strings.Contains(server, "server_name foo.com") && + // strings.Contains(server, "listen 443") + // }) + // Expect(err).ToNot(HaveOccurred()) + // }) + + Context("when session affinity annotation is present", func() { + // It("should use sticky sessions when ingress rules are configured", func() { + // cookieName := "STICKYSESSION" + + // By("Updating affinity annotation on ingress") + // ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{}) + // Expect(err).ToNot(HaveOccurred()) + // ingress.ObjectMeta.Annotations = map[string]string{ + // "nginx.ingress.kubernetes.io/affinity": "cookie", + // "nginx.ingress.kubernetes.io/session-cookie-name": cookieName, + // } + // _, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress) + // Expect(err).ToNot(HaveOccurred()) + // time.Sleep(5 * time.Second) + + // By("Making a first request") + // host := "foo.com" + // resp, _, errs := gorequest.New(). + // Get(f.NginxHTTPURL). + // Set("Host", host). + // End() + // Expect(len(errs)).Should(BeNumerically("==", 0)) + // Expect(resp.StatusCode).Should(Equal(http.StatusOK)) + + // cookies := (*http.Response)(resp).Cookies() + // sessionCookie, err := getCookie(cookieName, cookies) + // Expect(err).ToNot(HaveOccurred()) + + // By("Making a second request with the previous session cookie") + // resp, _, errs = gorequest.New(). + // Get(f.NginxHTTPURL). + // AddCookie(sessionCookie). + // Set("Host", host). + // End() + // Expect(len(errs)).Should(BeNumerically("==", 0)) + // Expect(resp.StatusCode).Should(Equal(http.StatusOK)) + + // By("Making a third request with no cookie") + // resp, _, errs = gorequest.New(). + // Get(f.NginxHTTPURL). + // Set("Host", host). + // End() + + // Expect(len(errs)).Should(BeNumerically("==", 0)) + // Expect(resp.StatusCode).Should(Equal(http.StatusOK)) + + // log, err := f.NginxLogs() + // Expect(err).ToNot(HaveOccurred()) + // Expect(log).ToNot(BeEmpty()) + + // By("Checking that upstreams are sticky when session cookie is used") + // index := strings.Index(log, fmt.Sprintf("reason: 'UPDATE' Ingress %s/foo.com", f.Namespace.Name)) + // reqLogs := log[index:] + // re := regexp.MustCompile(`\d{1,3}(?:\.\d{1,3}){3}(?::\d{1,5})`) + // upstreams := re.FindAllString(reqLogs, -1) + // Expect(len(upstreams)).Should(BeNumerically("==", 3)) + // Expect(upstreams[0]).To(Equal(upstreams[1])) + // Expect(upstreams[1]).ToNot(Equal(upstreams[2])) + // }) + + // It("should NOT use sticky sessions when a default backend and no ingress rules configured", func() { + // By("Updating affinity annotation and rules on ingress") + // ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{}) + // Expect(err).ToNot(HaveOccurred()) + // ingress.Spec = v1beta1.IngressSpec{ + // Backend: &v1beta1.IngressBackend{ + // ServiceName: "http-svc", + // ServicePort: intstr.FromInt(80), + // }, + // } + // ingress.ObjectMeta.Annotations = map[string]string{ + // "nginx.ingress.kubernetes.io/affinity": "cookie", + // } + // _, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress) + // Expect(err).ToNot(HaveOccurred()) + // time.Sleep(5 * time.Second) + + // By("Making a request") + // host := "foo.com" + // resp, _, errs := gorequest.New(). + // Get(f.NginxHTTPURL). + // Set("Host", host). + // End() + // Expect(len(errs)).Should(BeNumerically("==", 0)) + // Expect(resp.StatusCode).Should(Equal(http.StatusOK)) + + // By("Ensuring no cookies are set") + // cookies := (*http.Response)(resp).Cookies() + // Expect(len(cookies)).Should(BeNumerically("==", 0)) + // }) + + It("should use sticky sessions when dynamic configuration is disabled", func() { + cookieName := "STICKYSESSION" + + By("Disabling dynamic configuration") + err := disableDynamicConfiguration(f.KubeClientSet) + Expect(err).NotTo(HaveOccurred()) + + By("Updating affinity annotation on ingress") + ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{}) + Expect(err).ToNot(HaveOccurred()) + ingress.ObjectMeta.Annotations = map[string]string{ + "nginx.ingress.kubernetes.io/affinity": "cookie", + "nginx.ingress.kubernetes.io/session-cookie-name": cookieName, + } + _, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress) + Expect(err).ToNot(HaveOccurred()) + time.Sleep(5 * time.Second) + + By("Making a first request") + host := "foo.com" resp, _, errs := gorequest.New(). - Get(fmt.Sprintf("%s?id=endpoints_only_changes", f.NginxHTTPURL)). - Set("Host", "foo.com"). + Get(f.NginxHTTPURL). + Set("Host", host). + End() + // Expect(len(errs)).Should(BeNumerically("==", 0)) + // Expect(resp.StatusCode).Should(Equal(http.StatusOK)) + // Expect(resp).To(BeNil()) + + log, err := f.NginxLogs() + Expect(err).ToNot(HaveOccurred()) + Expect(log).To(BeEmpty()) + + cookies := (*http.Response)(resp).Cookies() + sessionCookie, err := getCookie(cookieName, cookies) + Expect(err).ToNot(HaveOccurred()) + + By("Making a second request with the previous session cookie") + resp, _, errs = gorequest.New(). + Get(f.NginxHTTPURL). + AddCookie(sessionCookie). + Set("Host", host). End() Expect(len(errs)).Should(BeNumerically("==", 0)) Expect(resp.StatusCode).Should(Equal(http.StatusOK)) - replicas := 2 - err := framework.UpdateDeployment(f.KubeClientSet, f.Namespace.Name, "http-svc", replicas, - func(deployment *appsv1beta1.Deployment) error { - deployment.Spec.Replicas = framework.NewInt32(int32(replicas)) - _, err := f.KubeClientSet.AppsV1beta1().Deployments(f.Namespace.Name).Update(deployment) - return err - }) - Expect(err).NotTo(HaveOccurred()) + By("Making a third request with no cookie") + resp, _, errs = gorequest.New(). + Get(f.NginxHTTPURL). + Set("Host", host). + End() - time.Sleep(5 * time.Second) - log, err := f.NginxLogs() - Expect(err).ToNot(HaveOccurred()) - Expect(log).ToNot(BeEmpty()) - index := strings.Index(log, "id=endpoints_only_changes") - restOfLogs := log[index:] + Expect(len(errs)).Should(BeNumerically("==", 0)) + Expect(resp.StatusCode).Should(Equal(http.StatusOK)) - By("POSTing new backends to Lua endpoint") - Expect(restOfLogs).To(ContainSubstring("dynamic reconfiguration succeeded")) - Expect(restOfLogs).ToNot(ContainSubstring("could not dynamically reconfigure")) + // log, err := f.NginxLogs() + // Expect(err).ToNot(HaveOccurred()) + // Expect(log).ToNot(BeEmpty()) - By("skipping Nginx reload") - Expect(restOfLogs).ToNot(ContainSubstring("backend reload required")) - Expect(restOfLogs).ToNot(ContainSubstring("ingress backend successfully reloaded")) - Expect(restOfLogs).To(ContainSubstring("skipping reload")) - Expect(restOfLogs).ToNot(ContainSubstring("first sync of Nginx configuration")) - }) - - It("should handle annotation changes", func() { - ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{}) - Expect(err).ToNot(HaveOccurred()) - - ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/load-balance"] = "round_robin" - _, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress) - Expect(err).ToNot(HaveOccurred()) - - time.Sleep(5 * time.Second) - log, err := f.NginxLogs() - Expect(err).ToNot(HaveOccurred()) - Expect(log).ToNot(BeEmpty()) + By("Checking that upstreams are sticky when session cookie is used") index := strings.Index(log, fmt.Sprintf("reason: 'UPDATE' Ingress %s/foo.com", f.Namespace.Name)) - restOfLogs := log[index:] - - By("POSTing new backends to Lua endpoint") - Expect(restOfLogs).To(ContainSubstring("dynamic reconfiguration succeeded")) - Expect(restOfLogs).ToNot(ContainSubstring("could not dynamically reconfigure")) - - By("skipping Nginx reload") - Expect(restOfLogs).ToNot(ContainSubstring("backend reload required")) - Expect(restOfLogs).ToNot(ContainSubstring("ingress backend successfully reloaded")) - Expect(restOfLogs).To(ContainSubstring("skipping reload")) - Expect(restOfLogs).ToNot(ContainSubstring("first sync of Nginx configuration")) + reqLogs := log[index:] + re := regexp.MustCompile(`\d{1,3}(?:\.\d{1,3}){3}(?::\d{1,5})`) + upstreams := re.FindAllString(reqLogs, -1) + Expect(len(upstreams)).Should(BeNumerically("==", 3)) + Expect(upstreams[0]).To(Equal(upstreams[1])) + Expect(upstreams[1]).ToNot(Equal(upstreams[2])) }) }) - - It("should handle a non backend update", func() { - ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{}) - Expect(err).ToNot(HaveOccurred()) - - ingress.Spec.TLS = []v1beta1.IngressTLS{ - { - Hosts: []string{"foo.com"}, - SecretName: "foo.com", - }, - } - - _, _, _, err = framework.CreateIngressTLSSecret(f.KubeClientSet, - ingress.Spec.TLS[0].Hosts, - ingress.Spec.TLS[0].SecretName, - ingress.Namespace) - Expect(err).ToNot(HaveOccurred()) - - _, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress) - Expect(err).ToNot(HaveOccurred()) - - time.Sleep(5 * time.Second) - log, err := f.NginxLogs() - Expect(err).ToNot(HaveOccurred()) - Expect(log).ToNot(BeEmpty()) - - By("reloading Nginx") - Expect(log).To(ContainSubstring("ingress backend successfully reloaded")) - - By("POSTing new backends to Lua endpoint") - Expect(log).To(ContainSubstring("dynamic reconfiguration succeeded")) - - By("still be proxying requests through Lua balancer") - err = f.WaitForNginxServer("foo.com", - func(server string) bool { - return strings.Contains(server, "proxy_pass http://upstream_balancer;") - }) - Expect(err).NotTo(HaveOccurred()) - - By("generating the respective ssl listen directive") - err = f.WaitForNginxServer("foo.com", - func(server string) bool { - return strings.Contains(server, "server_name foo.com") && - strings.Contains(server, "listen 443") - }) - Expect(err).ToNot(HaveOccurred()) - }) }) func enableDynamicConfiguration(kubeClientSet kubernetes.Interface) error { @@ -252,3 +413,12 @@ func ensureIngress(f *framework.Framework, host string) (*extensions.Ingress, er }, }) } + +func getCookie(name string, cookies []*http.Cookie) (*http.Cookie, error) { + for _, cookie := range cookies { + if cookie.Name == name { + return cookie, nil + } + } + return &http.Cookie{}, fmt.Errorf("Cookie does not exist") +}