Skip to content

Commit

Permalink
new hook snippet and start of cli
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardHoch committed Dec 17, 2024
1 parent 0f1f957 commit c0e8df2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 68 deletions.
49 changes: 13 additions & 36 deletions documentation/modules/about-hook-crs-for-migration-plans-api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ You can use migration hooks to perform automated operations on a VM either befor
You can add hooks to a migration plan using either the {project-first} CLI or the {project-short} UI.

// You can add hooks to a migration plan from the command line by using the {project-full} API.

[id="default-hook-image_{context}"]
== Default hook image
The default hook image for an {project-short} hook is `registry.redhat.io/rhmtc/openshift-migration-hook-runner-rhel8:v1.8.2-2`. The image is based on the Ansible Runner image with the addition of `python-openshift` to provide Ansible Kubernetes resources and a recent `oc` binary.
The default hook image for an {project-short} hook is`quay.io/konveyor/hook-runner`. The image is based on the Ansible Runner image with the addition of `python-openshift` to provide Ansible Kubernetes resources and a recent `oc` binary.

[id="hook-execution_{context}"]
== Hook execution
Expand All @@ -32,46 +30,26 @@ When you add a hook, you must specify the namespace where the hook CR is located
In order for a hook to run on a VM, the VM must be started and available via SSH.
====


////
.Example PreHook:
[source,yaml]
----
kind: Plan
apiVersion: forklift.konveyor.io/v1beta1
metadata:
name: test
namespace: konveyor-forklift
spec:
vms:
- id: vm-2861
hooks:
- hook:
namespace: konveyor-forklift
name: playbook
step: PreHook
----
////

The illustration that follows shows the general process of using a migration hook. Specific procedures are described in TBD1 and TBD2.

[Figure]

Figure

Process:


. Input your Ansible hook and credentials.

** Input an Ansible pre-migration hook image or an Ansible post-migration hook image to the {project-short} controller using the CLI. This step is always done using the CLI, whether the rest of the migration is done using the CLI or the UI.

// Check text vs this content
can either specify the playbook in the Hook CRD or in the image itself. If the user specifies it in the image we use the playbook.yml and we set it to run it with the ansible-runner. Otherwise we keep it up to the users image what playbook is run but that needs to be specified in the image itself

.. Input an Ansible hook image to the {project-short} controller using either the UI or the CLI.
+
* In the UI, you specify the `ansible-runner` and enter the `playbook.yml` that contains the hook.
* In the CLI, you input the hook image, which specifies the playbook that runs the hook.

** If you need additional data to run the playbook inside the pod, create a Secret that contains credentials for the VM. The Secret is not mounted to the pod, but is called by the playbook.
.. If you need additional data to run the playbook inside the pod, such as SSH data, create a Secret that contains credentials for the VM. The Secret is not mounted to the pod, but is called by the playbook.
+
[NOTE]
====
This Secret is not the same as the `Secret` CR that contains the credentials of your source provider.
====

. The {project-short} controller creates the `configmap`, which contains:

Expand All @@ -84,7 +62,7 @@ The `configmap` contains the name of the VM and instructs the playbook what to d
. The {project-short} controller does the following:

** Creates a job that starts the user specified image.
** Mounts the `coinfig` map to the container.
** Mounts the `configmap` to the container.

+
The Ansible hook imports the Secret that the user previously
Expand All @@ -93,7 +71,6 @@ The Ansible hook imports the Secret that the user previously
** For a prehook, the job logs into the VMs on the source provider using SSH and runs the prehook.
** For a posthook, the job logs into the VMs on {virt} using SSH and runs the posthook.

// Next, 1 or 2 procedure modules based on the blog.



Expand Down
13 changes: 1 addition & 12 deletions documentation/modules/adding-hook-using-cli.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[id="adding-migration-hook-via-cli_{context}"]
= Adding a migration hook to a migration plan using the CLI

You can a migration hook to an existing migration plan. Although you can complete part of the procedure for adding the hook to migration plan by using either the CLI or UI, one step must be done using the CLi.
You can a migration hook to an existing migration plan using the {project-first} CLI.

.Prerequisites

Expand All @@ -20,18 +20,7 @@ You can a migration hook to an existing migration plan. Although you can complet
.Procedure

. Enter your hook by doing one of the following actions:

.. UI-based migration:

... In the {ocp} web console, click *Migration* > *Plans for virtualization* and then click the migration plan you want to add the hook to.
... Click *Hooks*.
... For a pre-migration hook, in the *Pre migration hook*, toggle the *Enable hook* switch.
... Enter the *Hook runner image*. The default image is `quay.io/konveyor/hook-runner` and this value must be used if you are adding an Ansible playbook.
... Paste your hook in *Ansible playbook*.
... For a post-migration hook, follow the same steps in the *Post migration hook* section.
... At the top of the tab, click *Update hooks*.
... In a terminal, enter following command:
+
[source,terminal,subs="attributes+"]
----
Expand Down
43 changes: 23 additions & 20 deletions documentation/modules/snip_example-hook-for-migration-plans.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,50 @@
.Example migration hook
[source,yaml,subs="attributes+"]
----
- hosts: vms
gather_facts: no
tasks:
- name: Wait 500 seconds <1>
wait_for_connection:
timeout: 500
- name: Main- name: Main
- name: Main
hosts: localhost
vars_files:
- plan.yml
- workload.yml
tasks:
- name: Load Plan
include_vars:
file: plan.yml
name: plan
- name: Load Workload
include_vars:
file: workload.yml
name: workload
- k8s_info:
api_version: v1
kind: Secret
name: privkey
namespace: openshift-mtv
register: ssh_credentials
- name: Ensure SSH directory exists
file:
path: ~/.ssh
state: directory
mode: 0750
- name: Create SSH key
copy:
dest: ~/.ssh/id_rsa
content: "{{ ssh_credentials.resources[0].data.key | b64decode }}"
mode: 0600
- add_host:
name: "{{ workload.vm.ipaddress }}"
name: "{{ workload.vm.ipaddress }}" # ALT "{{ workload.vm.guestnetworks[2].ip }}"
ansible_user: root
groups: vms
- hosts: vms
vars_files:
- plan.yml
- workload.yml
tasks:
- name: Stop MariaDB
service:
name: mariadb
state: stopped
- name: Create Test File
copy:
dest: ~/test.txt
content: "Hello World"
dest: /premigration.txt
content: "Migration from {{ provider.source.name }}
of {{ vm.vm1.vm0.id }} has finished\n"
mode: 0644
----
<1> Only required for post migration hooks.
----

0 comments on commit c0e8df2

Please sign in to comment.