-
Notifications
You must be signed in to change notification settings - Fork 305
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
Adds secret env_var #3048
Adds secret env_var #3048
Conversation
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Code Review Agent Run #f2a7e1Actionable Suggestions - 0Review Details
|
Changelist by BitoThis pull request implements the following key changes.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3048 +/- ##
==========================================
+ Coverage 77.44% 83.58% +6.14%
==========================================
Files 238 3 -235
Lines 23158 195 -22963
Branches 2760 0 -2760
==========================================
- Hits 17935 163 -17772
+ Misses 4412 32 -4380
+ Partials 811 0 -811 ☔ View full report in Codecov by Sentry. |
lgtm, tests will pass in this PR once this is merged right? flyteorg/flyte#6160 |
Yea and when a new flyteidl version is released. |
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Code Review Agent Run #7c9e36Actionable Suggestions - 0Review Details
|
…t_env_name Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Does it make sense to add an integration test (and leave it disabled while until we get a new Flyte sandbox version up)? At least you'll be able to validate that this works locally. |
Code Review Agent Run #4296d4Actionable Suggestions - 0Additional Suggestions - 10
Review Details
|
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Added integration test in bc9b040 (Which is skipped now) For it to be enabled, |
Code Review Agent Run #7b0105Actionable Suggestions - 3
Review Details
|
def get_secret() -> str: | ||
return current_context().secrets.get(group="my-group", key="token") |
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.
Consider adding error handling around current_context().secrets.get()
call to handle cases where the secret may not exist or be accessible.
Code suggestion
Check the AI-generated fix before applying
def get_secret() -> str: | |
return current_context().secrets.get(group="my-group", key="token") | |
def get_secret() -> str: | |
try: | |
return current_context().secrets.get(group="my-group", key="token") | |
except ValueError as e: | |
raise ValueError(f"Failed to retrieve secret: {str(e)}") |
Code Review Run #7b0105
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
subprocess.run([ | ||
"kubectl", | ||
"create", | ||
"secret", | ||
"-n", | ||
"flytesnacks-development", | ||
"generic", | ||
"my-group", | ||
f"--from-literal=token={secret}", | ||
], capture_output=True, text=True) | ||
yield secret | ||
|
||
# Remove secret | ||
subprocess.run([ | ||
"kubectl", | ||
"delete", | ||
"secrets", | ||
"-n", | ||
"flytesnacks-development", | ||
"my-group", | ||
], capture_output=True, text=True) |
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.
Consider handling potential errors from subprocess.run()
calls when creating and deleting the secret. The command could fail if kubectl is not installed or user lacks permissions.
Code suggestion
Check the AI-generated fix before applying
@@ -908,11 +908,14 @@
result = subprocess.run([
"kubectl",
"create",
"secret",
"-n",
"flytesnacks-development",
"generic",
"my-group",
f"--from-literal=token={secret}",
], capture_output=True, text=True)
+ if result.returncode != 0:
+ raise RuntimeError(f"Failed to create secret: {result.stderr}")
yield secret
# Remove secret
result = subprocess.run([
"kubectl",
"delete",
"secrets",
"-n",
"flytesnacks-development",
"my-group",
], capture_output=True, text=True)
+ if result.returncode != 0:
+ raise RuntimeError(f"Failed to delete secret: {result.stderr}")
Code Review Run #7b0105
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Code Review Agent Run #aa41e1Actionable Suggestions - 3
Review Details
|
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Code Review Agent Run #dcba26Actionable Suggestions - 0Review Details
|
Tracking issue
Related to flyteorg/flyte#6141 (comment)
Requires flyteorg/flyte#6160
Why are the changes needed?
This PR adds an env_var to the Secrets IDL, which has the follow behavior:
If mount_requirement is ENV_VAR, then we set an environment variable named env_name to the value of the secret.
If mount_requirement is FILE, then we set an environment variable named env_name to the path of the mounted secret.
What changes were proposed in this pull request?
This PR adds
env_name
to theSecrets IDL
. This makes it easy to configure a secret in a Flyte task. For example, one can easily set a hugging face secret:Or for secrets that require a file:
How was this patch tested?
I ran the following to try the two different modes:
Docs link
Summary by Bito
Enhanced Secret class in Flytekit implementing dual access methods (ENV_VAR and FILE) for secret management. Changes include renamed env_var parameter, improved functionality for direct secret value access, and core improvements to error handling. Added integration tests for Kubernetes secrets management with test fixtures and workflow demonstrations. This pull request also introduces an environment variable to the Secrets IDL, allowing secrets to be accessed as environment variables or file paths. It includes updates to integration tests for Kubernetes secrets with added checks for kubectl availability.Unit tests added: True
Estimated effort to review (1-5, lower is better): 5