Skip to content

Commit

Permalink
Create a repo for kubernetes-client/python#339
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewi committed Nov 14, 2017
1 parent d2975b5 commit c5ca3c1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
1 change: 0 additions & 1 deletion py/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def setup(args):
util.configure_kubectl(project, zone, cluster_name)

k8s_config.load_kube_config()

# Create an API client object to talk to the K8s master.
api_client = k8s_client.ApiClient()

Expand Down
1 change: 1 addition & 0 deletions py/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def build_and_push_artifacts(go_dir, src_dir, registry, publish_path=None,
]

if publish_path:
logging.info("GOOGLE_APPLICATION_CREDENTIALS=%s", os.getenv("GOOGLE_APPLICATION_CREDENTIALS", ""))
gcs_client = storage.Client(project=gcb_project)
bucket_name, base_path = util.split_gcs_uri(publish_path)
bucket = gcs_client.get_bucket(bucket_name)
Expand Down
54 changes: 49 additions & 5 deletions test-infra/airflow/dags/credentials_repo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
import google.auth
import google.auth.transport
import google.auth.transport.requests

import kubernetes
from kubernetes import client as k8s_client
from kubernetes import config as k8s_config
from kubernetes.config import kube_config
from kubernetes.client import ApiClient, ConfigurationObject, configuration
import os
print(os.getenv("GOOGLE_APPLICATION_CREDENTIALS", ""))
#credentials, project_id = google.auth.default(scopes=["https://www.googleapis.com/auth/userinfo.email"])
credentials, project_id = google.auth.default()
request = google.auth.transport.requests.Request()
credentials.refresh(request)
import yaml
from py import util

def load_kube_config(config_file=None, context=None,
client_configuration=configuration,
persist_config=True, **kwargs):
"""Loads authentication and cluster information from kube-config file
and stores them in kubernetes.client.configuration.
:param config_file: Name of the kube-config file.
:param context: set the active context. If is set to None, current_context
from config file will be used.
:param client_configuration: The kubernetes.client.ConfigurationObject to
set configs to.
:param persist_config: If True, config file will be updated when changed
(e.g GCP token refresh).
"""

if config_file is None:
config_file = os.path.expanduser(kube_config.KUBE_CONFIG_DEFAULT_LOCATION)

config_persister = None
if persist_config:
def _save_kube_config(config_map):
with open(config_file, 'w') as f:
yaml.safe_dump(config_map, f, default_flow_style=False)
config_persister = _save_kube_config

kube_config._get_kube_config_loader_for_yaml_file(
config_file, active_context=context,
client_configuration=client_configuration,
config_persister=config_persister, **kwargs).load_and_set()

def refresh_credentials():
#credentials, project_id = google.auth.default(scopes=["https://www.googleapis.com/auth/cloud-platform"])
credentials, project_id = google.auth.default(scopes=["https://www.googleapis.com/auth/userinfo.email"])
request = google.auth.transport.requests.Request()
credentials.refresh(request)
return credentials

refresh_credentials()
load_kube_config(get_google_credentials=refresh_credentials)
# Create an API client object to talk to the K8s master.
api_client = k8s_client.ApiClient()

0 comments on commit c5ca3c1

Please sign in to comment.