Python kubernetes.client.VersionApi() Examples

The following are 5 code examples of kubernetes.client.VersionApi(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module kubernetes.client , or try the search function .
Example #1
Source File: kubeapi.py    From kqueen with MIT License 6 votes vote down vote up
def __init__(self, **kwargs):
        """
        Set cluster and prepare clients for all used resource types.

        Args:
            **kwargs: Keyword arguments (cluster is required)
        """
        # load configuration
        try:
            self.cluster = kwargs['cluster']
        except KeyError:
            raise ValueError('Missing parameter cluster')

        logger.debug('Initialized KubernetesAPI for {}'.format(self.cluster))

        # set apis
        api_client = self.get_api_client()

        self.api_corev1 = client.CoreV1Api(api_client=api_client)
        self.api_storagev1 = client.StorageV1Api(api_client=api_client)
        self.api_extensionsv1beta1 = client.ExtensionsV1beta1Api(api_client=api_client)
        self.api_version = client.VersionApi(api_client=api_client) 
Example #2
Source File: __init__.py    From k8s-handle with Apache License 2.0 5 votes vote down vote up
def _handler_provision(command, resources, priority_evaluator, use_kubeconfig, sync_mode, show_logs):
    kubeconfig_namespace = None

    if priority_evaluator.environment_deprecated():
        log.warning("K8S_HOST and K8S_CA environment variables support is deprecated "
                    "and will be discontinued in the future. Use K8S_MASTER_URI and K8S_CA_BASE64 instead.")

    # INFO rvadim: https://github.com/kubernetes-client/python/issues/430#issuecomment-359483997
    if use_kubeconfig:
        try:
            load_kube_config()
            kubeconfig_namespace = list_kube_config_contexts()[1].get('context').get('namespace')
        except Exception as e:
            raise RuntimeError(e)
    else:
        client.Configuration.set_default(priority_evaluator.k8s_client_configuration())

    settings.K8S_NAMESPACE = priority_evaluator.k8s_namespace_default(kubeconfig_namespace)
    log.info('Default namespace "{}"'.format(settings.K8S_NAMESPACE))

    if not settings.K8S_NAMESPACE:
        log.info("Default namespace is not set. "
                 "This may lead to provisioning error, if namespace is not set for each resource.")

    try:
        deprecation_checker = ApiDeprecationChecker(client.VersionApi().get_code().git_version[1:])
        available_checker = ResourceAvailabilityChecker(make_resource_getters_list())

        for resource in resources:
            deprecation_checker.run(resource)
            available_checker.run(resource)
    except client.api_client.ApiException:
        log.warning("Error while getting API version, deprecation check will be skipped.")

    provisioner = Provisioner(command, sync_mode, show_logs)

    for resource in resources:
        provisioner.run(resource) 
Example #3
Source File: k8s.py    From CPU-Manager-for-Kubernetes with Apache License 2.0 5 votes vote down vote up
def version_api_client_from_config(config):
    if config is None:
        k8sconfig.load_incluster_config()
        return k8sclient.VersionApi()
    else:
        client = k8sclient.ApiClient(configuration=config)
        return k8sclient.VersionApi(api_client=client) 
Example #4
Source File: manager.py    From polyaxon with Apache License 2.0 5 votes vote down vote up
def k8s_version_api(self):
        if not self._k8s_version_api:
            self._k8s_version_api = client.VersionApi(self.api_client)
        return self._k8s_version_api 
Example #5
Source File: ctx.py    From cc-utils with Apache License 2.0 5 votes vote down vote up
def create_version_api(self):
        cfg = self.get_kubecfg()
        return client.VersionApi(cfg)