예제 #1
0
def sync_groups(oauth_token_path, sync_spec_path):
    config.load_incluster_config()
    ouserclient = UserOpenshiftIoV1Api()
    for name, members in build_origin_groups(oauth_token_path,
                                             sync_spec_path).items():
        existing_group = get_or_init_group(ouserclient, name)
        existing_group.users = members
        ouserclient.replace_user_openshift_io_v1_group(name, existing_group)
예제 #2
0
    def _get_client(self, context):
        try:
            conf = config.new_client_from_config(context=context)
        except FileNotFoundError:
            self.log.debug("Kubernetes config file not found, attempting "
                           "to load in-cluster configs")
            conf = config.load_incluster_config()

        return (
            k8s_client.CoreV1Api(conf),
            k8s_client.RbacAuthorizationV1beta1Api(conf))
예제 #3
0
import os.path
import re
from bitmath import parse_string_unsafe, GiB, MiB
from openshift import client,config
from kubernetes import config, client as kubeclient
from kubernetes.client.rest import ApiException
from pprint import pprint
from flask import Flask, render_template
application = Flask(__name__)

SERVICE_TOKEN_FILENAME = "/var/run/secrets/kubernetes.io/serviceaccount/token"

if os.path.isfile(SERVICE_TOKEN_FILENAME):
    config.load_incluster_config()
else:
    config.load_kube_config()


def to_bytes(value):
    return parse_string_unsafe(value).to_Byte().bytes

def to_mib(value):
    return MiB(bytes=to_bytes(value))

def to_gib(value):
    b = parse_string_unsafe(value).to_Byte().bytes
    return GiB(bytes=b)

def to_millicores(value):
    try:
        unit = re.split('([a-zA-Z]+)',value)
예제 #4
0
from openshift.config import load_incluster_config
from openshift.client.api_client import ApiClient
from openshift.dynamic import DynamicClient, ResourceInstance

service_account_path = '/var/run/secrets/kubernetes.io/serviceaccount'

with open(os.path.join(service_account_path, 'namespace')) as fp:
    namespace = fp.read().strip()

with open('/var/run/secrets/kubernetes.io/serviceaccount/namespace') as fp:
    namespace = fp.read().strip()

application_name = os.environ.get('APPLICATION_NAME')
service_account_name = '%s-%s-hub' % (application_name, namespace)

load_incluster_config()

api_client = DynamicClient(ApiClient())

pod_resource = api_client.resources.get(api_version='v1', kind='Pod')

service_account_resource = api_client.resources.get(api_version='v1',
                                                    kind='ServiceAccount')

project_resource = api_client.resources.get(
    api_version='project.openshift.io/v1', kind='Project')

role_binding_resource = api_client.resources.get(api_version='v1',
                                                 kind='RoleBinding')

project_cache = {}