charm

package
v0.0.0-...-2f78cd6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: AGPL-3.0 Imports: 12 Imported by: 21

Documentation

Index

Constants

View Source
const (
	// DefaultChannelString represents the default track and risk if nothing
	// is found.
	DefaultChannelString = "stable"
)

Variables

View Source
var (
	// DefaultChannel represents the default track and risk.
	DefaultChannel = charm.Channel{
		Risk: charm.Stable,
	}
	// DefaultRiskChannel represents the default only risk channel.
	DefaultRiskChannel = charm.Channel{
		Risk: charm.Stable,
	}
)
View Source
var MissingBaseError = errors.ConstError("charm does not define any bases")

MissingBaseError is used to denote that BaseForCharm could not determine a base because a legacy charm did not declare any.

Functions

func BaseForCharm

func BaseForCharm(requestedBase base.Base, supportedBases []base.Base) (base.Base, error)

BaseForCharm takes a requested base and a list of bases supported by a charm and returns the base which is relevant. If the requested base is empty, then the first supported base is used, otherwise the requested base is validated against the supported bases.

func BaseIsCompatibleWithCharm

func BaseIsCompatibleWithCharm(b base.Base, c charm.CharmMeta) error

BaseIsCompatibleWithCharm returns nil if the provided charm is compatible with the provided base. Otherwise, return an UnsupportedBaseError

func CharmNotFound

func CharmNotFound(url string) error

CharmNotFound returns an error indicating that the charm at the specified URL does not exist.

func ComputedBases

func ComputedBases(c charm.CharmMeta) ([]base.Base, error)

ComputedBases of a charm, preserving legacy behaviour. For charms prior to v2, fall back the metadata series can convert to bases

func InvalidPath

func InvalidPath(path string) error

InvalidPath returns an invalidPathError.

func IsInvalidPathError

func IsInvalidPathError(err error) bool

func IsKubernetes

func IsKubernetes(cm charm.CharmMeta) bool

IsKubernetes reports whether the given charm should be deployed to Kubernetes, that is, a v1 charm with series "kubernetes", or a v2 charm with containers specified.

func IsUnsupportedBaseError

func IsUnsupportedBaseError(err error) bool

IsUnsupportedBaseError returns true if err is an UnsupportedSeriesError.

func MustParseChannel

func MustParseChannel(s string) charm.Channel

MustParseChannel parses a given string or returns a panic.

func NewCharmAtPath

func NewCharmAtPath(path string) (charm.Charm, *charm.URL, error)

NewCharmAtPath returns the charm represented by this path, and a URL that describes it.

func NewCharmInfoAdapter

func NewCharmInfoAdapter(meta EssentialMetadata) charmInfoAdapter

func NewUnsupportedBaseError

func NewUnsupportedBaseError(requestedBase base.Base, supportedBases []base.Base) error

NewUnsupportedBaseError returns an error indicating that the requested series is not supported by a charm.

func OSIsCompatibleWithCharm

func OSIsCompatibleWithCharm(os string, c charm.CharmMeta) error

OSIsCompatibleWithCharm returns nil is any of the bases the charm supports has an os which matched the provided os. Otherwise, return a NotSupported error

Types

type BaseSelector

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

BaseSelector is a helper type that determines what base the charm should be deployed to.

func ConfigureBaseSelector

func ConfigureBaseSelector(cfg SelectorConfig) (BaseSelector, error)

ConfigureBaseSelector returns a configured and validated BaseSelector

func (BaseSelector) CharmBase

func (s BaseSelector) CharmBase() (selectedBase base.Base, err error)

CharmBase determines what base to use with a charm. Order of preference is:

  • user requested with --base or defined by bundle when deploying
  • model default, if set, acts like --base
  • juju's default supported Ubuntu LTS (if compatible with valid charm bases)
  • the first supported base in the charm manifest
  • in the case of local charms with no manifest nor base in metadata, base must be provided by the user.

type CharmArchive

type CharmArchive interface {
	charm.Charm

	Version() string
	LXDProfile() *charm.LXDProfile
}

CharmArchive provides information about a downloaded charm archive.

type CharmID

type CharmID struct {
	// URL is the url of the charm.
	URL *charm.URL

	// Origin holds the original source of a charm, including its channel.
	Origin Origin

	// Metadata is optional extra information about a particular model's
	// "in-theatre" use of the charm.
	Metadata map[string]string
}

CharmID encapsulates data for identifying a unique charm in a charm repository.

type EssentialMetadata

type EssentialMetadata struct {
	ResolvedOrigin Origin

	Meta     *charm.Meta
	Manifest *charm.Manifest
	Config   *charm.Config
}

EssentialMetadata encapsulates the essential metadata required for deploying a particular charm.

type MetadataFormat

type MetadataFormat int

MetadataFormat of the parsed charm.

const (
	FormatUnknown MetadataFormat = iota
	FormatV1      MetadataFormat = iota
	FormatV2      MetadataFormat = iota
)

MetadataFormat are the different versions of charm metadata supported.

func Format

func Format(ch charm.CharmMeta) MetadataFormat

Format returns the metadata format for a given charm.

type MetadataRequest

type MetadataRequest struct {
	CharmName string
	Origin    Origin
}

MetadataRequest encapsulates the arguments for a charm essential metadata resolution request.

type Origin

type Origin struct {
	Source Source
	Type   string
	ID     string
	Hash   string

	// Users can request a revision to be installed instead of a channel, so
	// we should model that correctly here.
	Revision *int
	Channel  *charm.Channel
	Platform Platform

	// InstanceKey is an optional unique string associated with the application.
	// To assist with keeping KPI data in charmhub, it must be the same for every
	// charmhub Refresh action for the Refresh api endpoint related to an
	// application. For all other actions, a random uuid will used when the request
	// is sent. Create with the charmhub.CreateInstanceKey method. LP: 1944582
	InstanceKey string
}

Origin holds the original source of a charm. Information about where the charm was installed from (charm-hub, charm-store, local) and any additional information we can utilise when making modelling decisions for upgrading or changing.

type Platform

type Platform struct {
	Architecture string
	OS           string
	Channel      string
}

Platform describes the platform used to install the charm with.

func MustParsePlatform

func MustParsePlatform(s string) Platform

MustParsePlatform parses a given string or returns a panic.

func ParsePlatform

func ParsePlatform(s string) (Platform, error)

ParsePlatform parses a string representing a store platform. Serialized version of platform can be expected to conform to the following:

  1. Architecture is mandatory.
  2. OS is optional and can be dropped. Release is mandatory if OS wants to be displayed.
  3. Release is also optional.

To indicate something is missing `unknown` can be used in place.

Examples:

  1. `<arch>/<os>/<channel>`
  2. `<arch>`
  3. `<arch>/<series>`
  4. `<arch>/unknown/<series>`

func ParsePlatformNormalize

func ParsePlatformNormalize(s string) (Platform, error)

ParsePlatformNormalize parses a string presenting a store platform. The returned platform's architecture, os and series are normalized.

func (Platform) Normalize

func (p Platform) Normalize() Platform

Normalize the platform with normalized architecture, os and channel.

func (Platform) String

func (p Platform) String() string

type Repository

type Repository interface {
	// GetDownloadURL returns a url from which a charm can be downloaded
	// based on the given charm url and charm origin.  A charm origin
	// updated with the ID and hash for the download is also returned.
	GetDownloadURL(string, Origin) (*url.URL, Origin, error)

	// DownloadCharm retrieves specified charm from the store and saves its
	// contents to the specified path.
	DownloadCharm(charmName string, requestedOrigin Origin, archivePath string) (CharmArchive, Origin, error)

	// ResolveWithPreferredChannel verified that the charm with the requested
	// channel exists.  If no channel is specified, the latests, most stable is
	// used. It returns a charm URL which includes the most current revision,
	// if none was provided, a charm origin, and a slice of series supported by
	// this charm.
	ResolveWithPreferredChannel(string, Origin) (*charm.URL, Origin, []Platform, error)

	// GetEssentialMetadata resolves each provided MetadataRequest and
	// returns back a slice with the results. The results include the
	// minimum set of metadata that is required for deploying each charm.
	GetEssentialMetadata(...MetadataRequest) ([]EssentialMetadata, error)

	// ListResources returns a list of resources associated with a given charm.
	ListResources(string, Origin) ([]charmresource.Resource, error)

	// ResolveResources looks at the provided repository and backend (already
	// downloaded) resources to determine which to use. Provided (uploaded) take
	// precedence. If charmhub has a newer resource than the back end, use that.
	ResolveResources(resources []charmresource.Resource, id CharmID) ([]charmresource.Resource, error)

	// ResolveForDeploy does the same thing as ResolveWithPreferredChannel
	// returning EssentialMetadata also. Resources are returned if a
	// charm revision was not provided in the CharmID.
	ResolveForDeploy(CharmID) (ResolvedDataForDeploy, error)
}

Repository describes an API for querying charm/bundle information and downloading them from a store.

type RepositoryFactory

type RepositoryFactory interface {
	GetCharmRepository(src Source) (Repository, error)
}

RepositoryFactory is a factory for charm Repositories.

type ResolvedDataForDeploy

type ResolvedDataForDeploy struct {
	URL *charm.URL

	EssentialMetadata EssentialMetadata

	// Resources is a map of resource names to their current repository revision
	// based on the supplied origin
	Resources map[string]charmresource.Resource
}

ResolvedDataForDeploy is the response data from ResolveForDeploy

type SelectorConfig

type SelectorConfig struct {
	Config              SelectorModelConfig
	Force               bool
	Logger              SelectorLogger
	RequestedBase       base.Base
	SupportedCharmBases []base.Base
	WorkloadBases       []base.Base
	// usingImageID is true when the user is using the image-id constraint
	// when deploying the charm. This is needed to validate that in that
	// case the user is also explicitly providing a base.
	UsingImageID bool
}

type SelectorLogger

type SelectorLogger interface {
	Infof(string, ...interface{})
	Tracef(string, ...interface{})
}

SelectorLogger defines the logging methods needed

type SelectorModelConfig

type SelectorModelConfig interface {
	// DefaultBase returns the configured default base
	// for the environment, and whether the default base was
	// explicitly configured on the environment.
	DefaultBase() (string, bool)
}

type Source

type Source string

Source represents the source of the charm.

const (
	// Local represents a local charm.
	Local Source = "local"
	// CharmHub represents a charm from the new charmHub.
	CharmHub Source = "charm-hub"
)

func (Source) Matches

func (c Source) Matches(o string) bool

Matches attempts to match a string to a given source.

func (Source) String

func (c Source) String() string

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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