diff --git a/ocp_resources/hook.py b/ocp_resources/hook.py index 2295cf7a07..23e75503ca 100644 --- a/ocp_resources/hook.py +++ b/ocp_resources/hook.py @@ -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): """ @@ -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, @@ -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, @@ -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 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: + _spec["aap"] = {"jobTemplateId": self.aap_job_template_id} + else: + # TODO: remove else once image default is deprecated; use conditional assignment instead + _spec["image"] = self.image + _spec["playbook"] = self.playbook