New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Backend + SDK): Update kfp backend and kubernetes sdk to support ConfigMaps as volumes and as env variables #10483
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d42bca0
Update kfp backend and kubernetes sdk to support ConfigMaps as volume…
roytman dcde0c0
update go.mod, apiserver.csv and driver.csv
roytman b395d10
add test/snapshot/data files
roytman 03015f3
fix tests
roytman c703e3d
go mod tidy
roytman ca26f84
update backend/third_party_licenses/apiserver.csv
roytman 8dff487
update backend/third_party_licenses/apiserver.csv
roytman fc44104
fix comments
roytman e989d04
fix comments
roytman 811d887
Merge branch 'master' into ConfigMapsSupport3
roytman 36daba6
update go.mod, apiserver.csv and driver.csv
roytman File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Copyright 2024 The Kubeflow Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Dict | ||
|
||
from google.protobuf import json_format | ||
from kfp.dsl import PipelineTask | ||
from kfp.kubernetes import common | ||
from kfp.kubernetes import kubernetes_executor_config_pb2 as pb | ||
|
||
|
||
def use_config_map_as_env( | ||
task: PipelineTask, | ||
config_map_name: str, | ||
config_map_key_to_env: Dict[str, str], | ||
) -> PipelineTask: | ||
"""Use a Kubernetes ConfigMap as an environment variable as described by the `Kubernetes documentation | ||
https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data` _. | ||
|
||
Args: | ||
task: Pipeline task. | ||
config_map_name: Name of the ConfigMap. | ||
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``. | ||
|
||
Returns: | ||
Task object with updated ConfigMap configuration. | ||
""" | ||
|
||
msg = common.get_existing_kubernetes_config_as_message(task) | ||
|
||
key_to_env = [ | ||
pb.ConfigMapAsEnv.ConfigMapKeyToEnvMap( | ||
config_map_key=config_map_key, | ||
env_var=env_var, | ||
) for config_map_key, env_var in config_map_key_to_env.items() | ||
] | ||
config_map_as_env = pb.ConfigMapAsEnv( | ||
config_map_name=config_map_name, | ||
key_to_env=key_to_env, | ||
) | ||
|
||
msg.config_map_as_env.append(config_map_as_env) | ||
|
||
task.platform_config['kubernetes'] = json_format.MessageToDict(msg) | ||
|
||
return task | ||
|
||
|
||
def use_config_map_as_volume( | ||
task: PipelineTask, | ||
config_map_name: str, | ||
mount_path: str, | ||
) -> PipelineTask: | ||
"""Use a Kubernetes ConfigMap by mounting its data to the task's container as | ||
described by the `Kubernetes documentation <https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume>`_. | ||
|
||
Args: | ||
task: Pipeline task. | ||
config_map_name: Name of the ConfigMap. | ||
mount_path: Path to which to mount the ConfigMap data. | ||
|
||
Returns: | ||
Task object with updated ConfigMap configuration. | ||
""" | ||
|
||
msg = common.get_existing_kubernetes_config_as_message(task) | ||
|
||
config_map_as_vol = pb.ConfigMapAsVolume( | ||
config_map_name=config_map_name, | ||
mount_path=mount_path, | ||
) | ||
msg.config_map_as_volume.append(config_map_as_vol) | ||
|
||
task.platform_config['kubernetes'] = json_format.MessageToDict(msg) | ||
|
||
return task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe we can refactor these two for loops into functions so that we can also reuse them for secret mount and secret env