Skip to content

Commit

Permalink
MTV plan execution workflow (#273)
Browse files Browse the repository at this point in the history
Signed-off-by: Yaron Dayagi <[email protected]>
  • Loading branch information
ydayagi authored Jun 30, 2024
1 parent 49c070f commit 36196d2
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/mtv-migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: MTV Migration workflow container image and manifest push

on:
workflow_dispatch:
push:
branches: ["main"]
paths:
- "mtv-migration/**"
- "pipeline/**"
- .github/workflows/mtv-migration.yml
- .github/workflows/main.yml

jobs:
call-main-workflow:
uses: ./.github/workflows/main.yml
with:
workflow_id: mtv-migration
secrets: inherit
26 changes: 26 additions & 0 deletions mtv-migration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# MTV migration workflow - MTV Migration execution workflow
This workflow is a continuation of the MTV assessment workflow. It executes an MTV Plan and waits for its final condition. Final condition is either success or failure. It is important to note that we rely on MTV to reach a final state. We do not impose our own timeout.
[MTV Migration Plan documentation](https://docs.redhat.com/en/documentation/migration_toolkit_for_virtualization/2.6/html/installing_and_using_the_migration_toolkit_for_virtualization/migrating-vms-web-console_mtv#creating-migration-plans-ui)

## Prerequisite
* Access to an OCP cluster with MTV operator (Openshift Migration Toolkit for Virtualization) installed. The cluster credentials must allow creating the resources listed above.

## Workflow diagram
![MTV Migration workflow diagram](https://github.com/parodos-dev/serverless-workflows/blob/main/mtv-migration/mtv.svg?raw=true)

## Application configuration
Application properties can be initialized from environment variables before running the application:

| Environment variable | Description | Mandatory | Default value |
|-----------------------|-------------|-----------|---------------|
| `OCP_API_SERVER_URL` | The OpensShift API Server URL || |
| `OCP_API_SERVER_TOKEN`| The OpensShift API Server Token || |

## How to run
Example of POST to trigger the flow (see input schema [mtv-input.json](./schema/mtv-input.json)):
```bash
curl -X POST -H "Content-Type: application/json" http://localhost:8080/mtv-migration -d '{
"migrationName": "my-vms",
"migrationNamespace": "openshift-mtv"
}'
```
4 changes: 4 additions & 0 deletions mtv-migration/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quarkus.rest-client.mtv_yaml.url=${OCP_API_SERVER_URL}
quarkus.openapi-generator.mtv_yaml.auth.BearerToken.bearer-token=${OCP_API_SERVER_TOKEN}
quarkus.tls.trust-all=true
quarkus.kubernetes-client.trust-certs=true
1 change: 1 addition & 0 deletions mtv-migration/mtv.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions mtv-migration/mtv.sw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
specVersion: "0.8"
id: mtv-migration
version: '1.0'
name: MTV migration workflow
description: workflow executes a plan by creating a migration and waiting for it to be successful or failed
annotations:
- "workflow-type/infrastructure"
dataInputSchema: schemas/mtv-input.json
start: CreateMigration
functions:
- name: createMigration
type: rest
operation: 'specs/mtv.yaml#createMigration'
- name: getMigration
type: rest
operation: 'specs/mtv.yaml#getMigration'
- name: getMigrationError
type: expression
operation: .getStatusResult.status.conditions | map(select(.category == "Error" or .category == "Critical" or .type == "Failed"))[0].message
states:
- name: CreateMigration
type: operation
actions:
- functionRef:
refName: createMigration
arguments:
namespace: .migrationNamespace
apiVersion: "forklift.konveyor.io/v1beta1"
kind: Migration
metadata:
name: .migrationName
namespace: .migrationNamespace
spec:
plan:
name: .migrationName
namespace: .migrationNamespace
transition: GetMigration
- name: GetMigration
type: operation
actions:
- name: getMigration
actionDataFilter:
toStateData: .getStatusResult
functionRef:
refName: getMigration
arguments:
namespace: .migrationNamespace
migration: .migrationName
sleep:
before: PT10S
transition: CheckMigrationStatus
- name: CheckMigrationStatus
type: switch
dataConditions:
- name: MigrationFailure
condition: .getStatusResult.status.conditions | map(select(.category == "Error" or .category == "Critical" or .type == "Failed")) | length > 0
transition: MigrationFailure
- name: MigrationSuccessful
condition: .getStatusResult.status.conditions | map(select(.type == "Succeeded")) | length > 0
transition: MigrationSuccessful
defaultCondition:
transition:
nextState: GetMigration
- name: MigrationFailure
type: operation
actions:
- name: setMigrationErrorMessage
actionDataFilter:
toStateData: .migrationErrorMessage
functionRef:
refName: getMigrationError
stateDataFilter:
output: '{migrationError: .migrationErrorMessage}'
end: true
- name: MigrationSuccessful
type: operation
actions: []
stateDataFilter:
output: '{migrationSuccessful: "migration successful"}'
end: true
16 changes: 16 additions & 0 deletions mtv-migration/schemas/mtv-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"migrationName": {
"type": "string"
},
"migrationNamespace": {
"type": "string"
}
},
"required": [
"migrationName",
"migrationNamespace"
]
}
242 changes: 242 additions & 0 deletions mtv-migration/specs/mtv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
openapi: 3.0.0
info:
title: MTV Kubernetes API
version: v1beta1
paths:
/apis/forklift.konveyor.io/v1beta1/namespaces/{namespace}/migrations/{migration}:
get:
tags:
- forklift_konveyor_io_v1beta1
description: get a resource of type Migration in namespace
operationId: getMigration
parameters:
- in: path
name: namespace
required: true
schema:
type: string
- in: path
name: migration
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Migration'
"401":
description: Unauthorized
security:
- BearerToken: []
/apis/forklift.konveyor.io/v1beta1/namespaces/{namespace}/plans/{plan}:
get:
tags:
- forklift_konveyor_io_v1beta1
description: get a resource of type Plan in namespace
operationId: getPlan
parameters:
- in: path
name: namespace
required: true
schema:
type: string
- in: path
name: plan
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Plan'
"401":
description: Unauthorized
security:
- BearerToken: []
/apis/forklift.konveyor.io/v1beta1/namespaces/{namespace}/plans:
post:
tags:
- forklift_konveyor_io_v1beta1
description: create a resource of type Plan in namespace
operationId: createPlan
parameters:
- in: path
name: namespace
required: true
schema:
type: string
requestBody:
content:
'*/*':
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Plan'
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Plan'
"201":
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Plan'
"202":
description: Accepted
content:
application/json:
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Plan'
"401":
description: Unauthorized
security:
- BearerToken: []
/apis/forklift.konveyor.io/v1beta1/namespaces/{namespace}/migrations:
post:
tags:
- forklift_konveyor_io_v1beta1
description: create a resource of type Migration in namespace
operationId: createMigration
parameters:
- in: path
name: namespace
required: true
schema:
type: string
requestBody:
content:
'*/*':
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Migration'
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Migration'
"201":
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Migration'
"202":
description: Accepted
content:
application/json:
schema:
$ref: '#/components/schemas/forklift.konveyor.io.v1.beta1.Migration'
"401":
description: Unauthorized
security:
- BearerToken: []
components:
schemas:
K8sResource:
type: object
properties:
name:
type: string
namespace:
type: string
K8sConditions:
type: array
items:
type: object
properties:
status:
type: string
type:
type: string
category:
type: string
message:
type: string
forklift.konveyor.io.v1beta1.Vm:
type: object
properties:
id:
type: string
name:
type: string
forklift.konveyor.io.v1beta1.Vms:
type: array
items:
$ref: '#/components/schemas/forklift.konveyor.io.v1beta1.Vm'
forklift.konveyor.io.v1beta1.Map:
type: object
properties:
network:
$ref: '#/components/schemas/K8sResource'
storage:
$ref: '#/components/schemas/K8sResource'
forklift.konveyor.io.v1beta1.Provider:
type: object
properties:
destination:
$ref: '#/components/schemas/K8sResource'
source:
$ref: '#/components/schemas/K8sResource'
forklift.konveyor.io.v1.beta1.Plan:
type: object
properties:
apiVersion:
type: string
kind:
type: string
metadata:
$ref: '#/components/schemas/K8sResource'
spec:
type: object
properties:
map:
$ref: '#/components/schemas/forklift.konveyor.io.v1beta1.Map'
provider:
$ref: '#/components/schemas/forklift.konveyor.io.v1beta1.Provider'
targetNamespace:
type: string
vms:
$ref: '#/components/schemas/forklift.konveyor.io.v1beta1.Vms'
status:
type: object
properties:
conditions:
$ref: '#/components/schemas/K8sConditions'
forklift.konveyor.io.v1.beta1.Migration:
type: object
properties:
apiVersion:
type: string
kind:
type: string
metadata:
$ref: '#/components/schemas/K8sResource'
spec:
type: object
properties:
plan:
type: object
properties:
name:
type: string
namespace:
type: string
status:
type: object
properties:
conditions:
$ref: '#/components/schemas/K8sConditions'
securitySchemes:
BearerToken:
type: http
scheme: bearer
description: Bearer Token authentication

0 comments on commit 36196d2

Please sign in to comment.