-
Notifications
You must be signed in to change notification settings - Fork 77
feat: add aap_job_template_id support to Hook class #2759
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,5 @@ | ||||||||||||||||||||||||||||||||||
| import warnings | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| from ocp_resources.resource import NamespacedResource | ||||||||||||||||||||||||||||||||||
| from ocp_resources.utils.constants import TIMEOUT_4MINUTES | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -15,6 +17,7 @@ def __init__( | |||||||||||||||||||||||||||||||||
| namespace=None, | ||||||||||||||||||||||||||||||||||
| image="quay.io/konveyor/hook-runner:latest", | ||||||||||||||||||||||||||||||||||
| playbook=None, | ||||||||||||||||||||||||||||||||||
| aap_job_template_id=None, | ||||||||||||||||||||||||||||||||||
| client=None, | ||||||||||||||||||||||||||||||||||
| teardown=True, | ||||||||||||||||||||||||||||||||||
| yaml_file=None, | ||||||||||||||||||||||||||||||||||
|
|
@@ -25,6 +28,7 @@ def __init__( | |||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||
| image (str): Path to an ansible image | ||||||||||||||||||||||||||||||||||
| playbook (str): Ansible playbook to be performed | ||||||||||||||||||||||||||||||||||
| aap_job_template_id (int): AAP/AWX job template ID to trigger during hook execution | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| super().__init__( | ||||||||||||||||||||||||||||||||||
| name=name, | ||||||||||||||||||||||||||||||||||
|
|
@@ -35,15 +39,23 @@ def __init__( | |||||||||||||||||||||||||||||||||
| delete_timeout=delete_timeout, | ||||||||||||||||||||||||||||||||||
| **kwargs, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| if image == "quay.io/konveyor/hook-runner:latest": | ||||||||||||||||||||||||||||||||||
| warnings.warn( | ||||||||||||||||||||||||||||||||||
| "The default value for 'image' will be removed in the next release. Pass 'image' explicitly.", | ||||||||||||||||||||||||||||||||||
| DeprecationWarning, | ||||||||||||||||||||||||||||||||||
| stacklevel=2, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| self.image = image | ||||||||||||||||||||||||||||||||||
| self.playbook = playbook | ||||||||||||||||||||||||||||||||||
| self.aap_job_template_id = aap_job_template_id | ||||||||||||||||||||||||||||||||||
|
Comment on lines
1
to
+50
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a sentinel to distinguish "caller didn't pass
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def to_dict(self) -> None: | ||||||||||||||||||||||||||||||||||
| super().to_dict() | ||||||||||||||||||||||||||||||||||
| if not self.kind_dict and not self.yaml_file: | ||||||||||||||||||||||||||||||||||
| self.res.update({ | ||||||||||||||||||||||||||||||||||
| "spec": { | ||||||||||||||||||||||||||||||||||
| "image": self.image, | ||||||||||||||||||||||||||||||||||
| "playbook": self.playbook, | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| self.res["spec"] = {} | ||||||||||||||||||||||||||||||||||
| _spec = self.res["spec"] | ||||||||||||||||||||||||||||||||||
| if self.aap_job_template_id is not None: | ||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have here if;else?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and if you already modify the code here, switch to use the standatd approch for doing this for both please
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Hook CRD supports two mutually exclusive modes — playbook-based (spec.image + spec.playbook) and
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not block anything in code level, if it can sent to ocp api we send it, the ocp api will give the error if there is one.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if/else is needed here because We tested locally without the if/else and confirmed it fails. The two hook types have different spec shapes — it's not validation, just picking which fields to emit based on what the caller asked for. I did switch to the standard
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rnetser thinkg of removing the defult image, WDYT?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AmenB for now keep the if else and add a detraction warn about the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @myakove Added the deprecation warning. Note that it'll fire for every playbook hook that doesn't pass image explicitly — could be noisy. Want a different approach? |
||||||||||||||||||||||||||||||||||
| _spec["aap"] = {"jobTemplateId": self.aap_job_template_id} | ||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||
| _spec["image"] = self.image | ||||||||||||||||||||||||||||||||||
| _spec["playbook"] = self.playbook | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Positional args api break
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools