-
Notifications
You must be signed in to change notification settings - Fork 111
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
Issue: Incorrect env
Structure in initContainers
Generated by Hera
#1155
Comments
Hi @shyoon-devops, thanks for reporting this! The reason |
Hi @flaviuvadan, thanks for the suggestion! I’ll start working on the code this week and should be able to submit a PR within a week. I’ll keep you updated! :) |
…bs#1155) Signed-off-by: sh.yoon <sh.yoon.devops@gmail.com>
…bs#1155) Signed-off-by: sh.yoon <sh.yoon.devops@gmail.com>
…bs#1155) Signed-off-by: sh.yoon <sh.yoon.devops@gmail.com>
…bs#1155) Signed-off-by: sh.yoon <sh.yoon.devops@gmail.com>
**Pull Request Checklist** - [x] Fixes #1155 - [ ] Tests added - [x] Documentation/examples added - [x] [Good commit messages](https://cbea.ms/git-commit/) and/or PR title **PR Description** When using Hera to generate an Argo Workflow, I encountered an issue with the env structure in initContainers. Specifically, the env variable references for secrets are not being properly constructed. Instead of the correct structure with valueFrom, the generated YAML output directly assigns secret_name and secret_key, which is not valid in Argo Workflows. This issue occurs because Hera doesn't handle this internally within its template constructors. Instead, it uses the `initContainers` as they are provided [here](https://github.com/argoproj-labs/hera/blob/main/src/hera/workflows/container.py#L87). To address this, I created the `_build_init_containers` method in the `TemplateMixin` class. ```python def _build_init_containers(self) -> Optional[List[ModelUserContainer]]: """Builds the `init_containers` field and optionally returns a list of `UserContainer`.""" if self.init_containers is None: return None return [i.build() if isinstance(i, UserContainer) else i for i in self.init_containers] ``` This method ensures that the `init_containers` field is correctly constructed, and if any of the containers are instances of `UserContainer`, they are properly built before being returned. Signed-off-by: sh.yoon <sh.yoon.devops@gmail.com> Co-authored-by: Sambhav Kothari <skothari44@bloomberg.net>
Pre-bug-report checklist
1. This bug can be reproduced using pure Argo YAML
If yes, it is more likely to be an Argo bug unrelated to Hera. Please double check before submitting an issue to Hera.
2. This bug occurs in Hera when...
Bug report
Summary
When using Hera to generate an Argo Workflow, I encountered an issue with the
env
structure ininitContainers
. Specifically, theenv
variable references for secrets are not being properly constructed. Instead of the correct structure withvalueFrom
, the generated YAML output directly assignssecret_name
andsecret_key
, which is not valid in Argo Workflows.Reproduction Steps
Here’s a minimal example to reproduce the issue:
Expected Behavior
The
env
section ininitContainers
should be generated as follows:Actual Behavior
However, the generated YAML output is incorrect:
Cause and Suggested Fix
The issue appears to be due to the
SecretEnv
object not being properly converted to the expected format within theinitContainers
.A workaround is to explicitly call
.build()
on theSecretEnv
object or manually define the environment variable usingm.EnvVar
as follows:This properly constructs the
env
section in the generated YAML.Environment
Conclusion
This issue likely stems from a bug in how Hera handles the conversion of
SecretEnv
objects withininitContainers
. I recommend reviewing this part of the code to ensure that the generated YAML adheres to the correct structure for Argo Workflows.Thank you for your attention to this matter.
The text was updated successfully, but these errors were encountered: