本文整理汇总了Python中kubernetes.client.CustomObjectsApi方法的典型用法代码示例。如果您正苦于以下问题:Python client.CustomObjectsApi方法的具体用法?Python client.CustomObjectsApi怎么用?Python client.CustomObjectsApi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.CustomObjectsApi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_instance
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def get_instance(spec, api_custom_objects=None, api_resources=None):
# due to https://github.com/kubernetes-client/python/issues/387
if spec.get('kind') in Adapter.kinds_builtin:
if spec.get('apiVersion') == 'test/test':
return AdapterBuiltinKind(spec, K8sClientMock(spec.get('metadata', {}).get('name')))
api = Adapter.api_versions.get(spec.get('apiVersion'))
if not api:
return None
return AdapterBuiltinKind(spec, api())
api_custom_objects = api_custom_objects or client.CustomObjectsApi()
api_resources = api_resources or ResourcesAPI()
return AdapterCustomKind(spec, api_custom_objects, api_resources)
示例2: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def __init__(self) -> None:
kube_config.load_kube_config(
config_file=os.environ.get("KUBECONFIG", KUBE_CONFIG_PATH),
context=os.environ.get("KUBECONTEXT"),
)
models.V1beta1PodDisruptionBudgetStatus.disrupted_pods = property(
fget=lambda *args, **kwargs: models.V1beta1PodDisruptionBudgetStatus.disrupted_pods(
*args, **kwargs
),
fset=_set_disrupted_pods,
)
self.deployments = kube_client.AppsV1Api()
self.core = kube_client.CoreV1Api()
self.policy = kube_client.PolicyV1beta1Api()
self.apiextensions = kube_client.ApiextensionsV1beta1Api()
self.custom = kube_client.CustomObjectsApi()
self.autoscaling = kube_client.AutoscalingV2beta1Api()
self.request = kube_client.ApiClient().request
示例3: create_custom_resource_definition
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def create_custom_resource_definition(self,
group: str,
version: str,
plural: str,
body: Union[str, dict],
namespace: Optional[str] = None
):
"""
Creates custom resource definition object in Kubernetes
:param group: api group
:type group: str
:param version: api version
:type version: str
:param plural: api plural
:type plural: str
:param body: crd object definition
:type body: Union[str, dict]
:param namespace: kubernetes namespace
:type namespace: str
"""
api = client.CustomObjectsApi(self.get_conn())
if namespace is None:
namespace = self.get_namespace()
if isinstance(body, str):
body = _load_body_to_dict(body)
try:
response = api.create_namespaced_custom_object(
group=group,
version=version,
namespace=namespace,
plural=plural,
body=body
)
self.log.debug("Response: %s", response)
return response
except client.rest.ApiException as e:
raise AirflowException("Exception when calling -> create_custom_resource_definition: %s\n" % e)
示例4: get_custom_resource_definition
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def get_custom_resource_definition(self,
group: str,
version: str,
plural: str,
name: str,
namespace: Optional[str] = None):
"""
Get custom resource definition object from Kubernetes
:param group: api group
:type group: str
:param version: api version
:type version: str
:param plural: api plural
:type plural: str
:param name: crd object name
:type name: str
:param namespace: kubernetes namespace
:type namespace: str
"""
custom_resource_definition_api = client.CustomObjectsApi(self.get_conn())
if namespace is None:
namespace = self.get_namespace()
try:
response = custom_resource_definition_api.get_namespaced_custom_object(
group=group,
version=version,
namespace=namespace,
plural=plural,
name=name
)
return response
except client.rest.ApiException as e:
raise AirflowException("Exception when calling -> get_custom_resource_definition: %s\n" % e)
示例5: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def __init__(self, bearer_token=None):
'''
Initialize connection to Kubernetes
'''
self.bearer_token = bearer_token
api_client = None
try:
config.load_incluster_config()
except config.config_exception.ConfigException:
config.load_kube_config()
if self.bearer_token:
# Configure API key authorization: Bearer Token
configuration = client.Configuration()
configuration.api_key_prefix['authorization'] = 'Bearer'
configuration.api_key['authorization'] = self.bearer_token
api_client = client.ApiClient(configuration)
self.client = client.CoreV1Api(api_client)
self.batch_api = client.BatchV1Api(api_client)
self.batch_v1beta1_api = client.BatchV1beta1Api(api_client)
self.custom_objects = client.CustomObjectsApi(api_client)
self.api_extensions = client.ApiextensionsV1beta1Api(api_client)
self.extension_api = client.ExtensionsV1beta1Api(api_client)
self.apps_v1_api = client.AppsV1Api(api_client)
示例6: _get_k8s_custom_objects_client
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def _get_k8s_custom_objects_client():
k8s_config.load_incluster_config()
return k8s.CustomObjectsApi()
示例7: get_k8s_api_custom_client
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def get_k8s_api_custom_client(id_token):
custom_obj_api_instance = client.CustomObjectsApi(get_simple_client(id_token))
return custom_obj_api_instance
示例8: get_k8s_custom_obj_client
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def get_k8s_custom_obj_client(configuration):
return client.CustomObjectsApi(K8sApiClient(configuration))
示例9: wait_for_benchmark_job
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def wait_for_benchmark_job(job_name, namespace, timeout_minutes=20, replicas=1):
"""Wait for benchmark to be complete.
Args:
namespace: The name space for the deployment.
job_name: The name of the benchmark workflow.
timeout_minutes: Timeout interval in minutes.
replicas: Number of replicas that must be running.
Returns:
deploy: The deploy object describing the deployment.
Raises:
TimeoutError: If timeout waiting for deployment to be ready.
"""
end_time = datetime.datetime.now() + datetime.timedelta(minutes=timeout_minutes)
config.load_kube_config()
crd_api = k8s_client.CustomObjectsApi()
GROUP = "argoproj.io"
VERSION = "v1alpha1"
PLURAL = "workflows"
while datetime.datetime.now() < end_time:
workflow = crd_api.get_namespaced_custom_object(GROUP, VERSION, namespace, PLURAL, job_name)
if workflow and workflow['status'] and workflow['status']['phase'] and workflow['status']['phase'] == "Succeeded":
logging.info("Job Completed")
return workflow
logging.info("Waiting for job %s:%s", namespace, job_name)
time.sleep(10)
logging.error("Timeout waiting for workflow %s in namespace %s to be "
"complete", job_name, namespace)
raise TimeoutError(
"Timeout waiting for deployment {0} in namespace {1}".format(
job_name, namespace))
示例10: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def __init__(self, token=None, ca_file=None, context=None, multus=True, host='127.0.0.1', port=443,
user='root', debug=False, tags=None, namespace=None, cdi=False, datavolumes=True, readwritemany=False):
Kubecommon.__init__(self, token=token, ca_file=ca_file, context=context, host=host, port=port,
namespace=namespace, readwritemany=readwritemany)
self.crds = client.CustomObjectsApi(api_client=self.api_client)
self.debug = debug
self.multus = multus
self.tags = tags
self.cdi = False
self.datavolumes = False
if cdi:
try:
cdipods = self.core.list_pod_for_all_namespaces(label_selector='app=containerized-data-importer').items
if cdipods:
for pod in cdipods:
if pod.metadata.name.startswith('cdi-deployment'):
self.cdinamespace = pod.metadata.namespace
self.cdi = True
if self.cdi and datavolumes:
try:
cm = self.core.read_namespaced_config_map('kubevirt-config', KUBEVIRTNAMESPACE)
if 'feature-gates' in cm.data and 'DataVolumes' in cm.data['feature-gates']:
self.datavolumes = True
except:
pass
except:
pass
return
示例11: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def __init__(self):
# Create Kubernetes config.
load_incluster_config()
config = Configuration()
config.debug = Settings.KUBERNETES_SERVICE_DEBUG
self.api_client = client.ApiClient(config)
# Re-usable API client instances.
self.core_api = client.CoreV1Api(self.api_client)
self.custom_objects_api = client.CustomObjectsApi(self.api_client)
self.extensions_api = client.ApiextensionsV1beta1Api(self.api_client)
self.apps_api = client.AppsV1beta1Api(self.api_client)
示例12: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def __init__(self, group, plural, version, client):
self.group = group
self.plural = plural
self.version = version
self.client = k8s_client.CustomObjectsApi(client)
示例13: k8s_custom_object_api
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def k8s_custom_object_api(self):
if not self._k8s_custom_object_api:
self._k8s_custom_object_api = client.CustomObjectsApi(self.api_client)
return self._k8s_custom_object_api
示例14: create_custom_api
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def create_custom_api(self):
cfg = self.get_kubecfg()
return client.CustomObjectsApi(cfg)
示例15: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import CustomObjectsApi [as 别名]
def __init__(self):
config.load_kube_config()
# Make v1 and cv1 as global pointer that can be called from anywhere when this class instantiated.
global v1
global cv1
v1 = client.CoreV1Api()
cv1 = client.CustomObjectsApi()