本文整理汇总了Python中kubernetes.client.V1SecretKeySelector方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1SecretKeySelector方法的具体用法?Python client.V1SecretKeySelector怎么用?Python client.V1SecretKeySelector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.V1SecretKeySelector方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_kubernetes_secret_env_vars
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1SecretKeySelector [as 别名]
def test_get_kubernetes_secret_env_vars(self):
assert self.deployment.get_kubernetes_secret_env_vars(
secret_env_vars={"SOME": "SECRET(a_ref)"},
shared_secret_env_vars={"A": "SHAREDSECRET(_ref1)"},
) == [
V1EnvVar(
name="SOME",
value_from=V1EnvVarSource(
secret_key_ref=V1SecretKeySelector(
name="paasta-secret-kurupt-a--ref", key="a_ref", optional=False
)
),
),
V1EnvVar(
name="A",
value_from=V1EnvVarSource(
secret_key_ref=V1SecretKeySelector(
name="paasta-secret-underscore-shared-underscore-ref1",
key="_ref1",
optional=False,
)
),
),
]
示例2: get_kubernetes_secret_env_vars
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1SecretKeySelector [as 别名]
def get_kubernetes_secret_env_vars(
self,
secret_env_vars: Mapping[str, str],
shared_secret_env_vars: Mapping[str, str],
) -> Sequence[V1EnvVar]:
ret = []
for k, v in secret_env_vars.items():
service = self.get_sanitised_service_name()
secret = get_secret_name_from_ref(v)
sanitised_secret = sanitise_kubernetes_name(secret)
ret.append(
V1EnvVar(
name=k,
value_from=V1EnvVarSource(
secret_key_ref=V1SecretKeySelector(
name=f"paasta-secret-{service}-{sanitised_secret}",
key=secret,
optional=False,
)
),
)
)
for k, v in shared_secret_env_vars.items():
service = sanitise_kubernetes_name(SHARED_SECRET_SERVICE)
secret = get_secret_name_from_ref(v)
sanitised_secret = sanitise_kubernetes_name(secret)
ret.append(
V1EnvVar(
name=k,
value_from=V1EnvVarSource(
secret_key_ref=V1SecretKeySelector(
name=f"paasta-secret-{service}-{sanitised_secret}",
key=secret,
optional=False,
)
),
)
)
return ret
示例3: create_job_object
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1SecretKeySelector [as 别名]
def create_job_object(runner_image, region, s3_path, pvc_name):
target_folder = get_target_folder(s3_path)
# Configureate Pod template container
container = k8s_client.V1Container(
name="copy-dataset-worker",
image=runner_image,
command=["aws"],
args=["s3", "sync", s3_path, "/mnt/" + target_folder],
volume_mounts=[k8s_client.V1VolumeMount(name="data-storage", mount_path='/mnt')],
env=[k8s_client.V1EnvVar(name="AWS_REGION", value=region),
k8s_client.V1EnvVar(name="AWS_ACCESS_KEY_ID", value_from=k8s_client.V1EnvVarSource(secret_key_ref=k8s_client.V1SecretKeySelector(key="AWS_ACCESS_KEY_ID", name="aws-secret"))),
k8s_client.V1EnvVar(name="AWS_SECRET_ACCESS_KEY", value_from=k8s_client.V1EnvVarSource(secret_key_ref=k8s_client.V1SecretKeySelector(key="AWS_SECRET_ACCESS_KEY", name="aws-secret")))
],
)
volume = k8s_client.V1Volume(
name='data-storage',
persistent_volume_claim=k8s_client.V1PersistentVolumeClaimVolumeSource(claim_name=pvc_name)
)
# Create and configurate a spec section
template = k8s_client.V1PodTemplateSpec(
# metadata=k8s_client.V1ObjectMeta(labels={"app":"copy-dataset-worker"}),
spec=k8s_client.V1PodSpec(containers=[container], volumes=[volume], restart_policy="OnFailure"))
# Create the specification of deployment
spec = k8s_client.V1JobSpec(
# selector=k8s_client.V1LabelSelector(match_labels={"app":"copy-dataset-worker"}),
template=template)
# Instantiate the deployment object
deployment = k8s_client.V1Job(
api_version="batch/v1",
kind="Job",
metadata=k8s_client.V1ObjectMeta(name=container.name),
spec=spec)
return deployment
示例4: test_secret_key_ref
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1SecretKeySelector [as 别名]
def test_secret_key_ref(self):
service_account = self.cluster_object.spec.backups.gcs.service_account
expected = V1ServiceAccountRef(secret_key_ref=V1SecretKeySelector(name="storage-serviceaccount", key="json"))
self.assertEqual(expected, service_account)
示例5: use_aws_secret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1SecretKeySelector [as 别名]
def use_aws_secret(secret_name='aws-secret', aws_access_key_id_name='AWS_ACCESS_KEY_ID', aws_secret_access_key_name='AWS_SECRET_ACCESS_KEY'):
"""An operator that configures the container to use AWS credentials.
AWS doesn't create secret along with kubeflow deployment and it requires users
to manually create credential secret with proper permissions.
---
apiVersion: v1
kind: Secret
metadata:
name: aws-secret
type: Opaque
data:
AWS_ACCESS_KEY_ID: BASE64_YOUR_AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: BASE64_YOUR_AWS_SECRET_ACCESS_KEY
"""
def _use_aws_secret(task):
from kubernetes import client as k8s_client
(
task.container
.add_env_variable(
k8s_client.V1EnvVar(
name='AWS_ACCESS_KEY_ID',
value_from=k8s_client.V1EnvVarSource(
secret_key_ref=k8s_client.V1SecretKeySelector(
name=secret_name,
key=aws_access_key_id_name
)
)
)
)
.add_env_variable(
k8s_client.V1EnvVar(
name='AWS_SECRET_ACCESS_KEY',
value_from=k8s_client.V1EnvVarSource(
secret_key_ref=k8s_client.V1SecretKeySelector(
name=secret_name,
key=aws_secret_access_key_name
)
)
)
)
)
return task
return _use_aws_secret