当前位置: 首页>>代码示例>>Python>>正文


Python client.V1ObjectMeta方法代码示例

本文整理汇总了Python中kubernetes.client.V1ObjectMeta方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1ObjectMeta方法的具体用法?Python client.V1ObjectMeta怎么用?Python client.V1ObjectMeta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kubernetes.client的用法示例。


在下文中一共展示了client.V1ObjectMeta方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_job_manifest

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def create_job_manifest(envs, commands, name, image, template_file):
    if template_file is not None:
        with open( template_file ) as f:
            job=yaml.safe_load(f)
            job["metadata"]["name"]=name
            job["spec"]["template"]["metadata"]["labels"]["app"]=name
            job["spec"]["template"]["spec"]["containers"][0]["image"]=image
            job["spec"]["template"]["spec"]["containers"][0]["command"]=commands
            job["spec"]["template"]["spec"]["containers"][0]["name"]=name
            job["spec"]["template"]["spec"]["containers"][0]["env"]=envs
            job["spec"]["template"]["spec"]["containers"][0]["command"]=commands
    else:
        container=client.V1Container(image=image, command=commands, name=name, env=envs)
        pod_temp=client.V1PodTemplateSpec(
                spec=client.V1PodSpec(restart_policy="OnFailure", containers=[container]),
                metadata=client.V1ObjectMeta(name=name, labels={"app":name})
                )
        job=client.V1Job(
                api_version="batch/v1",
                kind="Job",
                spec=client.V1JobSpec(template=pod_temp),
                metadata=client.V1ObjectMeta(name=name)
                )
    return job 
开发者ID:mlperf,项目名称:training_results_v0.6,代码行数:26,代码来源:kubernetes.py

示例2: create_job_object

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def create_job_object():
    # Configureate Pod template container
    container = client.V1Container(
        name="pi",
        image="perl",
        command=["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"])
    # Create and configurate a spec section
    template = client.V1PodTemplateSpec(
        metadata=client.V1ObjectMeta(labels={"app": "pi"}),
        spec=client.V1PodSpec(restart_policy="Never", containers=[container]))
    # Create the specification of deployment
    spec = client.V1JobSpec(
        template=template,
        backoff_limit=4)
    # Instantiate the job object
    job = client.V1Job(
        api_version="batch/v1",
        kind="Job",
        metadata=client.V1ObjectMeta(name=JOB_NAME),
        spec=spec)

    return job 
开发者ID:kubernetes-client,项目名称:python,代码行数:24,代码来源:job_crud.py

示例3: create_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def create_service():
    core_v1_api = client.CoreV1Api()
    body = client.V1Service(
        api_version="v1",
        kind="Service",
        metadata=client.V1ObjectMeta(
            name="service-example"
        ),
        spec=client.V1ServiceSpec(
            selector={"app": "deployment"},
            ports=[client.V1ServicePort(
                port=5678,
                target_port=5678
            )]
        )
    )
    # Creation of the Deployment in specified namespace
    # (Can replace "default" with a namespace you may have created)
    core_v1_api.create_namespaced_service(namespace="default", body=body) 
开发者ID:kubernetes-client,项目名称:python,代码行数:21,代码来源:ingress_create.py

