async

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package async provides interfaces for async infrastructure provisioning.

Index

Constants

This section is empty.

Variables

View Source
var ErrNilProvisionResult = errors.New("provisioner returned nil result")

ErrNilProvisionResult is returned when a provisioner returns nil result without an error.

View Source
var Providers = registry.New[Provisioner]("async-provisioner")

Providers is the registry for async provisioners.

Functions

This section is empty.

Types

type KafkaAdmin

type KafkaAdmin interface {
	CreateTopics(ctx context.Context, partitions int32, replication int16, configs map[string]*string, topics ...string) (kadm.CreateTopicResponses, error)
	DeleteTopics(ctx context.Context, topics ...string) (kadm.DeleteTopicResponses, error)
	Close()
}

KafkaAdmin abstracts the Kafka admin operations for testability.

type KafkaAdminFactory

type KafkaAdminFactory func(brokers []string) (KafkaAdmin, error)

KafkaAdminFactory creates KafkaAdmin instances. Defaults to real kadm.Client.

type KafkaProvisioner

type KafkaProvisioner struct {
	Brokers           []string
	NumPartitions     int32
	ReplicationFactor int16
	AdminFactory      KafkaAdminFactory // nil = use real kadm
}

KafkaProvisioner provisions Kafka topics and consumer groups for preview environments using the Kafka AdminClient API. Compatible with Apache Kafka, AutoMQ, Redpanda, MSK, and any Kafka-protocol broker.

func (*KafkaProvisioner) Name

func (k *KafkaProvisioner) Name() string

Name returns the provisioner name.

func (*KafkaProvisioner) Provision

func (*KafkaProvisioner) Teardown

Teardown deletes the preview-scoped Kafka topic.

type NoopProvisioner

type NoopProvisioner struct{}

NoopProvisioner is a no-op provisioner that returns the target unchanged.

func (*NoopProvisioner) Name

func (n *NoopProvisioner) Name() string

Name returns the provisioner name.

func (*NoopProvisioner) Provision

Provision returns a resolved target of "<target>-<envName>" and populates default or custom environment variables without creating real infrastructure.

func (*NoopProvisioner) Teardown

Teardown is a no-op since no real infrastructure was created.

type ProvisionResult

type ProvisionResult struct {
	// ResolvedTarget is the provisioned resource name (e.g., "preview-123-payments" task queue).
	ResolvedTarget string
	// EnvVars are environment variables to inject into preview pods.
	EnvVars map[string]string
}

ProvisionResult contains the result of provisioning an async route.

type Provisioner

type Provisioner interface {
	// Provision creates async infrastructure for the given route spec.
	Provision(ctx context.Context, env *v1alpha1.Environment, route v1alpha1.AsyncRouteSpec) (*ProvisionResult, error)
	// Teardown removes async infrastructure for the given route spec.
	Teardown(ctx context.Context, env *v1alpha1.Environment, route v1alpha1.AsyncRouteSpec) error
	// Name returns the provisioner name.
	Name() string
}

Provisioner provisions and tears down async infrastructure for preview environments.

type TemporalProvisioner

type TemporalProvisioner struct {
	// Namespace is the Temporal namespace to use.
	Namespace string
}

TemporalProvisioner provisions Temporal task queues for preview environments. Task queues in Temporal are lazy — they auto-create when a worker polls. This provisioner generates deterministic queue names and injects them as env vars.

func (*TemporalProvisioner) Name

func (t *TemporalProvisioner) Name() string

Name returns the provisioner name.

func (*TemporalProvisioner) Provision

Provision generates a preview-scoped task queue name. Temporal task queues auto-create on first worker poll, so no actual provisioning is needed.

func (*TemporalProvisioner) Teardown

Teardown is a no-op for Temporal — stale task queues are harmless and are garbage-collected by Temporal when no workers are polling.

type WebhookProvisioner

type WebhookProvisioner struct {
	Endpoint   string
	HTTPClient *http.Client
}

WebhookProvisioner calls an external webhook to provision async infrastructure.

func NewWebhookProvisioner

func NewWebhookProvisioner(endpoint string) *WebhookProvisioner

NewWebhookProvisioner creates a WebhookProvisioner targeting the given endpoint URL.

func (*WebhookProvisioner) Name

func (w *WebhookProvisioner) Name() string

Name returns the provisioner name.

func (*WebhookProvisioner) Provision

Provision calls the webhook endpoint to create async infrastructure and returns the resolved target and environment variables to inject into preview pods.

func (*WebhookProvisioner) Teardown

Teardown calls the webhook endpoint to remove async infrastructure for the given route.

type WebhookRequest

type WebhookRequest struct {
	Action      string                  `json:"action"` // "provision" or "teardown"
	Environment string                  `json:"environment"`
	Namespace   string                  `json:"namespace"`
	Route       v1alpha1.AsyncRouteSpec `json:"route"`
}

WebhookRequest is sent to the provisioning webhook.

type WebhookResponse

type WebhookResponse struct {
	ResolvedTarget string            `json:"resolvedTarget"`
	EnvVars        map[string]string `json:"envVars"`
}

WebhookResponse is returned by the provisioning webhook.

Jump to

Keyboard shortcuts

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