From c0e8df299d9151e22dce784fc83dca053981cd7f Mon Sep 17 00:00:00 2001 From: RichardHoch Date: Tue, 17 Dec 2024 19:29:36 +0200 Subject: [PATCH] new hook snippet and start of cli --- ...bout-hook-crs-for-migration-plans-api.adoc | 49 +++++-------------- .../modules/adding-hook-using-cli.adoc | 13 +---- ...snip_example-hook-for-migration-plans.adoc | 43 ++++++++-------- 3 files changed, 37 insertions(+), 68 deletions(-) diff --git a/documentation/modules/about-hook-crs-for-migration-plans-api.adoc b/documentation/modules/about-hook-crs-for-migration-plans-api.adoc index 71fbf16b765..d88272deb54 100644 --- a/documentation/modules/about-hook-crs-for-migration-plans-api.adoc +++ b/documentation/modules/about-hook-crs-for-migration-plans-api.adoc @@ -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 @@ -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: @@ -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 @@ -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. diff --git a/documentation/modules/adding-hook-using-cli.adoc b/documentation/modules/adding-hook-using-cli.adoc index fda35ecb073..a5f8baa3a13 100644 --- a/documentation/modules/adding-hook-using-cli.adoc +++ b/documentation/modules/adding-hook-using-cli.adoc @@ -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 @@ -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+"] ---- diff --git a/documentation/modules/snip_example-hook-for-migration-plans.adoc b/documentation/modules/snip_example-hook-for-migration-plans.adoc index fd09684a401..fc8fd1f593a 100644 --- a/documentation/modules/snip_example-hook-for-migration-plans.adoc +++ b/documentation/modules/snip_example-hook-for-migration-plans.adoc @@ -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. \ No newline at end of file +---- \ No newline at end of file