addon

package
v1.3.10 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 57 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// ReadmeFileName is the addon readme file name
	ReadmeFileName string = "readme.md"

	// MetadataFileName is the addon meatadata.yaml file name
	MetadataFileName string = "metadata.yaml"

	// TemplateFileName is the addon template.yaml file name
	TemplateFileName string = "template.yaml"

	// ResourcesDirName is the addon resources/ dir name
	ResourcesDirName string = "resources"

	// DefinitionsDirName is the addon definitions/ dir name
	DefinitionsDirName string = "definitions"

	// DefSchemaName is the addon definition schemas dir name
	DefSchemaName string = "schemas"

	// AddonParameterDataKey is the key of parameter in addon args secrets
	AddonParameterDataKey string = "addonParameterDataKey"

	// DefaultGiteeURL is the addon repository of gitee api
	DefaultGiteeURL string = "https://gitee.com/api/v5/"
)
View Source
const (
	// ObservabilityAddon is the name of the observability addon
	ObservabilityAddon = "observability"
	// ObservabilityAddonEndpointComponent is the endpoint component name of the observability addon
	ObservabilityAddonEndpointComponent = "grafana"
	// ObservabilityAddonDomainArg is the domain argument name of the observability addon
	ObservabilityAddonDomainArg = "domain"
	// LocalAddonRegistryName is the addon-registry name for those installed by local dir
	LocalAddonRegistryName = "local"
)
View Source
const (
	// ObservabilityEnvBindingEnvTag is the env Tag for env-binding settings for observability addon
	ObservabilityEnvBindingEnvTag = `        envs:`

	// ObservabilityEnvBindingEnvTmpl is the env values for env-binding settings for observability addon
	ObservabilityEnvBindingEnvTmpl = `` /* 206-byte string literal not displayed */

	// ObservabilityWorkflowStepsTag is the workflow steps Tag for observability addon
	ObservabilityWorkflowStepsTag = `steps:`

	// ObservabilityWorkflow4EnvBindingTmpl is the workflow for env-binding settings for observability addon
	ObservabilityWorkflow4EnvBindingTmpl = `` /* 184-byte string literal not displayed */

)
View Source
const (
	// EOFError is error returned by xml parse
	EOFError string = "EOF"
	// DirType means a directory
	DirType = "dir"
	// FileType means a file
	FileType = "file"
)

Variables

View Source
var (
	// UIMetaOptions get Addon metadata for UI display
	UIMetaOptions = ListOptions{GetDetail: true, GetDefinition: true, GetParameter: true}

	// CLIMetaOptions get Addon metadata for CLI display
	CLIMetaOptions = ListOptions{}

	// UnInstallOptions used for addon uninstalling
	UnInstallOptions = ListOptions{GetDefinition: true}
)
View Source
var (
	// ErrRenderCueTmpl is error when render addon's cue file
	ErrRenderCueTmpl = NewAddonError("fail to render cue tmpl")

	// ErrRateLimit means exceed GitHub access rate limit
	ErrRateLimit = NewAddonError("exceed github access rate limit")

	// ErrNotExist  means addon not exists
	ErrNotExist = NewAddonError("addon not exist")
)
View Source
var ErrorNoDomain = errors.New("domain is not set")

ErrorNoDomain is the error when no domain is found

View Source
var ParameterFileName = strings.Join([]string{"resources", "parameter.cue"}, "/")

ParameterFileName is the addon resources/parameter.cue file name

View Source
var Patterns = []Pattern{{Value: ReadmeFileName}, {Value: MetadataFileName}, {Value: TemplateFileName}, {Value: ParameterFileName}, {IsDir: true, Value: ResourcesDirName}, {IsDir: true, Value: DefinitionsDirName}, {IsDir: true, Value: DefSchemaName}}

Patterns is the file pattern that the addon should be in

Functions

func ClassifyItemByPattern

func ClassifyItemByPattern(meta *SourceMeta, r AsyncReader) map[string][]Item

ClassifyItemByPattern will filter and classify addon data, data will be classified by pattern it meets

func Convert2AppName

func Convert2AppName(name string) string

Convert2AppName -

func Convert2SecName

func Convert2SecName(name string) string

Convert2SecName generate addon argument secret name

func DisableAddon

func DisableAddon(ctx context.Context, cli client.Client, name string, config *rest.Config, force bool) error

DisableAddon will disable addon from cluster.

func EnableAddon

func EnableAddon(ctx context.Context, name string, version string, cli client.Client, discoveryClient *discovery.DiscoveryClient, apply apply.Applicator, config *rest.Config, r Registry, args map[string]interface{}, cache *Cache) error

EnableAddon will enable addon with dependency check, source is where addon from.

func EnableAddonByLocalDir

func EnableAddonByLocalDir(ctx context.Context, name string, dir string, cli client.Client, dc *discovery.DiscoveryClient, applicator apply.Applicator, config *rest.Config, args map[string]interface{}) error

EnableAddonByLocalDir enable an addon from local dir

func FetchAddonRelatedApp

func FetchAddonRelatedApp(ctx context.Context, cli client.Client, addonName string) (*v1beta1.Application, error)

FetchAddonRelatedApp will fetch the addon related app, this func will use NamespacedName(vela-system, addon-addonName) to get app if not find will try to get 1.1 legacy addon related app by using NamespacedName(vela-system, `addonName`)

func FetchArgsFromSecret added in v1.2.4

func FetchArgsFromSecret(sec *v1.Secret) (map[string]interface{}, error)

FetchArgsFromSecret fetch addon args from secrets

func GetPatternFromItem

func GetPatternFromItem(it Item, r AsyncReader, rootPath string) string

GetPatternFromItem will check if the file path has a valid pattern, return empty string if it's invalid. AsyncReader is needed to calculate relative path

func IsVersionRegistry added in v1.3.0

func IsVersionRegistry(r Registry) bool

IsVersionRegistry check the repo source if support multi-version addon

func NewAddonError

func NewAddonError(msg string) error

NewAddonError will return an

func RenderApp

func RenderApp(ctx context.Context, addon *InstallPackage, k8sClient client.Client, args map[string]interface{}) (*v1beta1.Application, error)

RenderApp render a K8s application

func RenderArgsSecret

func RenderArgsSecret(addon *InstallPackage, args map[string]interface{}) *unstructured.Unstructured

RenderArgsSecret render addon enable argument to secret

func RenderDefinitionSchema

func RenderDefinitionSchema(addon *InstallPackage) ([]*unstructured.Unstructured, error)

RenderDefinitionSchema will render definitions' schema in addons.

func RenderDefinitions

func RenderDefinitions(addon *InstallPackage, config *rest.Config) ([]*unstructured.Unstructured, error)

RenderDefinitions render definition objects if needed

func WrapErrRateLimit

func WrapErrRateLimit(err error) error

WrapErrRateLimit return ErrRateLimit if is the situation, or return error directly

Types

type AsyncReader

type AsyncReader interface {
	// ListAddonMeta will return directory tree contain addon metadata only
	ListAddonMeta() (addonCandidates map[string]SourceMeta, err error)

	// ReadFile should accept relative path to github repo/path or OSS bucket, and report the file content
	ReadFile(path string) (content string, err error)

	// RelativePath return a relative path to GitHub repo/path or OSS bucket/path
	RelativePath(item Item) string
}

AsyncReader helps async read files of addon

func NewAsyncReader

func NewAsyncReader(baseURL, bucket, subPath, token string, rdType ReaderType) (AsyncReader, error)

NewAsyncReader create AsyncReader from 1. GitHub url and directory 2. OSS endpoint and bucket

type Cache

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

Cache package only cache for 1 and 2, we don't cache InstallPackage, and it only read for real installation

func NewCache

func NewCache(ds RegistryDataStore) *Cache

NewCache will build a new cache instance

func (*Cache) DiscoverAndRefreshLoop

func (u *Cache) DiscoverAndRefreshLoop(cacheTime time.Duration)

DiscoverAndRefreshLoop will run a loop to automatically discovery and refresh addons from registry

func (*Cache) GetUIData

func (u *Cache) GetUIData(r Registry, addonName, version string) (*UIData, error)

GetUIData get addon data for UI display from cache, if cache not found, it will find from source

func (*Cache) ListAddonMeta

func (u *Cache) ListAddonMeta(r Registry) (map[string]SourceMeta, error)

ListAddonMeta will list metadata from registry, if cache not found, it will find from source

func (*Cache) ListUIData

func (u *Cache) ListUIData(r Registry) ([]*UIData, error)

ListUIData will always list UIData from cache first, if not exist, read from source.

type Client added in v1.3.0

type Client struct {
	Client  *http.Client
	BaseURL *url.URL
}

Client manages communication with the Gitee API

