INNER CODE UNIT · Python
sc
IBM/AutoMLPipeline.jl · argo-workflow/agents/argo-k8s.py:44
def sc(context=current_kubectl_context):
try:
global current_kubectl_context
# First, switch the kubectl config context permanently
subprocess.run(
["kubectl", "config", "use-context", context],
capture_output=True,
text=True,
check=True,
)
logger.info(f"kubectl config switched to: {context}")
# Then load the kube config for Python client
config.load_kube_config(context=context)
initialize_clients() # Reinitialize clients with new context
current_kubectl_context = context # Track the current context globally
logger.info(f"Successfully switched to context: {context}")
return {"message": f"Switched to context: {context}"}