Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kustomize deployment of all workflows #81

Merged
merged 10 commits into from
Feb 27, 2024
2 changes: 1 addition & 1 deletion kustomize/escalation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A brief explanation of the system architecture is provided in the related [docum
### Image update
Run the following to update the default image to a custom configuration
```
cd overlays/prod && kustomize edit set image serverless-workflow-escalation=quay.io/orchestrator/serverless-workflow-escalation@1234
cd overlays/prod && kustomize edit set image serverless-workflow-escalation=quay.io/orchestrator/serverless-workflow-escalation:1234
```

## Configure properties
Expand Down
40 changes: 40 additions & 0 deletions kustomize/greeting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Prerequisites
* The manifests are generated without the `namespace` configuration
* Manifest names reflect the `resources` section of [kustomization.yaml](./base/kustomization.yaml)

A brief explanation of the system architecture is provided in the related [document](./move2kube.md).

## Kustomization options
### Image update
Run the following to update the default images to a custom configuration
```
cd base && kustomize edit set image serverless-workflow-greeting=quay.io/orchestrator/serverless-workflow-greeting:1234
```

## Deploy to the cluster
### Deploy the production environment
This environment applies the generated manifests with minimal customizations to:
* Use the latest application images
* Force the `prod` profile for the SonataFlow instance
* Deploy by default on the `sonataflow-infra` namespace

The default namespace can be customized with:
```bash
TARGET_NS=YOUR-NS
cd base && kustomize edit set namespace=$TARGET_NS && cd ..
```

Once the configuration is set, apply the deployment to the configured namespace with:
```bash
kustomize build base | oc apply -f -
```

You can monitor the deployment status with:
```bash
oc get sonataflow greeting -n sonataflow-infra -owide
```

And finally view the logs with:
```bash
oc logs -f -n sonataflow-infra -l app=greeting
```
20 changes: 20 additions & 0 deletions kustomize/greeting/base/01-configmap_01-greeting-resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
data:
greeting.sw.input-schema.json: |
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"language": {
"title": "Language",
"description": "Language to greet",
"type": "string",
"enum": ["English", "Spanish"],
"default": "English"
}
}
}
kind: ConfigMap
metadata:
creationTimestamp: null
name: 01-greeting-resources
74 changes: 74 additions & 0 deletions kustomize/greeting/base/01-sonataflow_greeting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlow
metadata:
annotations:
sonataflow.org/description: YAML based greeting workflow
sonataflow.org/expressionLang: jsonpath
sonataflow.org/profile: dev
sonataflow.org/version: "1.0"
creationTimestamp: null
labels:
app: greeting
sonataflow.org/workflow-app: greeting
name: greeting
spec:
flow:
dataInputSchema:
failOnValidationErrors: true
schema: specs/greeting.sw.input-schema.json
functions:
- name: greetFunction
operation: sysout
type: custom
start:
stateName: ChooseOnLanguage
states:
- dataConditions:
- condition: ${$.[?(@.language == 'English')]}
transition:
nextState: GreetInEnglish
- condition: ${$.[?(@.language == 'Spanish')]}
transition:
nextState: GreetInSpanish
defaultCondition:
transition:
nextState: GreetInEnglish
name: ChooseOnLanguage
type: switch
- data:
greeting: 'Hello from YAML Workflow, '
name: GreetInEnglish
transition:
nextState: GreetPerson
type: inject
- data:
greeting: 'Saludos desde YAML Workflow, '
name: GreetInSpanish
transition:
nextState: GreetPerson
type: inject
- actionMode: sequential
actions:
- actionDataFilter:
useResults: true
functionRef:
arguments:
message: $.greeting $.name
invoke: sync
refName: greetFunction
name: greetAction
end:
terminate: true
name: GreetPerson
type: operation
podTemplate:
container:
resources: {}
resources:
configMaps:
- configMap:
name: 01-greeting-resources
workflowPath: specs
status:
address: {}
lastTimeRecoverAttempt: null
4 changes: 4 additions & 0 deletions kustomize/greeting/base/config/image-configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is to configure where the image is defined in the resources of kind SonataFlow
images:
- path: spec/podTemplate/container/image
kind: SonataFlow
22 changes: 22 additions & 0 deletions kustomize/greeting/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- 01-configmap_01-greeting-resources.yaml
- 01-sonataflow_greeting.yaml

namespace: sonataflow-infra

configurations:
- config/image-configuration.yaml

# Replace dev profile in SonataFlow instance(s), add image and envFrom
patches:
- path: sonataflow-patch.yaml
target:
kind: SonataFlow
name: greeting
images:
- name: serverless-workflow-greeting
newName: quay.io/orchestrator/serverless-workflow-greeting
newTag: f6fbb19dd531f5bcb612b28862a2303dfae87bd7
11 changes: 11 additions & 0 deletions kustomize/greeting/base/sonataflow-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlow
metadata:
name: m2k
annotations:
sonataflow.org/profile: prod
spec:
podTemplate:
container:
image: serverless-workflow-greeting
resources: {}
78 changes: 78 additions & 0 deletions kustomize/move2kube/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Prerequisites
* The manifests are generated without the `namespace` configuration
* Manifest names reflect the `resources` section of [kustomization.yaml](./base/kustomization.yaml)

