Help us shape the future of Go! Take the 2026 Go Developer Survey

provisioner

package
v0.91.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

provisioner/

This directory contains provisioners capapble of spinning up resources of a particular type. It has a generic design that supports multiple provisioner implementations and multiple resource types.

There is currently one supported resource type:

  • runtime: an instance on a Rill runtime (see runtime/ at the root of our monorepo)

There are currently two supported provisioner implementations:

  • static: creates runtime instances using a pool of statically configured runtimes
  • kubernetes: creates runtime instances by dynamically provisioning a dedicated runtime in Kubernetes

Configuration

The provisioners are configured using the environment variable RILL_ADMIN_PROVISIONER_SET_JSON with a named set of provisioners using a format like the following example. More provisioners of the same type can be configured, this is a useful for example to support deployments to different Kubernetes clusters. Furthermore the name of the default provisioner needs to be specified with RILL_ADMIN_DEFAULT_PROVISIONER, this provisioner will be used for all deployed projects where a provisioner is not explicitly chosen.

Choosing a provisioner for runtimes

When provisioning a runtime, the provisioner is resolved in this order:

  1. The project's provisioner, if set (superuser-only, via rill sudo project edit --provisioner).
  2. The org's default provisioner, if set (superuser-only, via rill sudo org set-default-provisioner).
  3. The global default provisioner (RILL_ADMIN_DEFAULT_PROVISIONER).
{
  "static-example":
    {
      "type": "static",
      "spec":
        {
          "runtimes":
            [
              {
                "host": "http://localhost:8081",          // Runtime host
                "slots": 50,                              // Amount of slots in the pre-provisioned runtime
                "data_dir": "/mnt/data",                  // Directory to use for data storage like DB files etc.
                "audience_url": "http://localhost:8081"   // Audience URL (JWT)
              }
            ]
        }
    },

  "kubernetes-example":
    {
      "type": "kubernetes",
      "spec":
        {
          "timeout_seconds": 30,                              // Maximum time to wait for the runtime to become ready
          "data_dir": "/mnt/data",                            // Directory to use for data storage like DB files etc.
          "host": "http://node-*.localhost",                  // The wildcard '*' will be replaced with the deployment's 'provision_id'
          "namespace": "cloud-runtime",                       // Namespace to use in the K8s cluster
          "image": "rilldata/rill",                           // Rill Docker image
          "kubeconfig_path": "kubeconfig.yaml",               // K8s config file to authenticate against the cluster
          "template_paths":
            {
              "http_ingress": "templates/http_ingress.yaml",  // Ingress resource template for HTTP
              "grpc_ingress": "templates/grpc_ingress.yaml",  // Ingress resource template for GRCP
              "service": "templates/service.yaml",            // Service resource template
              "deployment": "templates/deployment.yaml",      // Deployment resource template
              "pvc": "templates/pvc.yaml"                     // PVC resource template
            }
        }
    }
}
Changing the provisioner of existing deployments

Running deployments keep their current provisioner. A change to the project-level or org-level provisioner is applied to a deployment the next time it goes from stopped to running (see StartDeploymentInner in admin/deployments.go). Use rill sudo project restart to stop and start a project's running deployments.

The global default provisioner only applies to newly provisioned runtimes. Changing RILL_ADMIN_DEFAULT_PROVISIONER doesn't move existing deployments. Similarly, if neither a project-level nor an org-level provisioner is set (for example after unsetting one), existing deployments keep their current provisioner.

When a deployment starts with a different provisioner than its runtime was provisioned with, the admin service:

  1. Deprovisions the runtime resource with the old provisioner (for example deleting its Kubernetes PVC, or releasing its static slots).
  2. Resets the resource for the new provisioner, keeping its ID. The runtime instance ID is derived from the resource ID, so it stays the same.
  3. Provisions the resource with the new provisioner and updates the deployment's runtime host.

The old runtime's disk is not migrated. The new runtime starts with an empty disk and relies on the runtime's metastore backups in object storage to recover its state. That requires both runtimes to share the same data bucket and metastore ID. The admin service deliberately doesn't call DeleteInstance on the old runtime, since that would also delete the instance's data in object storage.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Initializers = make(map[string]ProvisionerInitializer)

Initializers is a registry of provisioner initializers by type.

Functions

func NewSet added in v0.43.0

func NewSet(setSpecJSON string, db database.DB, logger *zap.Logger) (map[string]Provisioner, error)

NewSet initializes a set of provisioners from a JSON specification. The JSON specification should be a map of names to ProvisionerSpecs.

func Register added in v0.52.0

func Register(typ string, fn ProvisionerInitializer)

Register registers a new provisioner initializer.

Types

type ClickhouseConfig added in v0.52.0

type ClickhouseConfig struct {
	DSN      string `mapstructure:"dsn"`
	WriteDSN string `mapstructure:"write_dsn,omitempty"`
	Cluster  string `mapstructure:"cluster,omitempty"`
}

ClickhouseConfig describes the expected config for a provisioned Clickhouse resource.

func NewClickhouseConfig added in v0.52.0

func NewClickhouseConfig(cfg map[string]any) (*ClickhouseConfig, error)

func (*ClickhouseConfig) AsMap added in v0.52.0

func (c *ClickhouseConfig) AsMap() map[string]any

type DuckdbConfig added in v0.80.0