func NewGiteeClient added in v1.3.0

func NewGiteeClient(httpClient *http.Client, baseURL *url.URL) *Client

NewGiteeClient returns a new Gitee API client

func (*Client) GetGiteeContents added in v1.3.0

func (c *Client) GetGiteeContents(ctx context.Context, owner, repo, path, ref string) (fileContent *github.RepositoryContent, directoryContent []*github.RepositoryContent, err error)

GetGiteeContents can return either the metadata and content of a single file

type Dependency

type Dependency struct {
	Name string `json:"name,omitempty"`
}

Dependency defines the other addons it depends on

type DeployTo

type DeployTo struct {
	// This field keep the compatible for older case
	LegacyRuntimeCluster bool `json:"runtime_cluster"`
	DisableControlPlane  bool `json:"disableControlPlane"`
	RuntimeCluster       bool `json:"runtimeCluster"`
}

DeployTo defines where the addon to deploy to

type ElementFile

type ElementFile struct {
	Data string
	Name string
}

ElementFile can be addon's definition or addon's component

type File

type File struct {
	Name         string    `xml:"Key"`
	Size         int       `xml:"Size"`
	LastModified time.Time `xml:"LastModified"`
	Type         string    `xml:"Type"`
	StorageClass string    `xml:"StorageClass"`
}

File is for oss xml parse

type GitAddonSource

type GitAddonSource struct {
	URL   string `json:"url,omitempty" validate:"required"`
	Path  string `json:"path,omitempty"`
	Token string `json:"token,omitempty"`
}

GitAddonSource defines the information about the Git as addon source

func (*GitAddonSource) SafeCopy added in v1.3.4

func (g *GitAddonSource) SafeCopy() *GitAddonSource

SafeCopy hides field Token

type GiteeAddonSource added in v1.3.0

type GiteeAddonSource struct {
	URL   string `json:"url,omitempty" validate:"required"`
	Path  string `json:"path,omitempty"`
	Token string `json:"token,omitempty"`
}

GiteeAddonSource defines the information about the Gitee as addon source

func (*GiteeAddonSource) SafeCopy added in v1.3.4

func (g *GiteeAddonSource) SafeCopy() *GiteeAddonSource

SafeCopy hides field Token

type HelmSource added in v1.3.0

type HelmSource struct {
	URL string `json:"url,omitempty" validate:"required"`
}

HelmSource defines the information about the helm repo addon source

func (*HelmSource) SafeCopy added in v1.3.4

func (h *HelmSource) SafeCopy() *HelmSource

SafeCopy hides field Username, Password

type InstallPackage

type InstallPackage struct {
	Meta

	// Definitions and CUEDefinitions are converted as OAM X-Definitions, they will only in control plane cluster
	Definitions    []ElementFile `json:"definitions"`
	CUEDefinitions []ElementFile `json:"CUEDefinitions"`
	// DefSchemas are UI schemas read by VelaUX, it will only be installed in control plane clusters
	DefSchemas []ElementFile `json:"defSchemas,omitempty"`

	Parameters string `json:"parameters"`

	// CUETemplates and YAMLTemplates are resources needed to be installed in managed clusters
	CUETemplates  []ElementFile        `json:"CUETemplates"`
	YAMLTemplates []ElementFile        `json:"YAMLTemplates,omitempty"`
	AppTemplate   *v1beta1.Application `json:"appTemplate"`
}

InstallPackage contains all necessary files that can be installed for an addon

func GetInstallPackageFromReader

func GetInstallPackageFromReader(r AsyncReader, meta *SourceMeta, uiData *UIData) (*InstallPackage, error)

GetInstallPackageFromReader get install package of addon from Reader, this is used to enable an addon

type Installer

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

Installer helps addon enable, dependency-check, dispatch resources

func NewAddonInstaller

func NewAddonInstaller(ctx context.Context, cli client.Client, discoveryClient *discovery.DiscoveryClient, apply apply.Applicator, config *rest.Config, r *Registry, args map[string]interface{}, cache *Cache) Installer

NewAddonInstaller will create an installer for addon

type Item

type Item interface {
	// GetType return "dir" or "file"
	GetType() string
	GetPath() string
	GetName() string
}

Item is a partial interface for github.RepositoryContent

type ListBucketResult

type ListBucketResult struct {
	Files []File `xml:"Contents"`
	Count int    `xml:"KeyCount"`
}

ListBucketResult describe a file list from OSS

type ListOptions

type ListOptions struct {
	GetDetail     bool
	GetDefinition bool
	GetResource   bool
	GetParameter  bool
	GetTemplate   bool
	GetDefSchema  bool
}

ListOptions contains flags mark what files should be read in an addon directory

type MemoryReader added in v1.3.0

type MemoryReader struct {
	Name  string
	Files []*loader.BufferedFile
	// contains filtered or unexported fields
}

MemoryReader is async reader for memory data

func (*MemoryReader) ListAddonMeta added in v1.3.0

func (l *MemoryReader) ListAddonMeta() (map[string]SourceMeta, error)

ListAddonMeta list all metadata of helm repo registry

func (*MemoryReader) ReadFile added in v1.3.0

func (l *MemoryReader) ReadFile(path string) (string, error)

ReadFile ready file from memory

func (*MemoryReader) RelativePath added in v1.3.0

func (l *MemoryReader) RelativePath(item Item) string

RelativePath calculate the relative path of one file

type Meta

type Meta struct {
	Name               string              `json:"name" validate:"required"`
	Version            string              `json:"version"`
	Description        string              `json:"description"`
	Icon               string              `json:"icon"`
	URL                string              `json:"url,omitempty"`
	Tags               []string            `json:"tags,omitempty"`
	DeployTo           *DeployTo           `json:"deployTo,omitempty"`
	Dependencies       []*Dependency       `json:"dependencies,omitempty"`
	NeedNamespace      []string            `json:"needNamespace,omitempty"`
	Invisible          bool                `json:"invisible"`
	SystemRequirements *SystemRequirements `json:"system,omitempty"`
}

Meta defines the format for a single addon

type OSSAddonSource

type OSSAddonSource struct {
	Endpoint string `json:"end_point" validate:"required"`
	Bucket   string `json:"bucket"`
	Path     string `json:"path"`
}

OSSAddonSource is UIData source from alibaba cloud OSS style source

type OSSItem

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

OSSItem is Item implement for OSS

func (OSSItem) GetName

func (i OSSItem) GetName() string

GetName from OSSItem

func (OSSItem) GetPath

func (i OSSItem) GetPath() string

GetPath from OSSItem

func (OSSItem) GetType

func (i OSSItem) GetType() string

GetType from OSSItem

type ObservabilityEnvBindingValues

type ObservabilityEnvBindingValues struct {
	Envs []ObservabilityEnvironment
}

ObservabilityEnvBindingValues is a list of ObservabilityEnvironment and will be used to render observability-env-binding.yaml

type ObservabilityEnvironment

type ObservabilityEnvironment struct {
	Cluster           string
	Domain            string
	LoadBalancerIP    string
	ServiceExternalIP string
}

ObservabilityEnvironment contains the Observability addon's domain for each cluster

func GetObservabilityAccessibilityInfo

func GetObservabilityAccessibilityInfo(ctx context.Context, k8sClient client.Client, domain string) ([]ObservabilityEnvironment, error)

GetObservabilityAccessibilityInfo will get the accessibility info of addon in local cluster and multiple clusters

type Pattern

type Pattern struct {
	IsDir bool
	Value string
}

Pattern indicates the addon framework file pattern, all files should match at least one of the pattern.

type ReaderType

type ReaderType string

ReaderType marks where to read addon files

type Registry

type Registry struct {
	Name string `json:"name"`

	Helm  *HelmSource       `json:"helm,omitempty"`
	Git   *GitAddonSource   `json:"git,omitempty"`
	OSS   *OSSAddonSource   `json:"oss,omitempty"`
	Gitee *GiteeAddonSource `json:"gitee,omitempty"`
}

Registry represent a addon registry model

func (*Registry) BuildReader

func (r *Registry) BuildReader() (AsyncReader, error)

BuildReader will build a AsyncReader from registry, AsyncReader are needed to read addon files

func (*Registry) GetInstallPackage

func (r *Registry) GetInstallPackage(meta *SourceMeta, uiData *UIData) (*InstallPackage, error)

GetInstallPackage get install package which is all needed to enable an addon from addon registry

func (*Registry) GetUIData

func (r *Registry) GetUIData(meta *SourceMeta, opt ListOptions) (*UIData, error)

GetUIData get UIData of an addon

func (*Registry) ListAddonMeta

func (r *Registry) ListAddonMeta() (map[string]SourceMeta, error)

ListAddonMeta list addon file meta(path and name) from a registry

func (*Registry) ListUIData

func (r *Registry) ListUIData(registryAddonMeta map[string]SourceMeta, opt ListOptions) ([]*UIData, error)

ListUIData list UI data from addon registry

type RegistryDataStore

type RegistryDataStore interface {
	ListRegistries(context.Context) ([]Registry, error)
	AddRegistry(context.Context, Registry) error
	DeleteRegistry(context.Context, string) error
	UpdateRegistry(context.Context, Registry) error
	GetRegistry(context.Context, string) (Registry, error)
}

RegistryDataStore CRUD addon registry data in configmap

func NewRegistryDataStore

func NewRegistryDataStore(cli client.Client) RegistryDataStore

NewRegistryDataStore get RegistryDataStore operation interface

type SafeCopier added in v1.3.4

type SafeCopier interface {
	SafeCopy() interface{}
}

SafeCopier is an interface to copy Struct without sensitive fields, such as Token, Username, Password

type Source

type Source interface {
	GetUIData(meta *SourceMeta, opt ListOptions) (*UIData, error)
	ListUIData(registryAddonMeta map[string]SourceMeta, opt ListOptions) ([]*UIData, error)
	GetInstallPackage(meta *SourceMeta, uiData *UIData) (*InstallPackage, error)
	ListAddonMeta() (map[string]SourceMeta, error)
}

Source is where to get addons, Registry implement this interface

type SourceMeta

type SourceMeta struct {
	Name  string
	Items []Item
}

SourceMeta record the whole metadata of an addon

type Status

type Status struct {
	AddonPhase string
	AppStatus  *commontypes.AppStatus
	// the status of multiple clusters
	Clusters         map[string]map[string]interface{} `json:"clusters,omitempty"`
	InstalledVersion string
}

Status contain addon phase and related app status

func GetAddonStatus

func GetAddonStatus(ctx context.Context, cli client.Client, name string) (Status, error)

GetAddonStatus is genrall func for cli and apiServer get addon status

type SystemRequirements added in v1.2.4

type SystemRequirements struct {
	VelaVersion       string `json:"vela,omitempty"`
	KubernetesVersion string `json:"kubernetes,omitempty"`
}

SystemRequirements is this addon need version

type UIData

type UIData struct {
	Meta

	APISchema *openapi3.Schema     `json:"schema"`
	UISchema  []*utils.UIParameter `json:"uiSchema"`

	// Detail is README.md in an addon
	Detail string `json:"detail,omitempty"`

	Definitions    []ElementFile `json:"definitions"`
	CUEDefinitions []ElementFile `json:"CUEDefinitions"`
	Parameters     string        `json:"parameters"`
	RegistryName   string        `json:"registryName"`

	AvailableVersions []string `json:"availableVersions"`
}

UIData contains all information represent an addon for UI

func GetUIDataFromReader

func GetUIDataFromReader(r AsyncReader, meta *SourceMeta, opt ListOptions) (*UIData, error)

GetUIDataFromReader read ui metadata of addon from Reader, used to be displayed in UI

func ListAddonUIDataFromReader

func ListAddonUIDataFromReader(r AsyncReader, registryMeta map[string]SourceMeta, registryName string, opt ListOptions) ([]*UIData, error)

ListAddonUIDataFromReader list addons from AsyncReader

type VersionUnMatchError added in v1.3.1

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

VersionUnMatchError means addon system requirement cannot meet requirement

func (VersionUnMatchError) Error added in v1.3.1

func (v VersionUnMatchError) Error() string

type VersionedRegistry added in v1.3.0

type VersionedRegistry interface {
	ListAddon() ([]*UIData, error)
	GetAddonUIData(ctx context.Context, addonName, version string) (*UIData, error)
	GetAddonInstallPackage(ctx context.Context, addonName, version string) (*InstallPackage, error)
}

VersionedRegistry is the interface of support version registry

func BuildVersionedRegistry added in v1.3.0

func BuildVersionedRegistry(name, repoURL string) VersionedRegistry

BuildVersionedRegistry is build versioned addon registry

type WholeAddonPackage added in v1.3.0

type WholeAddonPackage struct {
	InstallPackage

	APISchema *openapi3.Schema `json:"schema"`

	// Detail is README.md in an addon
	Detail            string   `json:"detail,omitempty"`
	AvailableVersions []string `json:"availableVersions"`
}

WholeAddonPackage contains all infos of an addon

Jump to

Keyboard shortcuts

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