provisioners

package
v0.84.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 14 Imported by: 5

Documentation

Overview

Package provisioners contains the definitions of the different provisioners that can be used in a test to setup an environment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diagnosable

type Diagnosable interface {
	Diagnose(ctx context.Context, stackName string) (string, error)
}

Diagnosable defines the interface for a diagnosable provisioner.

type FileProvisioner

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

FileProvisioner is a provisioner that reads JSON files from a filesystem.

func NewFileProvisioner

func NewFileProvisioner(id string, fs fs.FS) *FileProvisioner

NewFileProvisioner returns a new FileProvisioner.

func (*FileProvisioner) Destroy

Destroy is a no-op for the FileProvisioner.

func (*FileProvisioner) ID

func (fp *FileProvisioner) ID() string

ID returns the ID of the provisioner.

func (*FileProvisioner) Provision

Provision reads JSON files from the filesystem and returns them as raw resources.

type Provisioner

type Provisioner interface {
	ID() string
	Destroy(context.Context, string, io.Writer) error
}

Provisioner defines the interface for a provisioner.

type ProvisionerMap

type ProvisionerMap map[string]Provisioner

ProvisionerMap is a map of provisioners.

func CopyProvisioners

func CopyProvisioners(in ProvisionerMap) ProvisionerMap

CopyProvisioners copies a map of provisioners

type PulumiEnvRunFunc

type PulumiEnvRunFunc[Env any] func(ctx *pulumi.Context, env *Env) error

PulumiEnvRunFunc is a function that runs a Pulumi program with a given environment.

type PulumiProvisioner

type PulumiProvisioner[Env any] struct {
	// contains filtered or unexported fields
}

PulumiProvisioner is a provisioner based on Pulumi with binding to an environment.

func NewTypedPulumiProvisioner

func NewTypedPulumiProvisioner[Env any](id string, runFunc PulumiEnvRunFunc[Env], configMap runner.ConfigMap) *PulumiProvisioner[Env]

NewTypedPulumiProvisioner returns a new PulumiProvisioner.

func NewUntypedPulumiProvisioner

func NewUntypedPulumiProvisioner(id string, runFunc pulumi.RunFunc, configMap runner.ConfigMap) *PulumiProvisioner[any]

NewUntypedPulumiProvisioner returns a new PulumiProvisioner without env binding.

func (*PulumiProvisioner[Env]) Destroy

func (pp *PulumiProvisioner[Env]) Destroy(ctx context.Context, stackName string, logger io.Writer) error

Destroy deletes the Pulumi stack.

func (*PulumiProvisioner[Env]) Diagnose

func (pp *PulumiProvisioner[Env]) Diagnose(ctx context.Context, stackName string) (string, error)

Diagnose runs the diagnose function if it is set diagnoseFunc

func (*PulumiProvisioner[Env]) ID

func (pp *PulumiProvisioner[Env]) ID() string

ID returns the ID of the provisioner.

func (*PulumiProvisioner[Env]) Provision

func (pp *PulumiProvisioner[Env]) Provision(ctx context.Context, stackName string, logger io.Writer) (RawResources, error)

Provision runs the Pulumi program and returns the raw resources.

func (*PulumiProvisioner[Env]) ProvisionEnv

func (pp *PulumiProvisioner[Env]) ProvisionEnv(ctx context.Context, stackName string, logger io.Writer, env *Env) (RawResources, error)

ProvisionEnv runs the Pulumi program with a given environment and returns the raw resources.

func (*PulumiProvisioner[Env]) SetDiagnoseFunc

func (pp *PulumiProvisioner[Env]) SetDiagnoseFunc(diagnoseFunc func(ctx context.Context, stackName string) (string, error))

SetDiagnoseFunc sets the diagnose function.

type RawResources

type RawResources map[string][]byte

RawResources is the common types returned by provisioners

func (RawResources) Merge

func (rr RawResources) Merge(in RawResources)

Merge merges two RawResources maps

type StaticStackProvisioner added in v0.84.0

type StaticStackProvisioner[Env any] struct {
	// contains filtered or unexported fields
}

StaticStackProvisioner is a provisioner that reads a single JSON file and populates a typed environment directly.

JSON file format

The file must be a JSON object whose top-level keys are resource names. Each value is the raw JSON payload for that resource. Keys prefixed with "_" are treated as metadata and are ignored.

{
  "_source": "pulumi-stack-my-stack",
  "kubernetesCluster": { "clusterName": "my-cluster", "kubeConfig": "…" },
  "fakeIntake":        { "host": "localhost", "port": 8080 },
  "agent":             { "version": "7.x" }
}

Field naming and key resolution

For each exported pointer field in *Env that implements components.Importable, the provisioner derives a resource key using the following priority order:

  1. The value of the `import` struct tag, when present.
  2. The field name with its first letter lowercased (lowerCamelCase).

The derived key is then looked up in the JSON object:

  • Match found: components.Importable.SetKey is called so that [environments.BuildEnvFromResources] can unmarshal the payload into the field.
  • No match: the field is set to nil and silently skipped.

Naming convention

For the provisioner to wire a field automatically, the corresponding JSON key must equal the lowerCamelCase form of the Go field name — unless the field carries an explicit `import` tag that overrides it.

Given this environment struct:

type MyEnv struct {
    KubernetesCluster *components.KubernetesCluster `import:"kubernetesCluster"` // explicit tag
    FakeIntake        *components.FakeIntake                                      // → key "fakeIntake"
    Agent             *components.KubernetesAgent                                 // → key "agent"
}

The expected JSON keys are "kubernetesCluster", "fakeIntake", and "agent". A field whose JSON key is absent from the file is set to nil (not an error); a JSON key that has no matching field is silently ignored.

Use the `import` tag when the field name and the JSON key diverge — for example when a legacy snapshot uses a different naming convention, or when two fields of the same type would otherwise produce duplicate keys.

Embedded structs and nesting

The provisioner inspects only the direct fields of *Env — it does not recurse into embedded structs.

Value-embedded structs (e.g. CoverageBase in environments.Host) are silently skipped because they have kind Struct, not Ptr. This is harmless as long as those helpers carry no components.Importable fields themselves.

// OK — CoverageBase is a value embed with no Importable fields.
// wireEnv skips it and still finds RemoteHost, FakeIntake, Agent, Updater.
type Host struct {
    CoverageBase                      // skipped (Struct, not Ptr)
    RemoteHost *components.RemoteHost // → key "remoteHost"
    FakeIntake *components.FakeIntake // → key "fakeIntake"
    Agent      *components.RemoteHostAgent  // → key "agent"
    Updater    *components.RemoteHostUpdater // → key "updater"
}

Embedding another environment struct by value does NOT work: its component pointer fields are invisible to wireEnv because Go reflection reports only the direct (non-promoted) fields at the outermost level.

// NOT OK — RemoteHost, FakeIntake, Agent, Updater inside Host are never seen.
type ExtendedHost struct {
    Host                            // skipped (Struct, not Ptr); its fields are invisible
    ExtraComp *components.FakeIntake // → key "extraComp" (only this is wired)
}

If you need to extend an existing environment, declare all component pointer fields directly on the outer struct and use `import` tags where the JSON keys must match a specific name.

This design means no `import` struct tags need to be added to built-in environment types such as [environments.Kubernetes], and no Pulumi provisioner code needs to change.

func NewStaticStackProvisioner added in v0.84.0

func NewStaticStackProvisioner[Env any](id string, filePath string) *StaticStackProvisioner[Env]

NewStaticStackProvisioner returns a new StaticStackProvisioner. Pass an empty id to use the default ("static-stack"). filePath must be the path to a single JSON descriptor file.

func (*StaticStackProvisioner[Env]) Destroy added in v0.84.0

Destroy is a no-op for the StaticStackProvisioner.

func (*StaticStackProvisioner[Env]) ID added in v0.84.0

func (fp *StaticStackProvisioner[Env]) ID() string

ID returns the provisioner's identifier.

func (*StaticStackProvisioner[Env]) ProvisionEnv added in v0.84.0

func (fp *StaticStackProvisioner[Env]) ProvisionEnv(_ context.Context, _ string, _ io.Writer, env *Env) (RawResources, error)

ProvisionEnv reads the JSON file, expands its top-level keys into RawResources, and wires the matching fields in *env.

type TypedProvisioner

type TypedProvisioner[Env any] interface {
	Provisioner
	ProvisionEnv(context.Context, string, io.Writer, *Env) (RawResources, error)
}

TypedProvisioner defines the interface for a provisioner with env binding

type UntypedProvisioner

type UntypedProvisioner interface {
	Provisioner
	Provision(context.Context, string, io.Writer) (RawResources, error)
}

UntypedProvisioner defines the interface for a provisioner without env binding

Directories

Path Synopsis
aws
docker
Package awsdocker contains the definition of the AWS Docker environment.
Package awsdocker contains the definition of the AWS Docker environment.
ecs
Package ecs contains the definition of the AWS ECS environment.
Package ecs contains the definition of the AWS ECS environment.
host
Package awshost contains the definition of the AWS Host environment.
Package awshost contains the definition of the AWS Host environment.
host/windows
Package winawshost contains the definition of the AWS Windows Host environment.
Package winawshost contains the definition of the AWS Windows Host environment.
kubernetes/eks
Package awskubernetes contains the provisioner for the Kubernetes based environments
Package awskubernetes contains the provisioner for the Kubernetes based environments
kubernetes/kindvm
Package kindvm contains the provisioner for the Kind-on-VM Kubernetes based environments
Package kindvm contains the provisioner for the Kind-on-VM Kubernetes based environments
kubernetes/kubeadm
Package kubeadm contains the provisioner for the kubeadm-on-VM Kubernetes based environments
Package kubeadm contains the provisioner for the kubeadm-on-VM Kubernetes based environments
azure
host/linux
Package azurehost contains the definition of the Azure Host environment.
Package azurehost contains the definition of the Azure Host environment.
host/windows
Package winazurehost contains the definition of the Azure Windows Host environment.
Package winazurehost contains the definition of the Azure Windows Host environment.
kubernetes
Package azurekubernetes contains the provisioner for Azure Kubernetes Service (AKS)
Package azurekubernetes contains the provisioner for Azure Kubernetes Service (AKS)
gcp
host/linux
Package gcphost contains the definition of the GCP Host environment.
Package gcphost contains the definition of the GCP Host environment.
kubernetes
Package gcpkubernetes contains the provisioner for Google Kubernetes Engine (GKE)
Package gcpkubernetes contains the provisioner for Google Kubernetes Engine (GKE)
kubernetes/openshiftvm
Package gcpopenshiftvm contains the provisioner for OpenShift VM on GCP
Package gcpopenshiftvm contains the provisioner for OpenShift VM on GCP
local
host
Package localhost contains the provisioner for the local Host based environments
Package localhost contains the provisioner for the local Host based environments
kubernetes
Package localkubernetes contains the provisioner for the local Kubernetes based environments
Package localkubernetes contains the provisioner for the local Kubernetes based environments

Jump to

Keyboard shortcuts

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