runtimeconfig

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

package runtimeconfig provides implementations and helpers for managing Spin runtime config.

It is mostly a terrifying pile of secrets.

The core flow of rendering a Spin Runtime Config from the CRD is as follows:

  1. We extract all of the config options from the spin app
  2. For all of the config options we build a map of secrets and config maps this has the advantage of de-duping whole-secrets into a single reference when different keys may be re-used.
  3. We fetch all of those secrets and config maps, returning an error if any are not found. (We do not currently support "optional" secrets, as there are no runtimeConfig options that would make sense to be optional).
  4. We then iterate over the RuntimeConfig CRD again, with the augmented data, to finally build a `runtimeconfig.Spin` that has populated config options.

This mostly results in a lot of incredibly ugly code because we need to translate between very disparate schemas.

Spin Runtime Config is modelled using Rust `enums` for its schema, with schemas varying based on the `type` option - this isn't something that can be cleanly modelled in a Kubernetes CRD, which is where our "type plus list of options" schema comes from. i.e:

keyValueStores:
  - name: "mystore"
    type: "redis"
    options:
      - name: url
        value: "redis://localghost:9000"
  - name: "myotherstore"
    type: "sqlite"
    options:
      - name: path
        value: "/mnt/store/redis.db"

Or when sourcing a value from a secret:

keyValueStores:
  - name: "mystore"
    type: "redis"
    options:
      - name: url
        valueFrom:
         secretKeyRef:
           name: "my-secret"
           key: "redis-url"

Will render into toml that looks something like:

[key_value_store.mystore]
type = "redis"
url = "redis://localghost:9000"

[key_value_store.myotherstore]
type = "sqlite"
path = "/mnt/store/redis.db"

To maximize compatibility with different spin options + custom builds, we do very little validation of runtime config options in the operator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	// Build takes a spin app and attempts to fetch any dependent secrets and build
	// a Spin-compatible representation of the configuration that can be rendered into
	// a new Secret.
	Build(ctx context.Context, app *spinv1alpha1.SpinApp) (*Spin, error)
}

type EnvVariablesProviderOptions

type EnvVariablesProviderOptions struct {
	Prefix     string `toml:"prefix,omitempty"`
	DotEnvPath string `toml:"dotenv_path,omitempty"`
}

type K8sBuilder

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

func NewBuilder

func NewBuilder(client client.Client) *K8sBuilder

func (*K8sBuilder) Build

func (k *K8sBuilder) Build(ctx context.Context, app *spinv1alpha1.SpinApp) (rc *Spin, err error)

type KeyValueStoreOptions

type KeyValueStoreOptions map[string]secret.String

type SQLiteDatabaseOptions

type SQLiteDatabaseOptions map[string]secret.String

type Spin

type Spin struct {
	Variables []VariablesProvider `toml:"config_provider,omitempty"`

	KeyValueStores map[string]KeyValueStoreOptions `toml:"key_value_store,omitempty"`

	SQLiteDatabases map[string]SQLiteDatabaseOptions `toml:"sqlite_database,omitempty"`

	LLMCompute map[string]secret.String `toml:"llm_compute,omitempty"`
}

func (*Spin) AddKeyValueStore

func (s *Spin) AddKeyValueStore(
	name, storeType, namespace string,
	secrets map[types.NamespacedName]*corev1.Secret,
	configMaps map[types.NamespacedName]*corev1.ConfigMap,
	opts []spinv1alpha1.RuntimeConfigOption) error

func (*Spin) AddLLMCompute

func (s *Spin) AddLLMCompute(computeType, namespace string,
	secrets map[types.NamespacedName]*corev1.Secret,
	configMaps map[types.NamespacedName]*corev1.ConfigMap,
	opts []spinv1alpha1.RuntimeConfigOption) error

func (*Spin) AddSQLiteDatabase

func (s *Spin) AddSQLiteDatabase(
	name, storeType, namespace string,
	secrets map[types.NamespacedName]*corev1.Secret,
	configMaps map[types.NamespacedName]*corev1.ConfigMap,
	opts []spinv1alpha1.RuntimeConfigOption) error

type VariablesProvider

type VariablesProvider struct {
	Type string `toml:"type,omitempty"`
	EnvVariablesProviderOptions
}

Jump to

Keyboard shortcuts

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