Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions ocp_resources/hook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import warnings

from ocp_resources.resource import NamespacedResource
from ocp_resources.utils.constants import TIMEOUT_4MINUTES

_UNSET = object()


class Hook(NamespacedResource):
"""
Expand All @@ -13,8 +17,9 @@ def __init__(
self,
name=None,
namespace=None,
image="quay.io/konveyor/hook-runner:latest",
image=_UNSET,
playbook=None,
aap_job_template_id=None,
client=None,
teardown=True,
yaml_file=None,
Comment thread
AmenB marked this conversation as resolved.
Expand All @@ -25,6 +30,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,
Expand All @@ -35,15 +41,25 @@ def __init__(
delete_timeout=delete_timeout,
**kwargs,
)
if image is _UNSET:
warnings.warn(
"The default value for 'image' will be removed in the next release. Pass 'image' explicitly.",
DeprecationWarning,
stacklevel=2,
)
image = "quay.io/konveyor/hook-runner:latest" if aap_job_template_id is None else None
self.image = image
self.playbook = playbook
self.aap_job_template_id = aap_job_template_id
Comment thread
AmenB marked this conversation as resolved.

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"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can app and playbook \ image co-exist? iiuc, they cannot. while we do not validate that (the api should); we have opinionated ordering here - i.e if a user passes both, we give app presedence. @myakove wdyt?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i mean in other places, for new resources, we do not have the if-else option but let the api raise if a user passes mutually exlusive values, should we do it here as well?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No, we send what the caller passing us.

if self.aap_job_template_id is not None:
Comment thread
AmenB marked this conversation as resolved.
_spec["aap"] = {"jobTemplateId": self.aap_job_template_id}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@myakove I think that we should get here app (as we do now with new generated resources). wdyt?

else:
Comment thread
AmenB marked this conversation as resolved.
# TODO: remove else once image default is deprecated; use conditional assignment instead
_spec["image"] = self.image
_spec["playbook"] = self.playbook