faas

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

README

faas

Main Build Status Develop Build Status Documentation GitHub Issues License Release

Function as a Service CLI and Client Library for KNative-enabled Kubernetes Clusters.

Local Setup and Configuration

Docker is required unless the --local flag is explicitly provided on creation of a new function.

It is recommended to set your preferred image registry for publishing Functions by setting the following environment variables:

export FAAS_REGISTRY=quay.io
export FAAS_NAMESPACE=alice

Alternately, these values can be provided using the --namespace and --registry flags when running the CLI.

Cluster Setup and Configuration

It is assumed that the local system has a kubectl configuration set up to connect to a Kubernetes cluster with the following configuration:

  • Knative Serving and Eventing Installed
  • Knative Domains patched to enable your chosen domain
  • Knative Network patched to enable subdomains
  • Kourier
  • (optionally) Cert-manager for HTTPS routes

See https://github.com/boson-project/config for cluster setup and configuration notes.

Running the CLI

The CLI can be run either by building and installing manually, by running one of the published containers, or using the appropriate pre-built binary releases.

Build and Install

With Go 1.13+ installed, build and install the binary to your path:

go install ./cmd/faas
Docker

Each tag has an assoicated container which can be run via:

docker run quay.io/boson/faas:v0.2.2
Pre-built Binary Releases

Coming soon.

Usage

See help:

faas

Examples

Create a new Function:

> mkdir -p example.com/www
> cd example.com/www
> faas create go
https://www.example.com
> curl https://www.example.com
OK

Using the Client Library

To create a Client which uses the included buildpacks-based function builder, pushes to a Quay.io repository function container artifacts and deploys to a Knative enabled cluster:

package main

import (
  "log"

  "github.com/boson-project/faas"
  "github.com/boson-project/faas/buildpacks"
  "github.com/boson-project/faas/docker"
  "github.com/boson-project/faas/embedded"
  "github.com/boson-project/faas/knative"
)

func main() {
  // A client which uses embedded function templates,
  // Quay.io/alice for interstitial build artifacts.
  // Docker to build and push, and a Knative client for deployment.
  client, err := faas.New(
    faas.WithInitializer(embedded.NewInitializer("")),
    faas.WithBuilder(buildpacks.NewBuilder("quay.io", "alice")),
    faas.WithPusher(docker.NewPusher()),
    faas.WithDeployer(knative.NewDeployer()))

  // Create a Go function which listens for CloudEvents.
  // Publicly routable as https://www.example.com.
  // Local implementation is written to the current working directory.
  if err := client.Create("go", "events", "www.example.com", "."); err != nil {
    log.Fatal(err)
  }
}

Documentation

Index

Constants

View Source
const ConfigFileName = ".faas.yaml"

ConfigFileName is an optional file checked for in the function root.

View Source
const DefaultNamespace = "faas"

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	// Build a service function of the given name with source located at path.
	// returns the image name built.
	Build(name, runtime, path string) (image string, err error)
}

Builder of function source to runnable image.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client for a given Function.

func New

func New(options ...Option) (c *Client, err error)

New client for Function management.

func (*Client) Create

func (c *Client) Create(runtime, template, name, root string) (err error)

Create a service function of the given runtime. Name and Root are optional: Name is derived from root if possible. Root is defaulted to the current working directory.

func (*Client) Describe

func (c *Client) Describe(name, root string) (fd FunctionDescription, err error)

Describe a function. Name takes precidence. If no name is provided, the function defined at root is used.

func (*Client) List

func (c *Client) List() ([]string, error)

List currently deployed service functions.

func (*Client) Remove

func (c *Client) Remove(name, root string) error

Remove a function. Name takes precidence. If no name is provided, the function defined at root is used.

func (*Client) Run

func (c *Client) Run(root string) error

Run the function whose code resides at root.

func (*Client) Update

func (c *Client) Update(root string) (err error)

Update a previously created service function.

type Config

type Config struct {
	// Name specifies the name to be used for this function. As a config option,
	// this value, if provided, takes precidence over the path-derived name but
	// not over the Option WithName, if provided.
	Name string `yaml:"name"`

	// Runtime of the implementation.
	Runtime string `yaml:"runtime"`
}

Config object which provides another mechanism for overriding client static defaults. Applied prior to the WithX options, such that the options take precedence if they are provided.

type DNSProvider

type DNSProvider interface {
	// Provide the given name by routing requests to address.
	Provide(name, address string)
}

DNSProvider exposes DNS services necessary for serving the Function.

type Deployer

type Deployer interface {
	// Deploy a service function of given name, using given backing image.
	Deploy(name, image string) (address string, err error)
}

