Skip to content
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

Do not import kubernetes in flytekit core #3118

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

thomasjpfan
Copy link
Member

@thomasjpfan thomasjpfan commented Feb 7, 2025

Tracking issue

Follow up to #2943

Why are the changes needed?

Since flytekit does not depend on kubernetes, importing flytekit will not work anymore if kubernetes is not installed.

What changes were proposed in this pull request?

This PR moves the imports out of the top level and into the function.

How was this patch tested?

Built an image with this PR and not kubernetes and make sure it works:

from flytekit import ImageSpec, task

image = ImageSpec(registry="localhost:30000", copy=["flytekit"])


@task(container_image=image)
def hello() -> str:
    return "hello world"

Ideally we also have a CI job that does not have kubernetes installed to make sure flytekit still works.

Summary by Bito

Optimization of kubernetes dependency handling in Flytekit by making it optional and lightweight, while also enhancing the authentication system through factory pattern implementation and lazy loading capabilities. The changes include moving kubernetes-related imports to function scope, implementing environment variable validation in Secret class, and improving credential management with better refresh mechanisms.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 2

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 7, 2025

Code Review Agent Run #6680ec

Actionable Suggestions - 0
Additional Suggestions - 1
  • flytekit/core/resources.py - 1
Review Details
  • Files reviewed - 3 · Commit Range: 29a0748..29a0748
    • flytekit/core/resources.py
    • flytekit/core/task.py
    • flytekit/models/task.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 7, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Optimize Kubernetes Import Dependencies

resources.py - Moved kubernetes imports to function scope and added TYPE_CHECKING

task.py - Relocated kubernetes ApiClient import to class scope

pyproject.toml - Removed kubernetes dependency from project requirements

eapolinario
eapolinario previously approved these changes Feb 7, 2025
@eapolinario
Copy link
Collaborator

eapolinario commented Feb 7, 2025

what do you think of adding an extra called kubernetes (and require that package there)?

@thomasjpfan
Copy link
Member Author

what do you think of adding an extra called kubernetes (and require that package there)?

It's either flytekit[kubernetes] or flytekit[podt-emplate]. I like the second one more, since it's based on a flytekit feature.

@eapolinario
Copy link
Collaborator

what do you think of adding an extra called kubernetes (and require that package there)?

It's either flytekit[kubernetes] or flytekit[podt-emplate]. I like the second one more, since it's based on a flytekit feature.

agreed.

Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove kubernetes>=12.0.1 in pyproject.toml?
https://github.com/flyteorg/flytekit/blob/master/pyproject.toml#L36

@thomasjpfan
Copy link
Member Author

Ah I see. I did not know kubernetes was added as a dependency.

@thomasjpfan thomasjpfan closed this Feb 7, 2025
@eapolinario
Copy link
Collaborator

wait, we can still remove it, right? Adding a 2MB dependency that doesn't get used all the time seems like a waste.

@eapolinario
Copy link
Collaborator

another great argument for removing kubernetes as a dependency (again) is because it wasn't put back in an official release yet (as per 2da64ef - only 1.15 beta releases).

@thomasjpfan thomasjpfan reopened this Feb 7, 2025
@thomasjpfan
Copy link
Member Author

Updated PR to remove kubernetes as a direct dependency.

@@ -211,6 +211,7 @@ def task(
pod_template_name: Optional[str] = None,
accelerator: Optional[BaseAccelerator] = None,
pickle_untyped: bool = False,
new_kwargs: bool = False,
Copy link
Collaborator

@eapolinario eapolinario Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a leftover from a test you were running, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I forgot to remove this. I reverted the change.

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 7, 2025

Code Review Agent Run #860995

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 29a0748..ab627d2
    • pyproject.toml
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
Copy link

codecov bot commented Feb 8, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 76.06%. Comparing base (ef6d7d4) to head (0ec5b54).

Files with missing lines Patch % Lines
flytekit/models/task.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3118      +/-   ##
==========================================
- Coverage   76.08%   76.06%   -0.03%     
==========================================
  Files         203      203              
  Lines       21609    21609              
  Branches     2782     2782              
==========================================
- Hits        16442    16437       -5     
- Misses       4346     4349       +3     
- Partials      821      823       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 8, 2025

Code Review Agent Run #6dbf04

Actionable Suggestions - 0
Review Details
  • Files reviewed - 10 · Commit Range: ab627d2..0ec5b54
    • flytekit/clients/auth_helper.py
    • flytekit/clients/grpc_utils/auth_interceptor.py
    • flytekit/core/task.py
    • flytekit/models/security.py
    • pyproject.toml
    • tests/flytekit/unit/clients/auth/test_keyring_store.py
    • tests/flytekit/unit/clients/test_auth_helper.py
    • tests/flytekit/unit/clients/test_friendly.py
    • tests/flytekit/unit/clients/test_raw.py
    • tests/flytekit/unit/models/core/test_security.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@kumare3
Copy link
Contributor

kumare3 commented Feb 8, 2025

Can we just make sure we get a good error if it is not installed and needed at compile time. We can ask folks to install it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants