workflowproj

package module
v1.44.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 23 Imported by: 1

README

Workflow Project Handler

Handler to programmatically convert a local SonataFlow project into Kubernetes manifests to deploy with the operator.

How to

Add this module to your project's dependencies:

go get github.com/kiegroup/kogito-serverless-workflow/workflowproj

Then you should have access to the main entry point of this package, which is the workflow project handler builder.

The API is simple enough to describe in a few lines:

package main

import (
	"os"

	"github.com/kiegroup/kogito-serverless-operator/workflowproj"
)

func Main() {
	// we are ignoring errors just for demo purposes, but don't do this!
	workflowFile, _ := os.Open("myworkflow.sw.json")
	propertiesFile, _ := os.Open("application.properties")
	specFile, _ := os.Open("myopenapi.yaml")
	defer workflowFile.Close()
	defer propertiesFile.Close()
	defer specFile.Close()
	
	// create the handler
	handler := workflowproj.New("mynamespace").
		WithWorkflow(workflowFile).
		WithAppProperties(propertiesFile).
		AddResource("myopenapi.yaml", specFile)

	// You can easily generate the Kubernetes manifests to later use client-go to deploy them in the cluster...
	objs, _ := handler.AsObjects()
	// client.Create(...), other stuff
	
	// ... or you can save the files locally to use them later or to integrate in a GitOps process
	_ = handler.SaveAsKubernetesResources("/my/dir/")
}

The SonataFlow custom resource generated is annotated with the devmode profile . Every other resource added to the project is a ConfigMap handling these resources for you.

Given that you already have the SonataFlow Operator installed , to deploy the generated project you can simply run:

kubectl apply -f /my/dir/* -n "mynamespace"

Documentation

Index

Constants

View Source
const (

	// ApplicationPropertiesFileName is the default application properties file name
	ApplicationPropertiesFileName = "application.properties"
	// LabelApp key to use among object selectors, "app" is used among k8s applications to group objects in some UI consoles
	LabelApp = "app"
	// LabelWorkflow specialized label managed by the controller
	LabelWorkflow = metadata.Domain + "/workflow-app"
)

Variables

This section is empty.

Functions

func CreateNewAppPropsConfigMap

func CreateNewAppPropsConfigMap(workflow *operatorapi.SonataFlow, properties string) *corev1.ConfigMap

CreateNewAppPropsConfigMap creates a new ConfigMap object to hold the workflow application properties.

func GetDefaultLabels

func GetDefaultLabels(workflow *operatorapi.SonataFlow) map[string]string

GetDefaultLabels gets the default labels based on the given workflow. You can use SetDefaultLabels that essentially does the same thing, if you don't need the labels explicitly.

func GetWorkflowPropertiesConfigMapName

func GetWorkflowPropertiesConfigMapName(workflow *operatorapi.SonataFlow) string

GetWorkflowPropertiesConfigMapName gets the default ConfigMap name that holds the application property for the given workflow

func SetDefaultLabels

func SetDefaultLabels(workflow *operatorapi.SonataFlow, object metav1.Object)

SetDefaultLabels adds the default workflow application labels to the given object. Overrides the defined labels.

func SetTypeToObject

func SetTypeToObject(obj runtime.Object, s *runtime.Scheme) error

SetTypeToObject sets the Kind and ApiVersion to a given object since the default constructor won't do it. See: https://github.com/kubernetes/client-go/issues/308#issuecomment-700099260

func SetWorkflowProfile

func SetWorkflowProfile(workflow *operatorapi.SonataFlow, profile metadata.ProfileType)

SetWorkflowProfile adds the profile annotation to the workflow

Types

type ResourceKind

type ResourceKind int
const (
	OpenApiResource ResourceKind = iota
	AsyncApiResource
	CamelRouteResource
	GenericResource
)

func ParseResourceKind

func ParseResourceKind(contents []byte) ResourceKind

ParseResourceKind tries to parse the contents of the given resource and find the correct type. Async and OpenAPI files are pretty fast to parse (0.00s). Camel and generic files can take a fair price from the CPU (0.03s on the i5) since it takes more processing power.

type WorkflowProject

type WorkflowProject struct {
	// Workflow the workflow definition
	Workflow *operatorapi.SonataFlow
	// Properties the application properties for the workflow
	Properties *corev1.ConfigMap
	// Resources any resource that this workflow requires, like an OpenAPI specification file.
	Resources []*corev1.ConfigMap
}

WorkflowProject is a structure to hold every Kubernetes object generated by the given WorkflowProjectHandler handler.

type WorkflowProjectHandler

type WorkflowProjectHandler interface {
	// Named overwrites the workflow ID. The handler will use this name instead to generate the manifests name.
	// Remember that together with the Namespace, the Name is the unique key of a Kubernetes object.
	Named(name string) WorkflowProjectHandler
	// WithWorkflow reader for a file or the content stream of a workflow definition.
	WithWorkflow(reader io.Reader) WorkflowProjectHandler
	// WithAppProperties reader for a file or the content stream of a workflow application properties.
	WithAppProperties(reader io.Reader) WorkflowProjectHandler
	// AddResource reader for a file or the content stream of any resource needed by the workflow. E.g. an OpenAPI specification file.
	// Name is required, should match the workflow function definition.
	AddResource(name string, reader io.Reader) WorkflowProjectHandler
	// AddResourceAt same as AddResource, but defines the path instead of using the default.
	AddResourceAt(name, path string, reader io.Reader) WorkflowProjectHandler
	// SaveAsKubernetesManifests saves the project in the given file system path in YAML format.
	SaveAsKubernetesManifests(path string) error
	// AsObjects returns a reference to the WorkflowProject holding the Kubernetes Manifests based on your files.
	AsObjects() (*WorkflowProject, error)
}

WorkflowProjectHandler is the description of the handler interface. A handler can generate Kubernetes manifests to deploy a new SonataFlow project in the cluster

func New

func New(namespace string) WorkflowProjectHandler

New is the entry point for this package. You can create a new handler with the given namespace, meaning that every manifest generated will use this namespace. namespace is a required parameter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL