addon

package
v1.2.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: Apache-2.0 Imports: 36 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 dir 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"
)
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 (
	// GetLevelOptions used when get or list addons
	GetLevelOptions = ListOptions{GetDetail: true, GetDefinition: true, GetParameter: true}

	// EnableLevelOptions used when enable addon
	EnableLevelOptions = ListOptions{GetDetail: true, GetDefinition: true, GetResource: true, GetTemplate: true, GetParameter: true, GetDefSchema: 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")
)

Functions

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) error

DisableAddon will disable addon from cluster.

func EnableAddon

func EnableAddon(ctx context.Context, addon *types.Addon, cli client.Client, apply apply.Applicator, source Source, args map[string]interface{}) error

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

func GetAddonsFromReader

func GetAddonsFromReader(r AsyncReader, opt ListOptions) ([]*types.Addon, error)

GetAddonsFromReader list addons from AsyncReader

func GetSingleAddonFromReader

func GetSingleAddonFromReader(r AsyncReader, addonName string, opt ListOptions) (*types.Addon, error)

GetSingleAddonFromReader read single addon from Reader

func NewAddonError

func NewAddonError(msg string) error

NewAddonError will return an

func RenderAppAndResources

func RenderAppAndResources(addon *types.Addon, args map[string]interface{}) (*v1beta1.Application, []*unstructured.Unstructured, []*unstructured.Unstructured, error)

RenderAppAndResources render a K8s application

func RenderArgsSecret

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

RenderArgsSecret render addon enable argument to secret

func WrapErrRateLimit

func WrapErrRateLimit(err error) error

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

Types

type AsyncReader

type AsyncReader interface {
	// Read will return either file content or directory sub-paths
	// Read should accept relative path to github repo/path or OSS bucket
	Read(path string) (content string, subItem []Item, err error)
	// Addon returns a addon to be readed
	Addon() *types.Addon
	// SendErr to outside and quit
	SendErr(err error)
	// ErrCh will get the reader's channel to send error
	ErrCh() chan error
	// Mutex return an mutex for slice insert
	Mutex() *sync.Mutex
	// RelativePath return a relative path to GitHub repo/path or OSS bucket
	RelativePath(item Item) string
	// WithNewAddonAndMutex is mainly for copy the whole reader to read a new addon
	WithNewAddonAndMutex() AsyncReader
}

AsyncReader helps async read files of addon

func NewAsyncReader

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

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

type File

type File struct {
	Name string `xml:"Key"`
	Size int    `xml:"Size"`
}

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) GetAddon

func (git *GitAddonSource) GetAddon(name string, opt ListOptions) (*types.Addon, error)

GetAddon get an addon info from GitAddonSource, can be used for get or enable

func (*GitAddonSource) ListAddons

func (git *GitAddonSource) ListAddons(opt ListOptions) ([]*types.Addon, error)

ListAddons list addons' info from GitAddonSource

type Handler

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

Handler helps addon enable, dependency-check, dispatch resources

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 OSSAddonSource

type OSSAddonSource struct {
	EndPoint string `json:"end_point" validate:"required"`
	Bucket   string `json:"bucket"`
}

OSSAddonSource is Addon source from alicloud OSS

func (*OSSAddonSource) GetAddon

func (o *OSSAddonSource) GetAddon(name string, opt ListOptions) (*types.Addon, error)

GetAddon from OSSAddonSource

func (*OSSAddonSource) ListAddons

func (o *OSSAddonSource) ListAddons(opt ListOptions) ([]*types.Addon, error)

ListAddons from OSSAddonSource

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 ReaderType

type ReaderType string

ReaderType marks where to read addon files

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

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 {
	GetAddon(name string, opt ListOptions) (*types.Addon, error)
	ListAddons(opt ListOptions) ([]*types.Addon, error)
}

Source is where to get addons

Jump to

Keyboard shortcuts

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