Created
October 24, 2018 22:35
-
-
Save sub-mod/b101556dda3ab7cb22117a690e9a79ef to your computer and use it in GitHub Desktop.
Remove load_incluster_config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openshift.dynamic import DynamicClient | |
from kubernetes.client import Configuration, ApiClient | |
from kubernetes.config.incluster_config import InClusterConfigLoader | |
import urllib3 | |
def load_incluster_config(environ): | |
"""Use the service account kubernetes gives to pods to connect to kubernetes | |
cluster. It's intended for clients that expect to be running inside a pod | |
running on kubernetes. It will raise an exception if called from a process | |
not running in a kubernetes environment.""" | |
InClusterConfigLoader(token_filename=environ["SERVICE_TOKEN_FILENAME"], | |
cert_filename=environ["SERVICE_CERT_FILENAME"], | |
environ=environ).load_and_set() | |
environ = { | |
"KUBERNETES_SERVICE_HOST": "paas.upshift.redhat.com", | |
"KUBERNETES_SERVICE_PORT": "443", | |
"SERVICE_TOKEN_FILENAME": "/Users/subin/development/aicoe/kubernetes.io/serviceaccount/token", | |
"SERVICE_CERT_FILENAME": "/Users/subin/development/aicoe/kubernetes.io/serviceaccount/ca.crt" | |
} | |
load_incluster_config() | |
configuration = Configuration() | |
configuration.verify_ssl = False | |
urllib3.disable_warnings() | |
configuration.assert_hostname = False | |
Configuration.set_default(configuration) | |
k8s_client = ApiClient() | |
dyn_client = DynamicClient(k8s_client) | |
v1_projects = dyn_client.resources.get(api_version='project.openshift.io/v1', kind='Project') | |
project_list = v1_projects.get() | |
for project in project_list.items: | |
print(project.metadata.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment