Documentation
¶
Index ¶
- Constants
- Variables
- func ClassifyItemByPattern(meta *SourceMeta, r AsyncReader) map[string][]Item
- func Convert2AppName(name string) string
- func Convert2SecName(name string) string
- func DisableAddon(ctx context.Context, cli client.Client, name string) error
- func EnableAddon(ctx context.Context, name string, cli client.Client, apply apply.Applicator, ...) error
- func EnableAddonByLocalDir(ctx context.Context, name string, dir string, cli client.Client, ...) error
- func FetchAddonRelatedApp(ctx context.Context, cli client.Client, addonName string) (*v1beta1.Application, error)
- func GetPatternFromItem(it Item, r AsyncReader, rootPath string) string
- func NewAddonError(msg string) error
- func RenderApp(ctx context.Context, addon *InstallPackage, config *rest.Config, ...) (*v1beta1.Application, error)
- func RenderArgsSecret(addon *InstallPackage, args map[string]interface{}) *unstructured.Unstructured
- func RenderDefinitionSchema(addon *InstallPackage) ([]*unstructured.Unstructured, error)
- func RenderDefinitions(addon *InstallPackage, config *rest.Config) ([]*unstructured.Unstructured, error)
- func WrapErrRateLimit(err error) error
- type AsyncReader
- type Cache
- type Dependency
- type DeployTo
- type ElementFile
- type File
- type GitAddonSource
- type InstallPackage
- type Installer
- type Item
- type ListBucketResult
- type ListOptions
- type Meta
- type OSSAddonSource
- type OSSItem
- type ObservabilityEnvBindingValues
- type ObservabilityEnvironment
- type Pattern
- type ReaderType
- type Registry
- func (r *Registry) BuildReader() (AsyncReader, error)
- func (r *Registry) GetInstallPackage(meta *SourceMeta, uiData *UIData) (*InstallPackage, error)
- func (r *Registry) GetUIData(meta *SourceMeta, opt ListOptions) (*UIData, error)
- func (r *Registry) ListAddonMeta() (map[string]SourceMeta, error)
- func (r *Registry) ListUIData(registryAddonMeta map[string]SourceMeta, opt ListOptions) ([]*UIData, error)
- type RegistryDataStore
- type Source
- type SourceMeta
- type Status
- type UIData
Constants ¶
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"
)
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"
)
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 */
)
const (
// EOFError is error returned by xml parse
EOFError string = "EOF"
// DirType means a directory
DirType = "dir"
// FileType means a file
FileType = "file"
)
Variables ¶
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{}
)
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")
)
var ErrorNoDomain = errors.New("domain is not set")
ErrorNoDomain is the error when no domain is found
var ParameterFileName = filepath.Join("resources", "parameter.cue")
ParameterFileName is the addon resources/parameter.cue file name
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 Convert2SecName ¶
func Convert2SecName(name string) string
Convert2SecName generate addon argument secret name
func DisableAddon ¶
func DisableAddon(ctx context.Context, cli client.Client, name string) error
DisableAddon will disable addon from cluster.
func EnableAddon ¶
func EnableAddon(ctx context.Context, name string, cli client.Client, 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, 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 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 RenderApp ¶
func RenderApp(ctx context.Context, addon *InstallPackage, config *rest.Config, 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 (*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 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 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
type InstallPackage ¶
type InstallPackage struct {
Meta
Definitions []ElementFile `json:"definitions"`
CUEDefinitions []ElementFile `json:"CUEDefinitions"`
Parameters string `json:"parameters"`
CUETemplates []ElementFile `json:"CUETemplates"`
YAMLTemplates []ElementFile `json:"YAMLTemplates,omitempty"`
DefSchemas []ElementFile `json:"def_schemas,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, 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 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"`
}
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
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 Registry ¶
type Registry struct {
Name string `json:"name"`
Git *GitAddonSource `json:"git,omitempty"`
OSS *OSSAddonSource `json:"oss,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 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"`
}
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 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"`
}
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