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

Remap image_pull_policy field on Container from ImagePullPolicy enum to str #877

Merged
merged 6 commits into from
Nov 23, 2023

Conversation

flaviuvadan
Copy link
Collaborator

Pull Request Checklist

Description of PR
When an autogenerated object is created through the service the service returns auto generated objects. This means the services relies on autogenerated code only. #784 documents how creating an autogen Workflow object fails because the value of Always does not fit the Template.container.imagePullPolicy field. This happens because the returned value is of type str (from the Argo Server) while the Python value is an enum of type ImagePullPolicy. This is caused by an inconsistency in the OpenAPI specification. Some fields use str for image pull policy (look at Events, User Container, etc) while Container uses ImagePullPolicy. This PR changes the field in the OpenAPI schema specification so that this Container field is also a str. This should solve #784. Our Pydantic configuration is set to use enum values, which means that users who rely on the autogen Container object and pass the ImagePullPolicy object in will have Pydantic automatically extract the .value field of that enum. The Hera objects already accommodate both str and ImagePullPolicy, so no breaking change there.

Signed-off-by: Flaviu Vadan <flaviuvadan@gmail.com>
@flaviuvadan flaviuvadan added semver:patch A change requiring a patch version bump type:bug A general bug labels Nov 23, 2023
@flaviuvadan
Copy link
Collaborator Author

Turns out autogen removes the ImagePullPolicy definition altogether, which is not the intended result..

Signed-off-by: Flaviu Vadan <flaviuvadan@gmail.com>
Signed-off-by: Flaviu Vadan <flaviuvadan@gmail.com>
@flaviuvadan
Copy link
Collaborator Author

Turns out autogen removes the ImagePullPolicy definition altogether, which is not the intended result..

Fixed

@flaviuvadan
Copy link
Collaborator Author

@vikramsg FYI ^

Signed-off-by: Flaviu Vadan <flaviuvadan@gmail.com>
Copy link

codecov bot commented Nov 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c2ef94b) 79.6% compared to head (8d18f61) 79.6%.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #877   +/-   ##
=====================================
  Coverage   79.6%   79.6%           
=====================================
  Files         45      45           
  Lines       3728    3728           
  Branches     758     758           
=====================================
  Hits        2970    2970           
  Misses       563     563           
  Partials     195     195           

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

@flaviuvadan flaviuvadan enabled auto-merge (squash) November 23, 2023 19:54
# { object name: { field name: ( ( existing field, existing value ) , ( new field, new value ) ) } }
INT_OR_STRING_FIELD_REMAPPING: Dict[str, Dict[str, Tuple[Tuple[str, str], Tuple[str, str]]]] = {
FIELD_REMAPPINGS: Dict[
str, Dict[str, Tuple[Tuple[str, Union[str, List[str]]], Optional[Tuple[str, Union[str, List[str]]]]]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure the type is helping at this point 😅 The comment is helpful enough, and longer term maybe we should create a helper class within this script?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea... I was very reluctant to add this type, especially as I realized it's growing. Yea, we'll have to refactor this a bit in the future.

"io.k8s.api.core.v1.Container": {
"imagePullPolicy": (
("enum", None),
None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's this None doing here? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

First part of the tuple says "original field, original field value" second one says "new field, new field value". New field value of None means delete the original field. So, this is removing the enum from Container, allowing codegen to put a string in place of the Container image pull policy enum, and stop generating the ImagePullPolicy enum altogether.

Later in the script you see we have to add a specification for IPP manually for otherwise it's not fully backwards compatible, even if it's not used by Container!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah of course, I was misreading the outer tuple. Makes sense (almost!), though I would suggest a refactor to helper classes if you have time/want to in a separate PR

Copy link
Collaborator

@elliotgunton elliotgunton left a comment

Choose a reason for hiding this comment

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

Maybe we add an issue for us to revisit/refactor spec.py? For now: :shipit:

@flaviuvadan flaviuvadan merged commit c8980bd into main Nov 23, 2023
16 checks passed
@flaviuvadan flaviuvadan deleted the fv/784 branch November 23, 2023 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:patch A change requiring a patch version bump type:bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation error when using Stored Template but job works fine
2 participants