workflowproj

package module
v0.0.0-...-7801012 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

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/apache/incubator-kie-tools/packages/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.SaveAsKubernetesManifests("/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 holding user properties
	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"
	// LabelService key to use among object selectors
	LabelService = metadata.Domain + "/service"
	// LabelWorkflow specialized label managed by the controller
	LabelWorkflow = metadata.Domain + "/workflow-app"
)

Variables

This section is empty.

Functions

func CreateNewManagedPropsConfigMap

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

CreateNewManagedPropsConfigMap creates a new ConfigMap object to hold the managed application properties of the workflos.

func CreateNewUserPropsConfigMap

func CreateNewUserPropsConfigMap(workflow *operatorapi.SonataFlow) *corev1.ConfigMap

CreateNewUserPropsConfigMap creates a new empty ConfigMap object to hold the user application properties of the workflow.

func GetDefaultLabels

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

GetDefaultLabels gets the default labels based on the given workflow.

func GetManagedPropertiesFileName

func GetManagedPropertiesFileName(workflow *operatorapi.SonataFlow) string

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

func GetMergedLabels

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

GetMergedLabels gets labels based on the given workflow, includes their own labels, merged with the default ones.

func GetWorkflowManagedPropertiesConfigMapName

func GetWorkflowManagedPropertiesConfigMapName(workflow *operatorapi.SonataFlow) string

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

func GetWorkflowUserPropertiesConfigMapName

func GetWorkflowUserPropertiesConfigMapName(workflow *operatorapi.SonataFlow) string

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

func IsDevProfile

func IsDevProfile(workflow *operatorapi.SonataFlow) bool

IsDevProfile detects if the workflow is using the Dev profile or not

func SetMergedLabels

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

SetMergedLabels adds the merged labels to the given object.

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
	// Profile overrides the default profile (dev) in the generated SonataFlow manifest
	Profile(profile metadata.ProfileType) 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.

Jump to

Keyboard shortcuts

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