Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-farache authored and gciavarrini committed Jun 21, 2024
1 parent 8a99b9d commit 9950794
Show file tree
Hide file tree
Showing 5 changed files with 2,758 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/create-ocp-project/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.1
version: 0.0.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
data:
create-ocp-project__main-schema.json: "{\n \"$id\": \"classpath:/schemas/create-ocp-project-schema.json\",\n
\ \"title\": \"Data input schema\",\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n
\ \"type\": \"object\",\n \"properties\": {\n \"inputs\": {\n \"title\":
\"Inputs\",\n \"type\": \"object\",\n \"properties\": {\n \"operationsProjectKey\":
{\n \"title\": \"Operations Project Key\",\n \"description\":
\"JIRA project key for operations\",\n \"type\": \"string\",\n \"default\":
\"OP\"\n },\n \"auditProjectKey\": {\n \"title\": \"Audit
Project Key\",\n \"description\": \"JIRA project key for auditing\",\n
\ \"type\": \"string\",\n \"default\": \"AUD\"\n },\n
\ \"projectName\": {\n \"title\": \"Project Name\",\n \"description\":
\"OCP project to create\",\n \"type\": \"string\",\n \"pattern\":
\"^[a-z0-9]([-a-z0-9]*[a-z0-9])?$\"\n } \n },\n \"required\":
[\n \"operationsProjectKey\",\n \"auditProjectKey\",\n \"projectName\"\n
\ ]\n }\n }\n \n}\n"
kind: ConfigMap
metadata:
creationTimestamp: null
name: 01-create-ocp-project-resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,319 @@
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlow
metadata:
annotations:
sonataflow.org/description: Creating an OpenShift Project
sonataflow.org/expressionLang: jq
sonataflow.org/profile: prod
sonataflow.org/version: "1.0"
creationTimestamp: null
labels:
app: create-ocp-project
sonataflow.org/workflow-app: create-ocp-project
name: create-ocp-project
spec:
flow:
dataInputSchema:
failOnValidationErrors: true
schema: schemas/create-ocp-project__main-schema.json
functions:
- name: jiraCreateIssue
operation: specs/jira-openapi.yaml#createIssue
type: rest
- name: jiraGetIssue
operation: specs/jira-openapi.yaml#getIssue
type: rest
- name: jiraCloseIssue
operation: specs/jira-openapi.yaml#transitionIssue
type: rest
- name: jiraGetIssueTransitions
operation: specs/jira-openapi.yaml#getIssueTransitions
type: rest
- name: createNotification
operation: specs/notifications-openapi.yaml#createNotification
type: rest
- name: createProjectOpenshiftIoV1Project
operation: specs/ocp-project-openapi.yaml#createProjectOpenshiftIoV1Project
type: rest
- name: readProjectOpenshiftIoV1Project
operation: specs/ocp-project-openapi.yaml#readProjectOpenshiftIoV1Project
type: rest
- name: print
operation: sysout
type: custom
start:
stateName: '[Audit]: workflow started'
states:
- actionMode: sequential
actions:
- actionDataFilter:
toStateData: .auditJiraCreateIssueResult
useResults: true
functionRef:
arguments:
fields:
description: '"Workflow executed to request creation project " + .inputs.projectName'
issuetype:
name: Task
labels:
- backstage-workflow
- '"workflowId=" + $WORKFLOW.instanceId'
project:
key: .inputs.auditProjectKey
summary: '"Workflow executed to request the creation of project " + .inputs.projectName'
invoke: sync
refName: jiraCreateIssue
name: callbackAction
name: '[Audit]: workflow started'
transition:
nextState: Open issue on Jira for operations
type: operation
- actionMode: sequential
actions:
- actionDataFilter:
toStateData: .operationsJiraCreateIssueResult
useResults: true
functionRef:
arguments:
fields:
description: '"Please review request to create project " + .inputs.projectName'
issuetype:
name: Task
labels:
- backstage-workflow
- '"workflowId=" + $WORKFLOW.instanceId'
project:
key: .inputs.operationsProjectKey
summary: '"Request authorization to create project " + .inputs.projectName'
invoke: sync
refName: jiraCreateIssue
name: callbackAction
name: Open issue on Jira for operations
transition:
nextState: 'Notify Backstage: Jira ticket created'
type: operation
- actionMode: sequential
actions:
- actionDataFilter:
useResults: true
functionRef:
arguments:
actions:
- title: View on Jira
url: $SECRET.jira_url + "/jira/servicedesk/projects/" + .inputs.operationsProjectKey + "/issues/" + .operationsJiraCreateIssueResult.key
message: Jira ticket created
origin: SonataFlow
targetUsers:
- default/guest
title: Jira ticket created
topic: Create OCP Project workflow
invoke: sync
refName: createNotification
name: 'Create notification: Jira ticket created'
name: 'Notify Backstage: Jira ticket created'
transition:
nextState: Poll Operation Jira issue
type: operation
- actionMode: sequential
actions:
- actionDataFilter:
toStateData: .operationsJiraGetIssueResult
useResults: true
functionRef:
arguments:
issueIdOrKey: .operationsJiraCreateIssueResult.id
invoke: sync
refName: jiraGetIssue
name: get issue
sleep:
before: PT10S
name: Poll Operation Jira issue
transition:
nextState: Check Operation issue done
type: operation
- dataConditions:
- condition: .operationsJiraGetIssueResult.fields.status.statusCategory.key == "done" and .operationsJiraGetIssueResult.fields.resolution.name != "Done"
name: Resource request denied
transition:
nextState: '[Audit]: Close issue on Jira - Project Creation Denied'
- condition: .operationsJiraGetIssueResult.fields.status.statusCategory.key == "done" and .operationsJiraGetIssueResult.fields.resolution.name == "Done"
name: Resource request authorized
transition:
nextState: Create Project
defaultCondition:
transition:
nextState: Poll Operation Jira issue
name: Check Operation issue done
type: switch
- actionMode: sequential
actions:
- actionDataFilter:
useResults: true
functionRef:
arguments:
kind: Project
metadata:
labels:
kubernetes.io/metadata.name: .inputs.projectName
name: .inputs.projectName
spec:
finalizers:
- kubernetes
invoke: sync
refName: createProjectOpenshiftIoV1Project
name: Create OCP Project
name: Create Project
transition:
nextState: 'Post operation: get project resource'
type: operation
- actionMode: sequential
actions:
- actionDataFilter:
toStateData: .project
useResults: true
functionRef:
arguments:
name: .inputs.projectName
invoke: sync
refName: readProjectOpenshiftIoV1Project
name: Get created project
sleep:
before: PT10S
name: 'Post operation: get project resource'
transition:
nextState: 'Post operation: check project resource created successfully'
type: operation
- dataConditions:
- condition: .project.status.phase == "Active"
name: Project Active
transition:
nextState: Notify project active
defaultCondition:
transition:
nextState: Notify project not active
name: 'Post operation: check project resource created successfully'
type: switch
- actionMode: sequential
actions:
- actionDataFilter:
useResults: true
functionRef:
arguments:
message: '"Project " + .inputs.projectName + " active"'
origin: SonataFlow
targetUsers:
- default/guest
title: '"Project " + .inputs.projectName + " active"'
topic: Create OCP Project
invoke: sync
refName: createNotification
name: 'Create notification: project active'
name: Notify project active
transition:
nextState: '[Audit]: Close issue on Jira'
type: operation
- actionMode: sequential
actions:
- actionDataFilter:
useResults: true
functionRef:
arguments:
message: '"Project " + .inputs.projectName + " NOT active"'
origin: SonataFlow
targetUsers:
- default/guest
title: '"Project " + .inputs.projectName + " NOT active"'
topic: Create OCP Project
invoke: sync
refName: createNotification
name: 'Create notification: project not active'
name: Notify project not active
transition:
nextState: '[Audit]: Close issue on Jira'
type: operation
- actionMode: sequential
actions:
- actionDataFilter:
toStateData: .jiraGetTransitionResult
useResults: true
functionRef:
arguments:
issueIdOrKey: .auditJiraCreateIssueResult.id
invoke: sync
refName: jiraGetIssueTransitions
name: get transition id
- actionDataFilter:
toStateData: .jiraCloseIssueResult
useResults: true
functionRef:
arguments:
issueIdOrKey: .auditJiraCreateIssueResult.id
transition:
id: .jiraGetTransitionResult.transitions[] | select(.to.name | contains("Done")) | .id
update:
comment:
- add:
body: '"Project " + .inputs.projectName + " is " + .project.status.phase'
invoke: sync
refName: jiraCloseIssue
name: Close issue on Jira due to Timeout
end:
terminate: true
name: '[Audit]: Close issue on Jira'
type: operation
- actionMode: sequential
actions:
- actionDataFilter:
toStateData: .jiraGetTransitionResult
useResults: true
functionRef:
arguments:
issueIdOrKey: .auditJiraCreateIssueResult.id
invoke: sync
refName: jiraGetIssueTransitions
name: get transition id
- actionDataFilter:
toStateData: .jiraCloseIssueResult
useResults: true
functionRef:
arguments:
issueIdOrKey: .auditJiraCreateIssueResult.id
transition:
id: .jiraGetTransitionResult.transitions[] | select(.to.name | contains("Done")) | .id
update:
comment:
- add:
body: '"Creation of project " + .inputs.projectName + " denied"'
invoke: sync
refName: jiraCloseIssue
name: Close issue on Jira due to Timeout
end:
terminate: true
name: '[Audit]: Close issue on Jira - Project Creation Denied'
type: operation
podTemplate:
container:
resources: {}
image: quay.io/orchestrator/serverless-workflow-create-ocp-project:ee4a4a1e1792d139fda593e684dfb9f0cdf5d164
resources:
configMaps:
- configMap:
name: 01-create-ocp-project-resources
workflowPath: schemas
- configMap:
name: 02-create-ocp-project-resources
workflowPath: specs
persistence:
postgresql:
secretRef:
name: sonataflow-psql-postgresql
userKey: postgres-username
passwordKey: postgres-password
serviceRef:
name: sonataflow-psql-postgresql
port: 5432
databaseName: sonataflow
databaseSchema: create-ocp-project
status:
address: {}
lastTimeRecoverAttempt: null
Loading

0 comments on commit 9950794

Please sign in to comment.