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

[kubernetes] Use KUBECONFIG if set #1716

Merged
merged 3 commits into from
Feb 5, 2024
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
12 changes: 10 additions & 2 deletions metaflow/plugins/kubernetes/kubernetes_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .kubernetes_job import KubernetesJob


CLIENT_REFRESH_INTERVAL_SECONDS = 300


Expand All @@ -32,11 +33,18 @@ def __init__(self):
def _refresh_client(self):
from kubernetes import client, config

if os.getenv("KUBERNETES_SERVICE_HOST"):
if os.getenv("KUBECONFIG"):
# There are cases where we're running inside a pod, but can't use
# the kubernetes client for that pod's cluster: for example when
# running in Bitbucket Cloud or other CI system.
# In this scenario, the user can set a KUBECONFIG environment variable
# to load the kubeconfig, regardless of whether we're in a pod or not.
config.load_kube_config()
elif os.getenv("KUBERNETES_SERVICE_HOST"):
# We are inside a pod, authenticate via ServiceAccount assigned to us
config.load_incluster_config()
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be a backwards incompatible change and will break many currently well functioning flows. do we expect KUBECONFIG env var to be always available?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be made backward compatible if the original call to config.load_kube_config in the else case is retained instead of throwing the KubernetesException.

# Use kubeconfig, likely $HOME/.kube/config
# Default to using kubeconfig, likely $HOME/.kube/config
# TODO (savin):
# 1. Support generating kubeconfig on the fly using boto3
# 2. Support auth via OIDC - https://docs.aws.amazon.com/eks/latest/userguide/authenticate-oidc-identity-provider.html
Expand Down
Loading