providers/proxy: add sticky sessions to ingress

This commit is contained in:
Jens Langhammer 2020-10-29 17:25:51 +01:00
parent 6aaae53a19
commit f3df3a0157
1 changed files with 15 additions and 2 deletions

View File

@ -1,5 +1,5 @@
"""Kubernetes Ingress Reconciler""" """Kubernetes Ingress Reconciler"""
from typing import TYPE_CHECKING from typing import TYPE_CHECKING, Dict
from urllib.parse import urlparse from urllib.parse import urlparse
from kubernetes.client import ( from kubernetes.client import (
@ -67,11 +67,24 @@ class IngressReconciler(KubernetesObjectReconciler[NetworkingV1beta1Ingress]):
if have_hosts_tls != expected_hosts_tls: if have_hosts_tls != expected_hosts_tls:
raise NeedsUpdate() raise NeedsUpdate()
def get_ingress_annotations(self) -> Dict[str, str]:
"""Get ingress annotations"""
annotations = {
# Ensure that with multiple proxy replicas deployed, the same CSRF request
# goes to the same pod
"nginx.ingress.kubernetes.io/affinity": "cookie",
"traefik.ingress.kubernetes.io/affinity": "true",
}
annotations.update(
self.controller.outpost.config.kubernetes_ingress_annotations
)
return dict()
def get_reference_object(self) -> NetworkingV1beta1Ingress: def get_reference_object(self) -> NetworkingV1beta1Ingress:
"""Get deployment object for outpost""" """Get deployment object for outpost"""
meta = self.get_object_meta( meta = self.get_object_meta(
name=self.name, name=self.name,
annotations=self.controller.outpost.config.kubernetes_ingress_annotations, annotations=self.get_ingress_annotations(),
) )
rules = [] rules = []
tls_hosts = [] tls_hosts = []