type DuckdbConfig struct {
	CPU          string `mapstructure:"cpu"`
	MemoryGB     string `mapstructure:"memory_limit_gb"`
	StorageBytes string `mapstructure:"storage_limit_bytes"`
}

func (*DuckdbConfig) AsMap added in v0.80.0

func (r *DuckdbConfig) AsMap() (map[string]any, error)

type Provisioner

type Provisioner interface {
	// Type returns the type of the provisioner.
	Type() string
	// Close is called when the provisioner is no longer needed.
	Close() error
	// Supports indicates if it can provision the resource type.
	Supports(rt ResourceType) bool
	// Provision provisions a new resource.
	// It may be called multiple times for the same ID if:
	//  - the initial provision is interrupted, or
	//  - the resource args are updated
	//
	// This means Provision should be idempotent for the resource's ID (or otherwise do appropriate garbage collection in calls to Check).
	Provision(ctx context.Context, r *Resource, opts *ResourceOptions) (*Resource, error)
	// Hibernate non-destructively scales down the resource in a way that preserves persistent state (e.g. disks).
	// If the provisioner does not support hibernation, it should just implement this as a no-op, returning r unchanged.
	//
	// When/if the resource should be scaled up again, Provision will be called.
	// You can/should update the Resource's State for bookkeeping the hibernation state.
	//
	// NOTE: This is not 1:1 related to project-level "hibernation". This is a lower-level, state-preserving teardown of provisioner resources.
	Hibernate(ctx context.Context, r *Resource) (*Resource, error)
	// Deprovision deprovisions a resource.
	Deprovision(ctx context.Context, r *Resource) error
	// AwaitReady waits for a resource to be ready.
	AwaitReady(ctx context.Context, r *Resource) error
	// Check is called periodically to health check the provisioner.
	// The provided context should have a generous timeout to allow the provisioner to perform maintenance tasks.
	Check(ctx context.Context) error
	// CheckResource is called periodically to health check a specific resource.
	// The provided context should have a generous timeout to allow the provisioner to perform maintenance tasks for the resource.
	// The resource's state map will be updated to match that of the returned value.
	CheckResource(ctx context.Context, r *Resource, opts *ResourceOptions) (*Resource, error)
}

Provisioner is able to provision resources for one or more resource types.

type ProvisionerInitializer added in v0.52.0

type ProvisionerInitializer func(specJSON []byte, db database.DB, logger *zap.Logger) (Provisioner, error)

ProvisionerInitializer creates a new provisioner.

type ProvisionerSpec added in v0.43.0

type ProvisionerSpec struct {
	Type string          `json:"type"`
	Spec json.RawMessage `json:"spec"`
}

ProvisionerSpec is a JSON-serializable specification for a provisioner.

type Resource added in v0.52.0

type Resource struct {
	// ID uniquely identifies the provisioned resource.
	ID string
	// Type describes what type of service the resource is.
	Type ResourceType
	// State contains state about the provisioned resource for use by the provisioner.
	// It should not be accessed outside of the provisioner.
	State map[string]any
	// Config contains access details for clients that use the resource.
	Config map[string]any
}

Resource represents a provisioned resource.

type ResourceOptions added in v0.52.0

type ResourceOptions struct {
	// Service-specific arguments for the provisioner. See resources.go for supported arguments.
	Args map[string]any
	// Annotations for the project the resource belongs to.
	Annotations map[string]string
	// RillVersion is the current version of Rill.
	RillVersion string
}

ResourceOptions contains metadata about a resource.

type ResourceType added in v0.52.0

type ResourceType string

ResourceType enumerates the provisionable resource types.

const (
	ResourceTypeRuntime    ResourceType = "runtime"
	ResourceTypeClickHouse ResourceType = "clickhouse"
)

func (ResourceType) Valid added in v0.53.0

func (r ResourceType) Valid() bool

type RuntimeArgs added in v0.52.0

type RuntimeArgs struct {
	Slots          int    `mapstructure:"slots"`
	Version        string `mapstructure:"version"`
	Environment    string `mapstructure:"environment"`
	OverrideDiskGB *int64 `mapstructure:"override_disk_gb"`
}

RuntimeArgs describe the expected arguments for provisioning a runtime resource.

func NewRuntimeArgs added in v0.52.0

func NewRuntimeArgs(args map[string]any) (*RuntimeArgs, error)

func (*RuntimeArgs) AsMap added in v0.52.0

func (r *RuntimeArgs) AsMap() map[string]any

type RuntimeConfig added in v0.52.0

type RuntimeConfig struct {
	Host         string `mapstructure:"host"`
	Audience     string `mapstructure:"audience"`
	CPU          int    `mapstructure:"cpu"`
	MemoryGB     int    `mapstructure:"memory_gb"`
	StorageBytes int64  `mapstructure:"storage_bytes"`
}

RuntimeConfig describes the expected config for a provisioned runtime resource.

func NewRuntimeConfig added in v0.52.0

func NewRuntimeConfig(cfg map[string]any) (*RuntimeConfig, error)

func (*RuntimeConfig) AsMap added in v0.52.0

func (r *RuntimeConfig) AsMap() map[string]any

func (*RuntimeConfig) DuckdbConfig added in v0.80.0

func (r *RuntimeConfig) DuckdbConfig() *DuckdbConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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