示例4: pod_disruption_budget_for_service_instance

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def pod_disruption_budget_for_service_instance(
    service: str, instance: str, max_unavailable: Union[str, int],
) -> V1beta1PodDisruptionBudget:
    return V1beta1PodDisruptionBudget(
        metadata=V1ObjectMeta(
            name=get_kubernetes_app_name(service, instance), namespace="paasta",
        ),
        spec=V1beta1PodDisruptionBudgetSpec(
            max_unavailable=max_unavailable,
            selector=V1LabelSelector(
                match_labels={
                    "paasta.yelp.com/service": service,
                    "paasta.yelp.com/instance": instance,
                }
            ),
        ),
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:19,代码来源:kubernetes_tools.py

示例5: create_secret

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def create_secret(
    kube_client: KubeClient,
    secret: str,
    service: str,
    secret_provider: BaseSecretProvider,
) -> None:
    service = sanitise_kubernetes_name(service)
    sanitised_secret = sanitise_kubernetes_name(secret)
    kube_client.core.create_namespaced_secret(
        namespace="paasta",
        body=V1Secret(
            metadata=V1ObjectMeta(
                name=f"paasta-secret-{service}-{sanitised_secret}",
                labels={
                    "yelp.com/paasta_service": service,
                    "paasta.yelp.com/service": service,
                },
            ),
            data={
                secret: base64.b64encode(
                    secret_provider.decrypt_secret_raw(secret)
                ).decode("utf-8")
            },
        ),
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:27,代码来源:kubernetes_tools.py

示例6: update_kubernetes_secret_signature

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def update_kubernetes_secret_signature(
    kube_client: KubeClient, secret: str, service: str, secret_signature: str
) -> None:
    service = sanitise_kubernetes_name(service)
    secret = sanitise_kubernetes_name(secret)
    kube_client.core.replace_namespaced_config_map(
        name=f"paasta-secret-{service}-{secret}-signature",
        namespace="paasta",
        body=V1ConfigMap(
            metadata=V1ObjectMeta(
                name=f"paasta-secret-{service}-{secret}-signature",
                labels={
                    "yelp.com/paasta_service": service,
                    "paasta.yelp.com/service": service,
                },
            ),
            data={"signature": secret_signature},
        ),
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:21,代码来源:kubernetes_tools.py

示例7: create_kubernetes_secret_signature

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def create_kubernetes_secret_signature(
    kube_client: KubeClient, secret: str, service: str, secret_signature: str
) -> None:
    service = sanitise_kubernetes_name(service)
    secret = sanitise_kubernetes_name(secret)
    kube_client.core.create_namespaced_config_map(
        namespace="paasta",
        body=V1ConfigMap(
            metadata=V1ObjectMeta(
                name=f"paasta-secret-{service}-{secret}-signature",
                labels={
                    "yelp.com/paasta_service": service,
                    "paasta.yelp.com/service": service,
                },
            ),
            data={"signature": secret_signature},
        ),
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:20,代码来源:kubernetes_tools.py

示例8: test_get_kubernetes_metadata

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def test_get_kubernetes_metadata(self):
        with mock.patch(
            "paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_service",
            autospec=True,
            return_value="kurupt",
        ) as mock_get_service, mock.patch(
            "paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_instance",
            autospec=True,
            return_value="fm",
        ) as mock_get_instance:

            ret = self.deployment.get_kubernetes_metadata("aaa123")
            assert ret == V1ObjectMeta(
                labels={
                    "yelp.com/paasta_git_sha": "aaa123",
                    "yelp.com/paasta_instance": mock_get_instance.return_value,
                    "yelp.com/paasta_service": mock_get_service.return_value,
                    "paasta.yelp.com/git_sha": "aaa123",
                    "paasta.yelp.com/instance": mock_get_instance.return_value,
                    "paasta.yelp.com/service": mock_get_service.return_value,
                },
                name="kurupt-fm",
            ) 
开发者ID:Yelp,项目名称:paasta,代码行数:25,代码来源:test_kubernetes_tools.py

示例9: test_sanitize_for_config_hash

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def test_sanitize_for_config_hash(self):
        with mock.patch(
            "paasta_tools.kubernetes_tools.get_kubernetes_secret_hashes", autospec=True
        ) as mock_get_kubernetes_secret_hashes:
            mock_config = V1Deployment(
                metadata=V1ObjectMeta(name="qwe", labels={"mc": "grindah"}),
                spec=V1DeploymentSpec(
                    replicas=2,
                    selector=V1LabelSelector(match_labels={"freq": "108.9"}),
                    template=V1PodTemplateSpec(),
                ),
            )
            ret = self.deployment.sanitize_for_config_hash(mock_config)
            assert "replicas" not in ret["spec"].keys()
            assert (
                ret["paasta_secrets"] == mock_get_kubernetes_secret_hashes.return_value
            ) 
开发者ID:Yelp,项目名称:paasta,代码行数:19,代码来源:test_kubernetes_tools.py

示例10: test_get_annotations_for_kubernetes_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def test_get_annotations_for_kubernetes_service(
    mock_kube_deploy_config, has_persistent_volumes, expected_annotations
):
    mock_client = mock.Mock()
    mock_client.deployments.read_namespaced_stateful_set.return_value = V1StatefulSet(
        metadata=V1ObjectMeta(annotations={"I-am": "stateful_set"})
    )
    mock_client.deployments.read_namespaced_deployment.return_value = V1Deployment(
        metadata=V1ObjectMeta(annotations={"I-am": "deployment"})
    )
    mock_kube_deploy_config.get_sanitised_deployment_name.return_value = (
        "fake_k8s_service"
    )
    mock_kube_deploy_config.get_persistent_volumes.return_value = has_persistent_volumes
    mock_kube_deploy_config.format_kubernetes_app.return_value = mock.Mock()
    annotations = get_annotations_for_kubernetes_service(
        mock_client, mock_kube_deploy_config
    )
    assert annotations == expected_annotations 
开发者ID:Yelp,项目名称:paasta,代码行数:21,代码来源:test_kubernetes_tools.py

示例11: create_rolebinding

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def create_rolebinding(name, scope_name, id_token):
    api_version = 'rbac.authorization.k8s.io'
    scope = scope_name
    subject = k8s_client.V1Subject(kind='Group', name=scope, namespace=name)
    role_ref = k8s_client.V1RoleRef(api_group=api_version, kind='Role', name=name)
    meta = k8s_client.V1ObjectMeta(name=name, namespace=name)
    rolebinding = k8s_client.V1RoleBinding(metadata=meta, role_ref=role_ref, subjects=[subject])
    rbac_api_instance = get_k8s_rbac_api_client(id_token)

    try:
        response = rbac_api_instance.create_namespaced_role_binding(name, rolebinding)
    except ApiException as apiException:
        KubernetesCreateException('rolebinding', apiException)

    logger.info("Rolebinding {} created".format(name))
    return response 
开发者ID:IntelAI,项目名称:inference-model-manager,代码行数:18,代码来源:tenants_utils.py

示例12: install_github_secret

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def install_github_secret(api_client, namespace, secret_name, github_token):
  """Install Github secret on the cluster.
  Return:
    secret: Secret for Github token
  """
  logging.info("Install Github secret.")

  corev1_api = k8s_client.CoreV1Api(api_client)
  try:
    secret = k8s_client.V1Secret()
    secret.metadata = k8s_client.V1ObjectMeta(name=secret_name)
    secret.type = "Opaque"
    secret.data = {"GITHUB_TOKEN": github_token}

    corev1_api.create_namespaced_secret(namespace, secret)
  except rest.ApiException as e:
    # Status appears to be a string.
    if e.status == 409:
      logging.info("Github token has already been installed")
    else:
      raise 
开发者ID:aws-samples,项目名称:aws-eks-deep-learning-benchmark,代码行数:23,代码来源:install_github_secret.py

示例13: install_aws_secret

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def install_aws_secret(api_client, namespace, secret_name, aws_access_key_id, aws_secret_access_key):
  """Install AWS secret on the cluster.
  Return:
    secret: Secret for AWS credentials
  """
  logging.info("Install AWS secret %s", secret_name)

  corev1_api = k8s_client.CoreV1Api(api_client)
  try:
    secret = k8s_client.V1Secret()
    secret.metadata = k8s_client.V1ObjectMeta(name=secret_name)
    secret.type = "Opaque"
    secret.data = {
      "AWS_ACCESS_KEY_ID": aws_access_key_id,
      "AWS_SECRET_ACCESS_KEY": aws_secret_access_key
      }

    corev1_api.create_namespaced_secret(namespace, secret)
  except rest.ApiException as e:
    # Status appears to be a string.
    if e.status == 409:
      logging.info("Github token has already been installed")
    else:
      raise 
开发者ID:aws-samples,项目名称:aws-eks-deep-learning-benchmark,代码行数:26,代码来源:install_aws_secret.py

示例14: update_mutatingwebhookconfiguration

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def update_mutatingwebhookconfiguration(config, name, app, webhook_name, cert,
                                        service, path, namespace,
                                        failure_policy):
    config.metadata = k8sclient.V1ObjectMeta()
    config.metadata.name = name
    config.metadata.labels = {"app": app}
    client_config = k8sclient.AdmissionregistrationV1beta1WebhookClientConfig(
        ca_bundle=cert,
        service=k8sclient.AdmissionregistrationV1beta1ServiceReference(
            name=service,
            namespace=namespace,
            path=path))
    webhook = k8sclient.V1beta1Webhook(name=webhook_name,
                                       client_config=client_config,
                                       failure_policy=failure_policy)
    webhook.rules = [{
        "apiGroups": [""],
        "apiVersions": ["v1"],
        "operations": ["CREATE"],
        "resources": ["pods"]
    }]
    config.webhooks = [webhook] 
开发者ID:intel,项目名称:CPU-Manager-for-Kubernetes,代码行数:24,代码来源:clusterinit.py

示例15: ns_create

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ObjectMeta [as 别名]
def ns_create(namespace):
    """Create K8S namespace.

    Args:
        namespace (str): Name of namespace.
    """
    try:
        ns_read(namespace)
    except ApiException:
        ns = client.V1Namespace()
        ns.metadata = client.V1ObjectMeta(name=namespace)
        api.create_namespace(ns)
        logging.info(f'Created namespace "{namespace}"')
        logging.debug(pretty_print(json.dumps(ns.metadata, default=str)))


# TODO: Can we be more precise with the return type annotation? 
开发者ID:hyperledger-labs,项目名称:nephos,代码行数:19,代码来源:k8s.py


注:本文中的kubernetes.client.V1ObjectMeta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。