feat: add aap_job_template_id support to Hook class#2759
Conversation
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Cherry-pick Operations
Branch Management
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
AI Features
Security Checks
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
WalkthroughHook is replaced with a deprecated compatibility shim over the generated ChangesHook compatibility shim migration
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoAdd AAP/AWX job template support to MTV Hook resource
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1. Positional args API break
|
a19aa01 to
3f9a036
Compare
3f9a036 to
517e05f
Compare
|
/verified |
|
/lgtm |
| self.res["spec"] = {} | ||
| _spec = self.res["spec"] | ||
| if self.aap_job_template_id is not None: | ||
| _spec["aap"] = {"jobTemplateId": self.aap_job_template_id} |
There was a problem hiding this comment.
@myakove I think that we should get here app (as we do now with new generated resources). wdyt?
| }, | ||
| }) | ||
| self.res["spec"] = {} | ||
| _spec = self.res["spec"] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
No, we send what the caller passing us.
|
We're landing the schema-aligned generated Hook in a separate PR: #2765 (ocp_resources/_hook_generated.py Once #2765 (#2765) merges, please retarget this PR to:
Example shim shape: from ocp_resources._hook_generated import Hook as _GeneratedHook
_UNSET = object()
_DEFAULT_IMAGE = "quay.io/konveyor/hook-runner:latest"
class Hook(_GeneratedHook):
def __init__(self, aap=None, deadline=None, image=_UNSET, playbook=None, service_account=None, **kwargs):
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
super().__init__(
aap=aap,
deadline=deadline,
image=image,
playbook=playbook,
service_account=service_account,
**kwargs,
) MTV call site change: Hook(aap_job_template_id=9) → Hook(aap={"jobTemplateId": 9}). |
|
/hold |
|
AmenB is not part of the approver, only approvers can mark pull request with hold |
Add support for AAP (Ansible Automation Platform) hooks. When aap_job_template_id is set, to_dict() produces spec.aap.jobTemplateId instead of spec.image + spec.playbook. The two hook types are mutually exclusive. Also adds type annotations to all __init__ parameters.
Head branch was pushed to by a user without write access
0510388 to
15bbb54
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ocp_resources/hook.py`:
- Around line 27-34: In the hook initialization logic, move the
DeprecationWarning into the `if image is _UNSET:` block so explicitly supplied
images do not trigger it. Add the requested TODO in that block documenting
removal of the legacy fallback, while preserving the existing `aap`-dependent
image assignment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4be5a318-eba3-46dc-b17b-f6f49c227353
📒 Files selected for processing (1)
ocp_resources/hook.py
| 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 |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Move the deprecation warning inside the unset check and add the missing TODO.
Currently, the DeprecationWarning is emitted unconditionally. As pointed out in previous reviews, this means callers who explicitly pass image="quay.io/konveyor/hook-runner:latest" (or any other image) will still receive a warning instructing them to pass image=, which they already did. Additionally, the requested TODO comment to remove the fallback is missing.
Move the warning inside the if image is _UNSET: block to only warn when the legacy default behavior is invoked, and add the TODO comment.
💡 Proposed fix
- 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:
+ 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,
+ )
+ # TODO: remove this fallback once the `image` default is fully deprecated
image = None if aap is not None else _DEFAULT_IMAGE🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@ocp_resources/hook.py` around lines 27 - 34, In the hook initialization
logic, move the DeprecationWarning into the `if image is _UNSET:` block so
explicitly supplied images do not trigger it. Add the requested TODO in that
block documenting removal of the legacy fallback, while preserving the existing
`aap`-dependent image assignment.
Summary
Add
aap_job_template_idparameter to theHookclass, enabling MTV AAP hook integration — Hook CRs that trigger AWX/AAP job templates during migration instead of running playbooks in containers.What changed
aap_job_template_id=NoneonHook.__init__().to_dict():aap_job_template_idis set → producesspec.aap.jobTemplateId.spec.image+spec.playbook(existing behavior, unchanged).No regression — existing callers that don't pass
aap_job_template_idhit the original code path.Why
The
mtv-api-testsproject (branchfeat/aap-hook-integration) has a new AAP hook integration test that creates a Hook CR viaHook(aap_job_template_id=9). Without this wrapper change, it fails with:Confirmed by running the test against the current PyPI release (11.0.134).
Related Jira tickets
Polarion: MTV-781
Summary by CodeRabbit
aap), along withdeadline,image,playbook, andservice_account.spec.image/spec.playbook; serialization now follows the new input parameters.imagehandling changes: it is omitted for AAP hooks, and defaults are applied only when AAP is not set.