Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kube client on mac with keepalive enabled #15551

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions airflow/kubernetes/kube_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
# specific language governing permissions and limitations
# under the License.
"""Client for kubernetes communication"""
import logging
from typing import Optional

from airflow.configuration import conf

log = logging.getLogger(__name__)

try:
from kubernetes import client, config
from kubernetes.client import Configuration
Expand Down Expand Up @@ -89,12 +92,23 @@ def _enable_tcp_keepalive() -> None:
tcp_keep_intvl = conf.getint('kubernetes', 'tcp_keep_intvl')
tcp_keep_cnt = conf.getint('kubernetes', 'tcp_keep_cnt')

socket_options = [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, tcp_keep_idle),
(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, tcp_keep_intvl),
(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, tcp_keep_cnt),
]
socket_options = [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)]

if hasattr(socket, "TCP_KEEPIDLE"):
socket_options.append((socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, tcp_keep_idle))
else:
log.warning("Unable to set TCP_KEEPIDLE on this platform")

if hasattr(socket, "TCP_KEEPINTVL"):
socket_options.append((socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, tcp_keep_intvl))
else:
log.warning("Unable to set TCP_KEEPINTVL on this platform")

if hasattr(socket, "TCP_KEEPCNT"):
socket_options.append((socket.IPPROTO_TCP, socket.TCP_KEEPCNT, tcp_keep_cnt))
else:
log.warning("Unable to set TCP_KEEPCNT on this platform")

HTTPSConnection.default_socket_options = HTTPSConnection.default_socket_options + socket_options
HTTPConnection.default_socket_options = HTTPConnection.default_socket_options + socket_options

Expand Down