Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1856973

Summary: [RFE] Make it easier to access plan information in a hook container
Product: OpenShift Container Platform Reporter: Jason Montleon <jmontleo>
Component: Migration ToolingAssignee: Jason Montleon <jmontleo>
Status: CLOSED ERRATA QA Contact: Xin jiang <xjiang>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.4CC: mberube, rjohnson, sregidor, xjiang
Target Milestone: ---   
Target Release: 4.5.0   
Hardware: Unspecified   
OS: Unspecified   
URL: https://github.com/konveyor/mig-controller/pull/587
Whiteboard:
Fixed In Version: Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: 1856814 Environment:
Last Closed: 2020-09-30 18:42:32 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1856814    

Description Jason Montleon 2020-07-14 20:10:19 UTC
+++ This bug was initially created as a clone of Bug #1856814 +++

Description of problem:


Version-Release number of selected component (if applicable):
1.2.3

Actual results:
It takes a lot of work to get something like the list of namespaces for the plan when running a hook.

Expected results:
We should at least add the plan name as an env var so it can be looked up, if not also adding env vars for common resources like namespaces, and so on.

It shouldn't require doing something like below. And this is the easier case of your hook running on the controller cluster. If it's on the other cluster where the mig* resources don't exist it will be even more difficult.

Additional info:
To get namespaces looks like:
- hosts: localhost
  gather_facts: false
  tasks:
  - k8s_facts:
      kind: pods
      api: v1
      namespace: openshift-migration
      name: "{{ lookup( 'env', 'HOSTNAME') }}"
    register: pods
 
  - k8s_facts:
      kind: jobs
      api: batch/v1
      namespace: openshift-migration
      name: "{{ pods.resources[0].metadata.ownerReferences[0].name }}"
    register: jobs
 
  - k8s_facts:
      kind: jobs
      api: batch/v1
      namespace: openshift-migration
      name: "{{ pods.resources[0].metadata.ownerReferences[0].name }}"
    register: jobs
 
  - k8s_facts:
      kind: migmigration
      api: migration.openshift.io/v1alpha1
      namespace: openshift-migration
    register: migrations
 
  - set_fact:
      migmigration: "{{ item.metadata }}"
    with_items: "{{ migrations.resources }}"
    when: item.metadata.uid == jobs.resources[0].metadata.labels.owner
 
  - k8s_facts:
      kind: migplan
      api: migration.openshift.io/v1alpha1
      namespace: openshift-migration
      name: "{{ migmigration.ownerReferences[0].name }}"
    register: migplans
 
  - set_fact:
      namespaces: "{{ migplans.resources[0].spec.namespaces }}"
 
  - debug:
      msg: "{{ namespaces }}"

--- Additional comment from Jason Montleon on 2020-07-14 16:58:30 UTC ---

With https://github.com/konveyor/mig-controller/pull/587 the same can be achieved with:

- hosts: localhost
  gather_facts: false
  tasks:
  - debug:
      msg: "{{ (lookup( 'env', 'MIGRATION_NAMESPACES')).split(',') }}"

Comment 5 Sergio 2020-09-18 12:35:23 UTC
Verified in MTC 1.3

openshift-migration-rhel7-operator@sha256:233af9517407e792bbb34c58558346f2424b8b0ab54be6f12f9f97513e391a6a

Migrating a namespace with name "hooktests"

This works fine
- hosts: localhost
  gather_facts: false
  tasks:
  - set_fact:
      namespace: "{{ (lookup( 'env', 'MIGRATION_NAMESPACES')).split(',') }}"

  - debug: msg={{ namespace }}

  - fail:
      msg: "no namespace defined"
    when: namespace|first != "hooktests"


Moved to VERIFIED status.

Comment 9 errata-xmlrpc 2020-09-30 18:42:32 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Migration Toolkit for Containers (MTC) Tool image release advisory 1.3.0), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:4148