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
71 changes: 32 additions & 39 deletions ocp_resources/hook.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
from ocp_resources.resource import NamespacedResource
from ocp_resources.utils.constants import TIMEOUT_4MINUTES
import warnings
from typing import Any

from ocp_resources._hook_generated import Hook as _GeneratedHook

class Hook(NamespacedResource):
"""
Migration Tool for Virtualization (MTV) Plan's Hook Resource.
_UNSET = object()
_DEFAULT_IMAGE = "quay.io/konveyor/hook-runner:latest"


class Hook(_GeneratedHook):
"""
Deprecated shim for backward compatibility.

api_group = NamespacedResource.ApiGroup.FORKLIFT_KONVEYOR_IO
Preserves the legacy default-image behavior. New code should use
``from ocp_resources._hook_generated import Hook`` directly.
"""

def __init__(
self,
name=None,
namespace=None,
image="quay.io/konveyor/hook-runner:latest",
playbook=None,
client=None,
teardown=True,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
**kwargs,
):
"""
Args:
image (str): Path to an ansible image
playbook (str): Ansible playbook to be performed
"""
aap: dict[str, Any] | None = None,
deadline: int | None = None,
image: Any = _UNSET,
playbook: str | None = None,
service_account: str | None = None,
**kwargs: Any,
) -> None:
warnings.warn(
"Hook legacy defaults are deprecated and will be removed. "
"Pass image= explicitly for local hooks; use aap={...} for AAP hooks.",
DeprecationWarning,
stacklevel=2,
)
if image is _UNSET:
image = None if aap is not None else _DEFAULT_IMAGE
Comment thread
AmenB marked this conversation as resolved.
super().__init__(
name=name,
namespace=namespace,
client=client,
teardown=teardown,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
aap=aap,
deadline=deadline,
image=image,
playbook=playbook,
service_account=service_account,
**kwargs,
)
self.image = image
self.playbook = playbook

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,
},
})