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

Add Individual Resource Verification Override #67

Merged
merged 9 commits into from
May 2, 2024

Conversation

HonakerM
Copy link
Collaborator

Related Issue

Supports #66

Related PRs

This PR helps support #64

What this PR does / why we need it

This PR allows users to override

Special notes for your reviewer

If applicable**

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

What gif most accurately describes how I feel towards this PR?

Example of a gif

Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
@gabe-l-hart
Copy link
Collaborator

@HonakerM I merged @pit1sIBM's job PR and it looks like that created conflicts. I also see tests failing at the moment. I'll keep an eye out for a push and review when ready!

Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
@HonakerM
Copy link
Collaborator Author

HonakerM commented May 2, 2024

@gabe-l-hart this is now readyto review!

Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

One debatable API breaking change and a couple of NITs. Thanks for adding all this!

@@ -39,6 +45,7 @@ def verify_resource(
# Use a predfined _SESSION_NAMESPACE default instead of None to differentiate between
# nonnamespaced resources (which pass None) and those that use session.namespace
namespace: Optional[str] = _SESSION_NAMESPACE,
verify_function: RESOURCE_VERIFY_FUNCTION = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: This should be Optional[RESOURCE_VERIFY_FUNCTION]. While you're at it, can you fix the other missing Optional[] type hints on the below args?


def __init__(self, name: str, manifest: dict):
def __init__(self, name: str, manifest: dict, verify_func: Callable = None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this use the full RESOURCE_VERIFY_FUNCTION signature rather than just Callable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Circular references :( I wasn't able to figure out a way to import verify_resources in the node dag.

@property
def manifest(self) -> str:
"""The resource manifest"""
return self.get_data()[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting. I wonder if having a Tuple returned from get_data is going to break anything. I think I might have at least one place where I've invoked get_data directly, so this could be seen as an API breaking change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!

@@ -10,7 +11,7 @@
class ManagedObject: # pylint: disable=too-many-instance-attributes
"""Basic struct to represent a managed kubernetes object"""

def __init__(self, definition):
def __init__(self, definition, verify_function: Callable = None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question about Callable here. Also, if you do change it, maybe throw a type hint on definition too!

@@ -282,3 +289,9 @@ def is_expected_reason() -> bool:
return obj_reason == expected_reason

return is_expected_status() and is_expected_reason()
return is_expected_status() and is_expected_reason()
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happened 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.

VS Code likes to autoformat things :( I think it removed a newline?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This diff shows six copies of the same return statement?

Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
@HonakerM HonakerM force-pushed the add_resource_verification branch from 8726eca to f5ea182 Compare May 2, 2024 21:13
Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

Looks good!

@HonakerM HonakerM force-pushed the add_resource_verification branch from 5f73d3a to 4275ad8 Compare May 2, 2024 21:37
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

One more nit pick!

return self.get_data()

@property
def verify_function(self) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Crap, one more NIT: The return on this should be Callable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! I will also fix the manifest section as well

Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
@gabe-l-hart gabe-l-hart merged commit d651383 into IBM:main May 2, 2024
6 checks passed
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.

2 participants