本文整理汇总了Python中kubernetes.client.V1EnvVar方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1EnvVar方法的具体用法?Python client.V1EnvVar怎么用?Python client.V1EnvVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.V1EnvVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_container_env
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def get_container_env(self) -> Sequence[V1EnvVar]:
secret_env_vars = {}
shared_secret_env_vars = {}
for k, v in self.get_env().items():
if is_secret_ref(v):
if is_shared_secret(v):
shared_secret_env_vars[k] = v
else:
secret_env_vars[k] = v
user_env = [
V1EnvVar(name=name, value=value)
for name, value in self.get_env().items()
if name
not in list(secret_env_vars.keys()) + list(shared_secret_env_vars.keys())
]
user_env += self.get_kubernetes_secret_env_vars(
secret_env_vars=secret_env_vars,
shared_secret_env_vars=shared_secret_env_vars,
)
return user_env + self.get_kubernetes_environment() # type: ignore
示例2: get_kubernetes_environment
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def get_kubernetes_environment(self) -> Sequence[V1EnvVar]:
kubernetes_env = [
V1EnvVar(
name="PAASTA_POD_IP",
value_from=V1EnvVarSource(
field_ref=V1ObjectFieldSelector(field_path="status.podIP")
),
),
V1EnvVar(
# this is used by some functions of operator-sdk
# it uses this environment variable to get the pods
name="POD_NAME",
value_from=V1EnvVarSource(
field_ref=V1ObjectFieldSelector(field_path="metadata.name")
),
),
V1EnvVar(
name="PAASTA_HOST",
value_from=V1EnvVarSource(
field_ref=V1ObjectFieldSelector(field_path="spec.nodeName")
),
),
]
return kubernetes_env
示例3: test_get_kubernetes_secret_env_vars
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [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,
)
),
),
]
示例4: add_pod_env
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def add_pod_env(op: BaseOp) -> BaseOp:
"""Adds pod environment info to ContainerOp.
"""
if isinstance(op, ContainerOp) and op.pod_labels and 'add-pod-env' in op.pod_labels and op.pod_labels['add-pod-env'] == 'true':
from kubernetes import client as k8s_client
op.container.add_env_variable(
k8s_client.V1EnvVar(
name='KFP_POD_NAME',
value_from=k8s_client.V1EnvVarSource(
field_ref=k8s_client.V1ObjectFieldSelector(
field_path='metadata.name'
)
)
)
).add_env_variable(
k8s_client.V1EnvVar(
name='KFP_NAMESPACE',
value_from=k8s_client.V1EnvVarSource(
field_ref=k8s_client.V1ObjectFieldSelector(
field_path='metadata.namespace'
)
)
)
)
return op
示例5: volume_pipeline
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def volume_pipeline():
op1 = dsl.ContainerOp(
name='download',
image='google/cloud-sdk',
command=['sh', '-c'],
arguments=['ls | tee /tmp/results.txt'],
file_outputs={'downloaded': '/tmp/results.txt'}) \
.add_volume(k8s_client.V1Volume(name='gcp-credentials',
secret=k8s_client.V1SecretVolumeSource(
secret_name='user-gcp-sa'))) \
.add_volume_mount(k8s_client.V1VolumeMount(
mount_path='/secret/gcp-credentials', name='gcp-credentials')) \
.add_env_variable(k8s_client.V1EnvVar(
name='GOOGLE_APPLICATION_CREDENTIALS',
value='/secret/gcp-credentials/user-gcp-sa.json')) \
.add_env_variable(k8s_client.V1EnvVar(name='Foo', value='bar'))
op2 = dsl.ContainerOp(
name='echo',
image='library/bash',
command=['sh', '-c'],
arguments=['echo %s' % op1.output])
示例6: init_envs
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def init_envs(self, container_props, name):
config = container_props.config
config_dict = self.pre_process_config(config)
configmap_name = name
list_envs = []
for key in config_dict:
config_map_ref = client.V1ConfigMapKeySelector(
key=key,
name=configmap_name)
env_var = client.V1EnvVarSource(
config_map_key_ref=config_map_ref)
env_object = client.V1EnvVar(
name=key,
value_from=env_var)
list_envs.append(env_object)
return list_envs
# Init container object
示例7: create_ps_manifest
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def create_ps_manifest( ps_id, ps_num, job_name, envs, image, commands, template_file ):
envs.append( client.V1EnvVar( name="DMLC_SERVER_ID", value=ps_id ))
envs.append( client.V1EnvVar( name="DMLC_ROLE", value="server" ))
if job_name is not None:
name = "mx-" + job_name + "-server-" + ps_id
else:
name = "mx-server-" + ps_id
return create_job_manifest(envs, commands, name, image, template_file )
示例8: create_wk_manifest
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def create_wk_manifest( wk_id, wk_num, ps_num, job_name, envs, image, commands, template_file ):
envs.append( client.V1EnvVar( name="DMLC_WORKER_ID", value=wk_id ))
envs.append( client.V1EnvVar( name="DMLC_SERVER_ID", value="0" ))
envs.append( client.V1EnvVar( name="DMLC_ROLE", value="worker" ))
if job_name is not None:
name = "mx-" + job_name + "-worker-" + wk_id
else:
name = "mx-worker-" + wk_id
return create_job_manifest(envs, commands, name, image, template_file )
示例9: create_sched_job_manifest
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def create_sched_job_manifest( wk_num, ps_num, envs, image, commands):
envs.append( client.V1EnvVar( name="DMLC_ROLE", value="scheduler" ))
name = ""
for i in envs:
if i.name is "DMLC_PS_ROOT_URI":
name = i.value
break
return create_job_manifest(envs, commands, name, image, None )
示例10: create_env
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def create_env(root_uri, root_port, sv_num, wk_num ):
envs = []
envs.append( client.V1EnvVar( name="DMLC_PS_ROOT_URI", value=root_uri))
envs.append( client.V1EnvVar( name="DMLC_PS_ROOT_PORT", value=str(root_port)))
envs.append( client.V1EnvVar( name="DMLC_NUM_SERVER", value=str(sv_num)))
envs.append( client.V1EnvVar( name="DMLC_NUM_WORKER", value=str(wk_num)))
return envs
示例11: get_kubernetes_secret_env_vars
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [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
示例12: test_get_container_env
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def test_get_container_env(self):
with mock.patch(
"paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_env",
autospec=True,
return_value={
"mc": "grindah",
"dj": "beats",
"A": "SECRET(123)",
"B": "SHAREDSECRET(456)",
},
), mock.patch(
"paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_kubernetes_environment",
autospec=True,
return_value=[V1EnvVar(name="manager", value="chabuddy")],
), mock.patch(
"paasta_tools.kubernetes_tools.is_secret_ref", autospec=True
) as mock_is_secret_ref, mock.patch(
"paasta_tools.kubernetes_tools.is_shared_secret", autospec=True
) as mock_is_shared_secret, mock.patch(
"paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_kubernetes_secret_env_vars",
autospec=True,
return_value=[],
) as mock_get_kubernetes_secret_env_vars:
mock_is_secret_ref.side_effect = lambda x: True if "SECRET" in x else False
mock_is_shared_secret.side_effect = (
lambda x: False if not x.startswith("SHARED") else True
)
expected = [
V1EnvVar(name="mc", value="grindah"),
V1EnvVar(name="dj", value="beats"),
V1EnvVar(name="manager", value="chabuddy"),
]
assert expected == self.deployment.get_container_env()
mock_get_kubernetes_secret_env_vars.assert_called_with(
self.deployment,
secret_env_vars={"A": "SECRET(123)"},
shared_secret_env_vars={"B": "SHAREDSECRET(456)"},
)
示例13: create_job_object
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [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
示例14: update_ds_env
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def update_ds_env(self, ds, ns, env_vars):
config.load_kube_config(os.environ.get('KUBECONFIG'))
api = client.AppsV1Api(client.ApiClient())
node_ds = api.read_namespaced_daemon_set(ds, ns, exact=True, export=True)
for container in node_ds.spec.template.spec.containers:
if container.name == ds:
for k, v in env_vars.items():
logger.info("Set %s=%s", k, v)
env_present = False
for env in container.env:
if env.name == k:
env_present = True
if not env_present:
v1_ev = client.V1EnvVar(name=k, value=v, value_from=None)
container.env.append(v1_ev)
api.replace_namespaced_daemon_set(ds, ns, node_ds)
# Wait until the DaemonSet reports that all nodes have been updated.
while True:
time.sleep(10)
node_ds = api.read_namespaced_daemon_set_status("calico-node", "kube-system")
logger.info("%d/%d nodes updated",
node_ds.status.updated_number_scheduled,
node_ds.status.desired_number_scheduled)
if node_ds.status.updated_number_scheduled == node_ds.status.desired_number_scheduled:
break
示例15: _get_pod_spec
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1EnvVar [as 别名]
def _get_pod_spec(self):
container = k8sclient.V1Container(
name='fixture',
image=self._image,
command=self._get_cmd(),
env=[k8sclient.V1EnvVar(name=k, value=v) for k, v in self._env.iteritems()],
)
return k8sclient.V1PodSpec(
containers=[container]
)