Deployer of function source to running status.

type Describer

type Describer interface {
	Describe(name string) (description FunctionDescription, err error)
}

type Function

type Function struct {
	// contains filtered or unexported fields
}

func NewFunction

func NewFunction(root string) (f *Function, err error)

func (*Function) DerivedName

func (f *Function) DerivedName(searchLimit int) string

DerivedName returns the name that will be used if path derivation is choosen, limited in its upward recursion. This is exposed for preemptive calculation for interactive confirmation, such as via a CLI.

func (*Function) Initialize

func (f *Function) Initialize(runtime, context, name string, domainSearchLimit int, initializer Initializer) (err error)

func (*Function) Initialized

func (f *Function) Initialized() bool

type FunctionDescription

type FunctionDescription struct {
	Name          string         `json:"name" yaml:"name"`
	Routes        []string       `json:"routes" yaml:"routes"`
	Subscriptions []Subscription `json:"subscriptions" yaml:"subscriptions"`
}

type Initializer

type Initializer interface {
	// Initialize a Function of the given name, template configuration `
	// (expected signature) using a context template.
	Initialize(runtime, template, path string) error
}

Initializer creates the initial/stub Function code on first create.

type Lister

type Lister interface {
	// List the service functions currently deployed.
	List() ([]string, error)
}

Lister of deployed services.

type Option

type Option func(*Client)

Option defines a function which when passed to the Client constructor optionally mutates private members at time of instantiation.

func WithBuilder

func WithBuilder(d Builder) Option

WithBuilder provides the concrete implementation of a builder.

func WithDNSProvider

func WithDNSProvider(provider DNSProvider) Option

WithDNSProvider proivdes a DNS provider implementation for registering the effective DNS name which is either explicitly set via WithName or is derived from the root path.

func WithDeployer

func WithDeployer(d Deployer) Option

WithDeployer provides the concrete implementation of a deployer.

func WithDescriber

func WithDescriber(describer Describer) Option

WithDescriber provides a concrete implementation of a function describer.

func WithDomainSearchLimit

func WithDomainSearchLimit(limit int) Option

WithDomainSearchLimit sets the maximum levels of upward recursion used when attempting to derive effective DNS name from root path. Ignored if DNS was explicitly set via WithName.

func WithInitializer

func WithInitializer(i Initializer) Option

WithInitializer provides the concrete implementation of the Function initializer (generates stub code on initial create).

func WithInternal

func WithInternal(i bool) Option

WithInternal sets the internal (no public route) mode for deployed function.

func WithLister

func WithLister(l Lister) Option

WithLister provides the concrete implementation of a lister.

func WithLocal

func WithLocal(l bool) Option

WithLocal sets the local mode

func WithProgressListener

func WithProgressListener(p ProgressListener) Option

WithProgressListener provides a concrete implementation of a listener to be notified of progress updates.

func WithPusher

func WithPusher(d Pusher) Option

WithPusher provides the concrete implementation of a pusher.

func WithRemover

func WithRemover(r Remover) Option

WithRemover provides the concrete implementation of a remover.

func WithRunner

func WithRunner(r Runner) Option

WithRunner provides the concrete implementation of a deployer.

func WithUpdater

func WithUpdater(u Updater) Option

WithUpdater provides the concrete implementation of an updater.

func WithVerbose

func WithVerbose(v bool) Option

WithVerbose toggles verbose logging.

type ProgressListener

type ProgressListener interface {
	// SetTotal steps of the given task.
	SetTotal(int)

	// Increment to the next step with the given message.
	Increment(message string)

	// Complete signals completion, which is expected to be somewhat different than a step increment.
	Complete(message string)

	// Done signals a cessation of progress updates.  Should be called in a defer statement to ensure
	// the progress listener can stop any outstanding tasks such as synchronous user updates.
	Done()
}

ProgressListener is notified of task progress.

type Pusher

type Pusher interface {
	// Push the image of the service function.
	Push(image string) error
}

Pusher of function image to a registry.

type Remover

type Remover interface {
	// Remove the service function from remote.
	Remove(name string) error
}

Remover of deployed services.

type Runner

type Runner interface {
	// Run the function locally.
	Run(path string) error
}

Runner runs the function locally.

type Subscription

type Subscription struct {
	Source string `json:"source" yaml:"source"`
	Type   string `json:"type" yaml:"type"`
	Broker string `json:"broker" yaml:"broker"`
}

type Updater

type Updater interface {
	// Deploy a service function of given name, using given backing image.
	Update(name, image string) error
}

Updater of a deployed service function with new image.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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