Skip to content

Conversation

@elbamit
Copy link
Contributor

@elbamit elbamit commented Dec 27, 2025

📝 Description

During import mlrun, authentication tokens stored locally in the igz.yml file are synced to Kubernetes and persisted as secrets. This PR prevents that synchronization from occurring when the code is executed from within a runtime.

To detect runtime execution, an environment variable MLRUN_RUNTIME_KIND is injected into the pods and used as the indicator. Its value is derived from the mlrun/class label.


🛠️ Changes Made

  • Refactor the _generate_runtime_env to include both the logic of nuclio's env generation function (_get_runtime_env) and the mlrun one used for other runtimes
  • Created a _generate_external_source_runtime_envs for non-static env vars such as MLRUN_RUNTIME_KIND
  • Created a _generate_k8s_runtime_env for k8s format
  • Update all callees of above functions accordingly
  • Created an is_running_in_runtime helper function
  • Updated the sync_secret_tokens to not run if inside a runtime

✅ Checklist

  • I updated the documentation (if applicable)
  • I have tested the changes in this PR
  • I confirmed whether my changes are covered by system tests
    • If yes, I ran all relevant system tests and ensured they passed before submitting this PR
    • I updated existing system tests and/or added new ones if needed to cover my changes
  • If I introduced a deprecation:

🧪 Testing

  • Refactor existing tests for kubejob, nuclio and dask
  • Refactor _get_pod_env_vars_as_dict used in test_submit because it assumed all external sources env vars are secret kind

🔗 References


🚨 Breaking Changes?

  • Yes (explain below)
  • No

🔍️ Additional Notes

…imes/nuclio/functions.py _get_runtime_env inside of it since they were duplicate functions. Also added the MLRUN_RUNTIME_KIND env var with a fieldRef to the mlrun/class label. Function is now able to return k8s format instead of casting the returned value later in many different places
Copy link
Member

@liranbg liranbg left a comment

Choose a reason for hiding this comment

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

preliminary review

def _generate_runtime_env(
self, runobj: RunObject = None, auth_info: mlrun.common.schemas.AuthInfo = None
) -> dict:
self, runobj: RunObject = None, return_k8s_format: bool = False
Copy link
Member

Choose a reason for hiding this comment

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

ideally, you want to have helper function to convern between formats - but, regardless this is a bit problematic because _generate_runtime_env may include valueFrom in which you wont be able to flatten. thus, I think we need to calibrate why we have some consumers using one way and other another way (perhaps diff between remote runtime and local runs). for that purpose, we need to move it to launchers or so.

… create _generate_k8s_runtime_env to get the kubernetes format. Change callees functions and tests accordingly.
@elbamit elbamit marked this pull request as ready for review January 6, 2026 08:02
@elbamit elbamit requested review from a team and TomerShor as code owners January 6, 2026 08:02
Copy link
Member

@liranbg liranbg left a comment

Choose a reason for hiding this comment

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

minor question/comment - lgtm

Comment on lines 449 to 453
if self.metadata.credentials.access_key:
runtime_env[
mlrun.common.runtimes.constants.FunctionEnvironmentVariables.auth_session
] = self.metadata.credentials.access_key

Copy link
Member

Choose a reason for hiding this comment

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

what's that for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +449 to +456
# Import here to avoid circular import
import mlrun.runtimes

# Set auth session only for nuclio runtimes that have an access key
if (
self.kind in mlrun.runtimes.RuntimeKinds.nuclio_runtimes()
and self.metadata.credentials.access_key
):
Copy link
Member

Choose a reason for hiding this comment

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

Would be fix on a following PR

@liranbg liranbg merged commit 01697a7 into mlrun:development Jan 7, 2026
13 checks passed
liranbg pushed a commit that referenced this pull request Jan 8, 2026
### 📝 Description

This is a following PR of #9121 that
fixes a circular import in the runtime module and removes the need for
function-level import.

`RuntimeKinds` was moved into a dedicated module
(`mlrun/runtimes/constants.py`) so it can be imported without pulling in
nuclio runtime modules. The nuclio resolver helpers
(`resolve_nuclio_runtime` / `resolve_nuclio_sub_kind`) cannot live in
`constants.py` because they depend on nuclio runtime classes (e.g.
`RemoteRuntime`), which import `base.py` and create an import cycle.

To preserve backwards compatibility, the resolvers remain available as:
`RuntimeKinds.resolve_nuclio_runtime` and
`RuntimeKinds.resolve_nuclio_sub_kind`,
implemented in `mlrun/runtimes/__init__.py` and attached as
`staticmethod`s.

---

### 🛠️ Changes Made
- Moved `RuntimeKinds` to `mlrun/runtimes/constants.py`
- Removed nuclio-related imports from `constants.py` to avoid import
cycles
- Implemented nuclio resolver helpers in `mlrun/runtimes/__init__.py`
- Kept the existing `RuntimeKinds.resolve_nuclio_*` API working via
`staticmethod` assignment

---

### ✅ Checklist
- [ ] I updated the documentation (if applicable)
- [ ] I have tested the changes in this PR
- [ ] I confirmed whether my changes are covered by system tests
- [ ] If yes, I ran all relevant system tests and ensured they passed
before submitting this PR
- [ ] I updated existing system tests and/or added new ones if needed to
cover my changes
- [ ] If I introduced a deprecation:
  - [ ] I followed the [Deprecation Guidelines](./DEPRECATION.md)
  - [ ] I updated the relevant Jira ticket for documentation

---

### 🧪 Testing
<!-- - How it was tested (unit tests, manual, integration) -->  
<!-- - Any special cases covered. -->  

---

### 🔗 References
- Ticket link: https://iguazio.atlassian.net/browse/ML-10519
- Design docs links:
- External links:

---

### 🚨 Breaking Changes?

- [ ] Yes (explain below)
- [ ] No

<!-- If yes, describe what needs to be changed downstream: -->

---

### 🔍️ Additional Notes
<!-- Anything else reviewers should know (follow-up tasks, known issues,
affected areas etc.). -->
<!-- ### 📸 Screenshots / Logs -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants