bootstrap

package
v0.0.0-...-b9bb202 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 56 Imported by: 0

Documentation

Overview

Package bootstrap ensures that when the initial bootstrap process has started that we seed the following:

  1. The macaroon config keypairs are generated.
  2. The initial juju-metrics user is registered.
  3. The agent binary is seeded into the objectstore.
  4. The initial storage pools are created.
  5. The controller application has been created, along with the supporting machine and spaces.
  6. The controller charm is seeded into the objectstore.
  7. Seed any extra authorised keys into the controller model.
  8. Finally, set a flag to indicate bootstrap has been completed

The intention is that the worker is started as soon as possible during bootstrap and that it will uninstall itself once the bootstrap process has completed.

If any of these steps fail, the bootstrap worker will restart. So it is important that seeding processes are idempotent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CAASAgentBinaryUploader

CAASAgentBinaryUploader is the function that is used to populate the tools for CAAS.

func CAASControllerCharmUploader

func CAASControllerCharmUploader(cfg ControllerCharmDeployerConfig) (bootstrap.ControllerCharmDeployer, error)

CAASControllerCharmUploader is the function that is used to upload the controller charm for CAAS.

func CAASControllerUnitPassword

func CAASControllerUnitPassword(context.Context) (string, error)

CAASControllerUnitPassword is the function that is used to get the unit password for CAAS. This is currently retrieved from the environment variable.

func IAASAgentBinaryUploader

func IAASAgentBinaryUploader(ctx context.Context, dataDir string, storageService BinaryAgentStorageService, objectStore objectstore.ObjectStore, logger logger.Logger) (func(), error)

IAASAgentBinaryUploader is the function that is used to populate the tools for IAAS.

func IAASControllerCharmUploader

func IAASControllerCharmUploader(cfg ControllerCharmDeployerConfig) (bootstrap.ControllerCharmDeployer, error)

IAASControllerCharmUploader is the function that is used to upload the controller charm for CAAS.

func IAASControllerUnitPassword

func IAASControllerUnitPassword(context.Context) (string, error)

IAASControllerUnitPassword is the function that is used to get the unit password for IAAS.

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency manifold that runs the trace worker.

func NewWorker

func NewWorker(cfg WorkerConfig) (*bootstrapWorker, error)

NewWorker creates a new bootstrap worker.

func PopulateControllerCharm

func PopulateControllerCharm(ctx context.Context, controllerCharmDeployer bootstrap.ControllerCharmDeployer) error

PopulateControllerCharm is the function that is used to populate the controller charm.

func RequiresBootstrap

func RequiresBootstrap(ctx context.Context, flagService FlagService) (bool, error)

RequiresBootstrap is the function that is used to check if the bootstrap process has completed.

Types

type AgentBinaryBootstrapFunc

type AgentBinaryBootstrapFunc func(context.Context, string, BinaryAgentStorageService, objectstore.ObjectStore, logger.Logger) (func(), error)

AgentBinaryBootstrapFunc is the function that is used to populate the tools.

type ApplicationService

type ApplicationService interface {
	// CreateApplication creates a new application with the given name and
	// charm.
	CreateApplication(
		context.Context, string, charm.Charm, corecharm.Origin,
		applicationservice.AddApplicationArgs, ...applicationservice.AddUnitArg,
	) (coreapplication.ID, error)

	// ResolveControllerCharmDownload resolves the controller charm download slot.
	ResolveControllerCharmDownload(
		ctx context.Context,
		resolve application.ResolveControllerCharmDownload,
	) (application.ResolvedControllerCharmDownload, error)

	// UpdateApplication updates the application with the given name.
	UpdateCAASUnit(ctx context.Context, unitName unit.Name, params applicationservice.UpdateCAASUnitParams) error

	// SetUnitPassword sets the password for the given unit.
	SetUnitPassword(ctx context.Context, unitName unit.Name, passwordHash string) error
}

ApplicationService instances save an application to dqlite state.

type BakeryConfigService

type BakeryConfigService interface {
	InitialiseBakeryConfig(context.Context) error
}

BakeryConfigService describes the service used to initialise the maccaroon bakery config

type BinaryAgentStorage

type BinaryAgentStorage interface {
	// Add adds the agent binary to the storage.
	Add(context.Context, io.Reader, binarystorage.Metadata) error
	// Close closes the storage.
	Close() error
}

BinaryAgentStorage is the interface that is used to store the agent binary.

type BinaryAgentStorageService

type BinaryAgentStorageService interface {
	AgentBinaryStorage(objectstore.ObjectStore) (BinaryAgentStorage, error)
}

BinaryAgentStorageService is the interface that is used to get the storage for the agent binary.

type BootstrapAddressFinderFunc

type BootstrapAddressFinderFunc func(context.Context, instance.Id) (network.ProviderAddresses, error)

BootstrapAddressFinderFunc is responsible for finding the network provider addresses for a bootstrap instance.

func BootstrapAddressFinder

func BootstrapAddressFinder(
	providerGetter providertracker.ProviderGetter[environs.InstanceLister],
) BootstrapAddressFinderFunc

BootstrapAddressFinder is responsible for finding the bootstrap network addresses for a bootstrap instance. If the provider does not implement the environs.InstanceLister interface then "localhost" will be returned. This is the case for CAAS providers.

type CloudService

type CloudService interface {
	Cloud(context.Context, string) (*cloud.Cloud, error)
}

CloudService is the interface that is used to interact with the cloud.

type ControllerCharmDeployerConfig

type ControllerCharmDeployerConfig struct {
	StateBackend                SystemState
	ApplicationService          ApplicationService
	Model                       coremodel.Model
	ModelConfigService          ModelConfigService
	ObjectStore                 objectstore.ObjectStore
	ControllerConfig            controller.Config
	DataDir                     string
	BootstrapMachineConstraints constraints.Value
	ControllerCharmName         string
	ControllerCharmChannel      charm.Channel
	CharmhubHTTPClient          HTTPClient
	UnitPassword                string
	Logger                      logger.Logger
}

ControllerCharmDeployerConfig holds the configuration for the ControllerCharmDeployer.

type ControllerCharmDeployerFunc

type ControllerCharmDeployerFunc func(ControllerCharmDeployerConfig) (bootstrap.ControllerCharmDeployer, error)

ControllerCharmDeployerFunc is the function that is used to upload the controller charm.

type ControllerConfigService

type ControllerConfigService interface {
	ControllerConfig(context.Context) (controller.Config, error)
}

ControllerConfigService is the interface that is used to get the controller configuration.

type ControllerUnitPasswordFunc

type ControllerUnitPasswordFunc func(context.Context) (string, error)

ControllerUnitPasswordFunc is the function that is used to get the controller unit password.

type FlagService

type FlagService interface {
	GetFlag(context.Context, string) (bool, error)
	SetFlag(context.Context, string, bool, string) error
}

FlagService is the interface that is used to set the value of a flag.

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient is the interface that is used to make HTTP requests.

type KeyManagerService

type KeyManagerService interface {
	// AddPublicKeysForUser is responsible for adding public keys to a user in
	// this model. If no keys are supplied then no operation will take place.
	AddPublicKeysForUser(context.Context, user.UUID, ...string) error
}

KeyManagerService provides access to the authorised keys for individual users of a model.

type MachineService

type MachineService interface {
	// GetMachineUUID returns the UUID of a machine identified by its name.
	GetMachineUUID(ctx context.Context, name machine.Name) (string, error)
	// SetMachineCloudInstance sets an entry in the machine cloud instance table
	// along with the instance tags and the link to a lxd profile if any.
	SetMachineCloudInstance(
		ctx context.Context,
		machineUUID string,
		instanceID instance.Id,
		displayName string,
		hardwareCharacteristics *instance.HardwareCharacteristics,
	) error
	// InstanceIDAndName returns the cloud specific instance ID and display name for
	// this machine.
	InstanceIDAndName(ctx context.Context, machineUUID string) (instance.Id, string, error)
}

MachineService provides access to the machine domain. Used here to set the machine cloud instance data.

type ManifoldConfig

type ManifoldConfig struct {
	AgentName           string
	StateName           string
	ObjectStoreName     string
	BootstrapGateName   string
	DomainServicesName  string
	HTTPClientName      string
	ProviderFactoryName string
	StorageRegistryName string

	AgentBinaryUploader     AgentBinaryBootstrapFunc
	ControllerCharmDeployer ControllerCharmDeployerFunc
	ControllerUnitPassword  ControllerUnitPasswordFunc
	RequiresBootstrap       RequiresBootstrapFunc
	PopulateControllerCharm PopulateControllerCharmFunc

	Logger logger.Logger
}

ManifoldConfig defines the configuration for the trace manifold.

func (ManifoldConfig) Validate

func (cfg ManifoldConfig) Validate() error

Validate validates the manifold configuration.

type ModelConfigService

type ModelConfigService interface {
	// ModelConfig returns the current config for the model.
	ModelConfig(context.Context) (*config.Config, error)
}

ModelConfigService provides access to the model configuration.

type ModelService

type ModelService interface {
	// ControllerModel returns the representation of the model that is used for
	// running the Juju controller.
	// Should this model not have been established yet an error satisfying
	// [github.com/juju/juju/domain/model/errors.NotFound] will be returned.
	ControllerModel(context.Context) (model.Model, error)
}

ModelService provides a means for interacting with the underlying models of this controller

type NetworkService

type NetworkService interface {
	// Space returns a space from state that matches the input ID.
	// An error is returned if the space does not exist or if there was a problem
	// accessing its information.
	Space(ctx context.Context, uuid string) (*network.SpaceInfo, error)
	// SpaceByName returns a space from state that matches the input name.
	// An error is returned that satisfied errors.NotFound if the space was not found
	// or an error static any problems fetching the given space.
	SpaceByName(ctx context.Context, name string) (*network.SpaceInfo, error)
	// GetAllSpaces returns all spaces for the model.
	GetAllSpaces(ctx context.Context) (network.SpaceInfos, error)
	// ReloadSpaces loads spaces and subnets from the provider into state.
	ReloadSpaces(ctx context.Context) error
}

NetworkService is the interface that is used to interact with the network spaces/subnets.

type ObjectStoreGetter

type ObjectStoreGetter interface {
	// GetObjectStore returns a object store for the given namespace.
	GetObjectStore(context.Context, string) (objectstore.ObjectStore, error)
}

ObjectStoreGetter is the interface that is used to get a object store.

type PopulateControllerCharmFunc

type PopulateControllerCharmFunc func(context.Context, bootstrap.ControllerCharmDeployer) error

PopulateControllerCharmFunc is the function that is used to populate the controller charm.

type RequiresBootstrapFunc

type RequiresBootstrapFunc func(context.Context, FlagService) (bool, error)

RequiresBootstrapFunc is the function that is used to check if the bootstrap process has completed.

type StorageService

type StorageService interface {
	CreateStoragePool(ctx context.Context, name string, providerType storage.ProviderType, attrs storageservice.PoolAttrs) error
}

StorageService instances save a storage pool to dqlite state.

type SystemState deprecated

type SystemState interface {
	// ToolsStorage returns a new binarystorage.StorageCloser that stores tools
	// metadata in the "juju" database "toolsmetadata" collection.
	ToolsStorage(store objectstore.ObjectStore) (binarystorage.StorageCloser, error)
	// AddApplication adds an application to the model.
	AddApplication(state.AddApplicationArgs, objectstore.ObjectStore) (bootstrap.Application, error)
	// Charm returns the charm with the given name.
	Charm(string) (charm.Charm, error)
	// Unit returns the unit with the given id.
	Unit(string) (bootstrap.Unit, error)
	// Machine returns the machine with the given id.
	Machine(string) (bootstrap.Machine, error)
	// PrepareLocalCharmUpload returns the charm URL that should be used to
	// upload the charm.
	PrepareLocalCharmUpload(url string) (chosenURL *charm.URL, err error)
	// ApplyOperation applies the given operation.
	ApplyOperation(*state.UpdateUnitOperation) error
	// CloudService returns the cloud service for the given cloud.
	CloudService(string) (bootstrap.CloudService, error)
	// SetAPIHostPorts sets the addresses, if changed, of two collections:
	//   - The list of *all* addresses at which the API is accessible.
	//   - The list of addresses at which the API can be accessed by agents according
	//     to the controller management space configuration.
	//
	// Each server is represented by one element in the top level slice.
	SetAPIHostPorts(controllerConfig controller.Config, newHostPorts []network.SpaceHostPorts, newHostPortsForAgents []network.SpaceHostPorts) error
	// SaveCloudService creates a cloud service.
	SaveCloudService(args state.SaveCloudServiceArgs) (*state.CloudService, error)
}

SystemState is the interface that is used to get the legacy state (mongo).

Note: It is expected over time for each one of these methods to be replaced with a domain service.

Deprecated: Use domain services when available.

type UserService

type UserService interface {
	// AddUser will add a new user to the database and return the UUID of the
	// user if successful. If no password is set in the incoming argument,
	// the user will be added with an activation key.
	AddUser(ctx context.Context, arg userservice.AddUserArg) (user.UUID, []byte, error)

	// AddExternalUser adds a new external user to the database and does not set a
	// password or activation key.
	// The following error types are possible from this function:
	//   - accesserrors.UserNameNotValid: When the username supplied is not
	//     valid.
	//   - accesserrors.UserAlreadyExists: If a user with the supplied name
	//     already exists.
	//   - accesserrors.CreatorUUIDNotFound: If the creator supplied for the
	//     user does not exist.
	AddExternalUser(ctx context.Context, name user.Name, displayName string, creatorUUID user.UUID) error

	// GetUserByName will return the user with the given name.
	GetUserByName(ctx context.Context, name user.Name) (user.User, error)
}

UserService is the interface that is used to add a new user to the database.

type WorkerConfig

type WorkerConfig struct {
	Agent                   agent.Agent
	ObjectStoreGetter       ObjectStoreGetter
	ControllerConfigService ControllerConfigService
	CloudService            CloudService
	UserService             UserService
	StorageService          StorageService
	ProviderRegistry        storage.ProviderRegistry
	ApplicationService      ApplicationService
	ControllerModel         coremodel.Model
	ModelConfigService      ModelConfigService
	MachineService          MachineService
	KeyManagerService       KeyManagerService
	FlagService             FlagService
	NetworkService          NetworkService
	BakeryConfigService     BakeryConfigService
	BootstrapUnlocker       gate.Unlocker
	AgentBinaryUploader     AgentBinaryBootstrapFunc
	ControllerCharmDeployer ControllerCharmDeployerFunc
	PopulateControllerCharm PopulateControllerCharmFunc
	CharmhubHTTPClient      HTTPClient
	UnitPassword            string
	BootstrapAddressFinder  BootstrapAddressFinderFunc
	Logger                  logger.Logger

	// Deprecated: This is only here, until we can remove the state layer.
	SystemState SystemState
}

WorkerConfig encapsulates the configuration options for the bootstrap worker.

func (*WorkerConfig) Validate

func (c *WorkerConfig) Validate() error

Validate ensures that the config values are valid.

Jump to

Keyboard shortcuts

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