A brief explanation of the system architecture is provided in the related [document](./move2kube.md).

## Kustomization options
### Image update
Run the following to update the default images to a custom configuration
```
cd base && kustomize edit set image serverless-workflow-move2kube=quay.io/orchestrator/serverless-workflow-move2kube:1234 && cd ..
cd base && kustomize edit set image serverless-workflow-m2k-kfunc=quay.io/orchestrator/serverless-workflow-m2k-kfunc:1234 && cd ..
```

## Configure properties
Edit configuration in [replace-config.yaml](./base/replace-config.yaml), [config.properties](./base/config.properties) and
dmartinol marked this conversation as resolved.
Show resolved Hide resolved
[secret.properties](./base/secret.properties) to match your environment configuration.

## Deploy to the cluster
### Deploy the production environment
This environment applies the generated manifests with minimal customizations to:
* Use the latest application images
* Force the `prod` profile for the SonataFlow instance
* Deploy by default on the `sonataflow-infra` namespace
* Mount the configurations defined in [Configure properties](#configure-properties) as environment variables

The default namespace can be customized with:
```bash
TARGET_NS=YOUR-NS
cd base && kustomize edit set namespace=$TARGET_NS && cd ..
dmartinol marked this conversation as resolved.
Show resolved Hide resolved
```

Once the configuration is set, apply the deployment to the configured namespace with:
```bash
kustomize build base | oc apply -f -
dmartinol marked this conversation as resolved.
Show resolved Hide resolved
```

You can monitor the deployment status with:
```bash
oc get sonataflow m2k -n sonataflow-infra -owide
Copy link
Collaborator

@gabriel-farache gabriel-farache Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be

oc get sonataflow m2k -n ${TARGET_NS} -owide

```

And finally view the logs with:
```bash
oc logs -f -n sonataflow-infra -l app=m2k
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, the namespace should be parameterized too (${TARGET_NS} instead of sonataflow-infra)

```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, even if you reference the INSTALL.md file, you should copy/paste the steps when you update the move2kube URLs: provide the command to do it or at least the location of the file and the props to edit and then put the kustomize apply command again to apply those and then the command to restart the m2k pods to reflect the changes of the CM to the pods

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following you here: are you referring to the pre-installation steps or the fact that whenever you update the CM/Secret mounted to the Pod's envFrom the Pod is not restarted? (which is a different issue, and BTW tracked by apache/incubator-kie-kogito-serverless-operator#298)
Pls clarify

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the README to clarify that the MOVE2KUBE_URL and MOVE2KUBE_API properties must match the exposed Route, but I would not make it a 2 steps installation. On the contrary, I would be tempted to split the configuration in 2 to isolate the installation of Move2Kube that, BTW, may also be already installed in the cluster or anywhere else. But not today, of course 😉

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be tempted to split the configuration in 2 to isolate the installation of Move2Kube

That would be fine for me too, like in move2kube.md too add/move some steps
But that is for later for sure


### Notes about transformation from Helm chart
* The Helm values is converted to a `move2kube-values` ConfigMap and we use a replacement configuration to update the affected fields one by one, as in
[replace-config.yaml](./base/replace-config.yamll)
* The original [YAML](../../charts/workflows/charts/move2kube/values.yaml) is converted to a [properties file](./base/values.properties)
* The original Helm variable references were transformed accordingly, e.g. `{{ .Values.instance.name }}` is changed to `__instance_name__`
* The following properties are not managed as values but they were either not used in the chart or we map them differently (e.g. using the image transformer in [kustomization.yaml](./base/kustomization.yaml)):
```
# namespace=sonataflow-infra
# workflow_backstageNotificationURL=http://orchestrator-backstage.orchestrator/api/notifications
# kfunction_image=quay.io/orchestrator/serverless-workflow-m2k-kfunc:latest
# workflow_move2kubeURL=https://move2kube-route-sonataflow-infra.apps.cluster-8xfw.redhatworkshops.io
# workflow_image=quay.io/orchestrator/serverless-workflow-move2kube:latest
```
* In the chart, the name of some resources combined the workflow name to a fixed string. This is no more applicable using the kustomize replacements, because
it replaces the full content of a target path
* We left on purpose some "errors" of this kind as in:
```yaml
apiVersion: v1
kind: Service
metadata:
name: __instance_name__-svc
...
```
The above name is completely replaced to `name: move2kube`
* Other properties are defined in [config.properties](./base/config.properties) and allow the deployer to define the runtime environment (we can simplify that [values.properties](./base/values.properties) defines instead the deployment configuration)
* These are mounted to the services that require such customization, e.g. the `SonataFlow` instance and the `m2k-save-transformation-func` Knative Service

You can run the following diff to highlight the main changes:
```bash
diff -r base/ ../../charts/workflows/charts/move2kube/templates
```
Loading