Skip to content

Commit be50c3c

Browse files
rimoliveDharmitD
authored andcommitted
Add optional field for the secret/configmap as env vars
Signed-off-by: ddalvi <[email protected]>
1 parent ddaac1e commit be50c3c

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

kubernetes_platform/go/kubernetesplatform/kubernetes_executor_config.pb.go

Lines changed: 32 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kubernetes_platform/proto/kubernetes_executor_config.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ message SecretAsEnv {
7373
}
7474

7575
repeated SecretKeyToEnvMap key_to_env = 2;
76+
// An optional boolean value indicating whether the Secret must be defined.
77+
optional bool optional = 3;
7678

7779
// Name of the Secret.
7880
ml_pipelines.TaskInputsSpec.InputParameterSpec secret_name_parameter = 4;
@@ -173,9 +175,11 @@ message ConfigMapAsEnv {
173175
}
174176

175177
repeated ConfigMapKeyToEnvMap key_to_env = 2;
178+
// An optional boolean value indicating whether the ConfigMap must be defined.
179+
optional bool optional = 3;
176180

177181
// Name of the ConfigMap.
178-
ml_pipelines.TaskInputsSpec.InputParameterSpec config_map_name_parameter = 3;
182+
ml_pipelines.TaskInputsSpec.InputParameterSpec config_map_name_parameter = 4;
179183
}
180184

181185
message GenericEphemeralVolume {

kubernetes_platform/python/kfp/kubernetes/config_map.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def use_config_map_as_env(
2424
task: PipelineTask,
2525
config_map_name: Union[pipeline_channel.PipelineParameterChannel, str],
2626
config_map_key_to_env: Dict[str, str],
27+
optional: bool = False,
2728
) -> PipelineTask:
2829
"""Use a Kubernetes ConfigMap as an environment variable as described by the `Kubernetes documentation
2930
https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data` _.
@@ -32,6 +33,7 @@ def use_config_map_as_env(
3233
task: Pipeline task.
3334
config_map_name: Name of the ConfigMap.
3435
config_map_key_to_env: Dictionary of ConfigMap key to environment variable name. For example, ``{'foo': 'FOO'}`` sets the value of the ConfigMap's foo field to the environment variable ``FOO``.
36+
optional: Optional field specifying whether the ConfigMap must be defined.
3537
3638
Returns:
3739
Task object with updated ConfigMap configuration.
@@ -45,7 +47,7 @@ def use_config_map_as_env(
4547
env_var=env_var,
4648
) for config_map_key, env_var in config_map_key_to_env.items()
4749
]
48-
config_map_as_env = pb.ConfigMapAsEnv(key_to_env=key_to_env)
50+
config_map_as_env = pb.ConfigMapAsEnv(key_to_env=key_to_env, optional=optional)
4951

5052
config_map_name_parameter = common.parse_k8s_parameter_input(config_map_name, task)
5153
config_map_as_env.config_map_name_parameter.CopyFrom(config_map_name_parameter)

kubernetes_platform/python/kfp/kubernetes/secret.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def use_secret_as_env(
2626
task: PipelineTask,
2727
secret_name: Union[pipeline_channel.PipelineParameterChannel, str],
2828
secret_key_to_env: Dict[str, str],
29+
optional: bool = False,
2930
) -> PipelineTask:
3031
"""Use a Kubernetes Secret as an environment variable as described by the `Kubernetes documentation
3132
https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables `_.
@@ -34,6 +35,7 @@ def use_secret_as_env(
3435
task: Pipeline task.
3536
secret_name: Name of the Secret.
3637
secret_key_to_env: Dictionary of Secret data key to environment variable name. For example, ``{'password': 'PASSWORD'}`` sets the data of the Secret's password field to the environment variable ``PASSWORD``.
38+
optional: Optional field specifying whether the Secret must be defined.
3739
3840
Returns:
3941
Task object with updated secret configuration.
@@ -47,7 +49,7 @@ def use_secret_as_env(
4749
env_var=env_var,
4850
) for secret_key, env_var in secret_key_to_env.items()
4951
]
50-
secret_as_env = pb.SecretAsEnv(key_to_env=key_to_env)
52+
secret_as_env = pb.SecretAsEnv(key_to_env=key_to_env, optional=optional)
5153

5254
secret_name_parameter = common.parse_k8s_parameter_input(secret_name, task)
5355
secret_as_env.secret_name_parameter.CopyFrom(secret_name_parameter)

0 commit comments

Comments
 (0)