plugins

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BaseRefPath is the target path for reference docs
	BaseRefPath = "docs/en/end-user"
	// ReferenceSourcePath is the location for source reference
	ReferenceSourcePath = "hack/references"
	// ComponentDefinitionTypePath is the URL path for component typed capability
	ComponentDefinitionTypePath = "components"
	// WorkloadTypePath is the URL path for workload typed capability
	WorkloadTypePath = "workload-types"
	// TraitPath is the URL path for trait typed capability
	TraitPath = "traits"
)
View Source
const (
	// TerraformWriteConnectionSecretToRefName is the name for Terraform WriteConnectionSecretToRef
	TerraformWriteConnectionSecretToRefName = "writeConnectionSecretToRef"
	// TerraformWriteConnectionSecretToRefType is the type for Terraform WriteConnectionSecretToRef
	TerraformWriteConnectionSecretToRefType = "[writeConnectionSecretToRef](#writeConnectionSecretToRef)"
)
View Source
const DescriptionUndefined = "description not defined"

DescriptionUndefined indicates the description is not defined

View Source
const TypeGithub = "github"

TypeGithub represents github

View Source
const TypeLocal = "local"

TypeLocal represents github

View Source
const TypeOss = "oss"

TypeOss represent oss

View Source
const TypeUnknown = "unknown"

TypeUnknown represents parse failed

Variables

View Source
var BaseOpenAPIV3Template = `` /* 198-byte string literal not displayed */

BaseOpenAPIV3Template is Standard OpenAPIV3 Template

View Source
var ConfigurationYamlSample = map[string]string{
	"annotations": `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: myapp
spec:
  components:
    - name: express-server
      type: webservice
      properties:
        image: crccheck/hello-world
        port: 8000
      traits:
        - type: labels
          properties:
            "release": "stable"
        - type: annotations
          properties:
            "description": "web application"
`,

	"ingress": `
kind: Application
metadata:
  name: first-vela-app
spec:
  components:
    - name: express-server
      type: webservice
      properties:
        image: crccheck/hello-world
        port: 8000
      traits:
        - type: ingress
          properties:
            domain: testsvc.example.com
            http:
              "/": 8000
`,

	"labels": `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: myapp
spec:
  components:
    - name: express-server
      type: webservice
      properties:
        image: crccheck/hello-world
        port: 8000
      traits:
        - type: labels
          properties:
            "release": "stable"
        - type: annotations
          properties:
            "description": "web application"
`,

	"metrics": `
...
    format: "prometheus"
    port: 8080
    path: "/metrics"
    scheme:  "http"
    enabled: true
`,

	"route": `
...
    domain: example.com
    issuer: tls
    rules:
      - path: /testapp
        rewriteTarget: /
`,

	"scaler": `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: website
spec:
  components:
    - name: frontend
      type: webservice
      properties:
        image: nginx
      traits:
        - type: scaler
          properties:
            replicas: 2
        - type: sidecar
          properties:
            name: "sidecar-test"
            image: "fluentd"
    - name: backend
      type: worker
      properties:
        image: busybox
        cmd:
          - sleep
          - '1000'
`,

	"sidecar": `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: vela-app-with-sidecar
spec:
  components:
    - name: log-gen-worker
      type: worker
      properties:
        image: busybox
        cmd:
          - /bin/sh
          - -c
          - >
            i=0;
            while true;
            do
              echo "$i: $(date)" >> /var/log/date.log;
              i=$((i+1));
              sleep 1;
            done
        volumes:
          - name: varlog
            mountPath: /var/log
            type: emptyDir
      traits:
        - type: sidecar
          properties:
            name: count-log
            image: busybox
            cmd: [ /bin/sh, -c, 'tail -n+1 -f /var/log/date.log']
            volumes:
              - name: varlog
                path: /var/log
`,

	"task": `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: app-worker
spec:
  components:
    - name: mytask
      type: task
      properties:
        image: perl
	    count: 10
	    cmd: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
`,

	"volumes": `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: app-worker
spec:
  components:
    - name: myworker
      type: worker
      properties:
        image: "busybox"
        cmd:
          - sleep
          - "1000"
      traits:
        - type: aws-ebs-volume
          properties:
            name: "my-ebs"
            mountPath: "/myebs"
            volumeID: "my-ebs-id"
`,

	"webservice": `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: website
spec:
  components:
    - name: frontend
      type: webservice
      properties:
        image: oamdev/testapp:v1
        cmd: ["node", "server.js"]
        port: 8080
        cpu: "0.1"
        env:
          - name: FOO
            value: bar
          - name: FOO
            valueFrom:
              secretKeyRef:
                name: bar
                key: bar
`,
	"worker": `
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: app-worker
spec:
  components:
    - name: myworker
      type: worker
      properties:
        image: "busybox"
        cmd:
          - sleep
          - "1000"
`,
}

ConfigurationYamlSample stores the configuration yaml sample for capabilities

Functions

func GetCapabilitiesFromCluster

func GetCapabilitiesFromCluster(ctx context.Context, namespace string, c common.Args, selector labels.Selector) ([]types.Capability, error)

GetCapabilitiesFromCluster will get capability from K8s cluster

func GetCapabilityByComponentDefinitionObject added in v1.0.5

func GetCapabilityByComponentDefinitionObject(componentDef v1beta1.ComponentDefinition, referenceName string) (*types.Capability, error)

GetCapabilityByComponentDefinitionObject gets capability by ComponentDefinition object

func GetCapabilityByName added in v1.0.5

func GetCapabilityByName(ctx context.Context, c common.Args, capabilityName string, ns string) (*types.Capability, error)

GetCapabilityByName gets capability by definition name

func GetCapabilityByTraitDefinitionObject added in v1.0.5

func GetCapabilityByTraitDefinitionObject(traitDef v1beta1.TraitDefinition) (*types.Capability, error)

GetCapabilityByTraitDefinitionObject gets capability by TraitDefinition object

func GetComponentsFromCluster

func GetComponentsFromCluster(ctx context.Context, namespace string, c common.Args, selector labels.Selector) ([]types.Capability, []error, error)

GetComponentsFromCluster will get capability from K8s cluster

func GetComponentsFromClusterWithValidateOption added in v1.0.5

func GetComponentsFromClusterWithValidateOption(ctx context.Context, namespace string, c common.Args, selector labels.Selector, validateFlag bool) ([]types.Capability, []error, error)

GetComponentsFromClusterWithValidateOption will get capability from K8s cluster with an option whether to valid Components

func GetDescription

func GetDescription(annotation map[string]string) string

GetDescription get description from annotation

func GetInstalledCapabilityWithCapName

func GetInstalledCapabilityWithCapName(capT types.CapType, capName string) (types.Capability, error)

GetInstalledCapabilityWithCapName will get cap by alias

func GetNamespacedCapabilitiesFromCluster added in v1.0.5

func GetNamespacedCapabilitiesFromCluster(ctx context.Context, namespace string, c common.Args, selector labels.Selector) ([]types.Capability, error)

GetNamespacedCapabilitiesFromCluster will get capability from K8s cluster in the specified namespace and default namespace If the definition could be found from `namespace`, try to find in namespace `types.DefaultKubeVelaNS`

func GetSubDir

func GetSubDir(dir string, capT types.CapType) string

GetSubDir will get dir for capability

func GetTraitsFromCluster

func GetTraitsFromCluster(ctx context.Context, namespace string, c common.Args, selector labels.Selector) ([]types.Capability, []error, error)

GetTraitsFromCluster will get capability from K8s cluster

func GetTraitsFromClusterWithValidateOption added in v1.0.5

func GetTraitsFromClusterWithValidateOption(ctx context.Context, namespace string, c common.Args, selector labels.Selector, validateFlag bool) ([]types.Capability, []error, error)

GetTraitsFromClusterWithValidateOption will get capability from K8s cluster with an option whether to valid Traits

func HandleDefinition

func HandleDefinition(name, crdName string, annotation, labels map[string]string, extension *runtime.RawExtension, tp types.CapType,
	applyTo []string, schematic *commontypes.Schematic) (types.Capability, error)

HandleDefinition will handle definition to capability

func HandleTemplate

func HandleTemplate(in *runtime.RawExtension, schematic *commontypes.Schematic, name string) (types.Capability, error)

HandleTemplate will handle definition template to capability

func LoadAllInstalledCapability

func LoadAllInstalledCapability(userNamespace string, c common.Args) ([]types.Capability, error)

LoadAllInstalledCapability will list all capability

func LoadCapabilityByName

func LoadCapabilityByName(name string, userNamespace string, c common.Args) (types.Capability, error)

LoadCapabilityByName will load capability from local by name

func LoadCapabilityFromSyncedCenter

func LoadCapabilityFromSyncedCenter(mapper discoverymapper.DiscoveryMapper, dir string) ([]types.Capability, error)

LoadCapabilityFromSyncedCenter will load capability from dir

func LoadInstalledCapabilityWithType

func LoadInstalledCapabilityWithType(userNamespace string, c common.Args, capT types.CapType) ([]types.Capability, error)

LoadInstalledCapabilityWithType will load cap list by type

func ParseCapability added in v1.1.0

func ParseCapability(mapper discoverymapper.DiscoveryMapper, data []byte) (types.Capability, error)

ParseCapability will convert config from remote center to capability

func RemoveLegacyTemps

func RemoveLegacyTemps(retainedTemps []types.Capability, dir string) int

RemoveLegacyTemps will remove capability definitions under `dir` but not included in `retainedTemps`.

func SinkTemp2Local

func SinkTemp2Local(templates []types.Capability, dir string) int

SinkTemp2Local will sink template to local file

func StoreRepos

func StoreRepos(repos []CapCenterConfig) error

StoreRepos will store cap center repo locally

func WalkParameterSchema added in v1.0.4

func WalkParameterSchema(parameters *openapi3.Schema, name string, depth int)

WalkParameterSchema will extract properties from *openapi3.Schema

Types

type BoolType

type BoolType = bool

BoolType is bool type

type CapCenterConfig

type CapCenterConfig struct {
	Name    string `json:"name"`
	Address string `json:"address"`
	Token   string `json:"token"`
}

CapCenterConfig is used to store cap center config in file

func LoadRepos

func LoadRepos() ([]CapCenterConfig, error)

LoadRepos will load all cap center repos

type CenterClient

type CenterClient interface {
	SyncCapabilityFromCenter() error
}

CenterClient defines an interface for cap center client

func NewCenterClient

func NewCenterClient(ctx context.Context, name, address, token string) (CenterClient, error)

NewCenterClient create a client from type

type CommonReference added in v1.1.0

type CommonReference struct {
	Name       string
	Parameters []ReferenceParameter
	Depth      int
}

CommonReference contains parameters info of HelmCategory and KubuCategory type capability at present

type CommonSchema added in v1.1.0

type CommonSchema struct {
	Name    string
	Schemas *openapi3.Schema
}

CommonSchema is a struct contains *openapi3.Schema style parameter

type ConsoleReference

type ConsoleReference struct {
	ParseReference
	TableName   string             `json:"tableName"`
	TableObject *tablewriter.Table `json:"tableObject"`
}

ConsoleReference is the struct for capability information in console

func (*ConsoleReference) GenerateCUETemplateProperties added in v1.0.4

func (ref *ConsoleReference) GenerateCUETemplateProperties(capability *types.Capability) ([]ConsoleReference, error)

GenerateCUETemplateProperties get all properties of a capability

func (*ConsoleReference) GenerateTerraformCapabilityProperties added in v1.0.4

func (ref *ConsoleReference) GenerateTerraformCapabilityProperties(capability types.Capability) ([]ConsoleReference, error)

GenerateTerraformCapabilityProperties generates Capability properties for Terraform ComponentDefinition in Cli console

type Content added in v1.1.0

type Content struct {
	OssContent
	GithubContent
	LocalContent
}

Content contains different type of content needed when building Registry

func Parse

func Parse(addr string) (string, *Content, error)

Parse will parse config from address

type GithubContent

type GithubContent struct {
	Owner string `json:"owner"`
	Repo  string `json:"repo"`
	Path  string `json:"path"`
	Ref   string `json:"ref"`
}

GithubContent for cap center

type GithubRegistry added in v1.1.0

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

GithubRegistry is Registry's implementation treat github url as resource

func NewGithubCenter

func NewGithubCenter(ctx context.Context, token, centerName string, r *GithubContent) (*GithubRegistry, error)

NewGithubCenter will create client by github center implementation

func (GithubRegistry) GetCap added in v1.1.0

func (g GithubRegistry) GetCap(addonName string) (types.Capability, []byte, error)

GetCap return capability object and raw data specified by cap name

func (GithubRegistry) ListCaps added in v1.1.0

func (g GithubRegistry) ListCaps() ([]types.Capability, error)

ListCaps list all capabilities of registry

func (*GithubRegistry) SyncCapabilityFromCenter added in v1.1.0

func (g *GithubRegistry) SyncCapabilityFromCenter() error

SyncCapabilityFromCenter will sync capability from github registry TODO(wonderflow): currently we only sync by create, we also need to delete which not exist remotely.

type Int64Type

type Int64Type = int64

Int64Type is int64 type

type ListBucketResult added in v1.1.0

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

ListBucketResult describe a file list from OSS

type LocalContent added in v1.1.0

type LocalContent struct {
	AbsDir string `json:"abs_dir"`
}

LocalContent for local registry

type LocalRegistry added in v1.1.0

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

LocalRegistry is Registry's implementation treat local url as resource

func (LocalRegistry) GetCap added in v1.1.0

func (l LocalRegistry) GetCap(addonName string) (types.Capability, []byte, error)

GetCap return capability object and raw data specified by cap name

func (LocalRegistry) ListCaps added in v1.1.0

func (l LocalRegistry) ListCaps() ([]types.Capability, error)

ListCaps list all capabilities of registry

type MarkdownReference

type MarkdownReference struct {
	ParseReference
}

MarkdownReference is the struct for capability information in

func (*MarkdownReference) CreateMarkdown

func (ref *MarkdownReference) CreateMarkdown(ctx context.Context, caps []types.Capability, baseRefPath, referenceSourcePath string) error

CreateMarkdown creates markdown based on capabilities

func (*MarkdownReference) GenerateReferenceDocs

func (ref *MarkdownReference) GenerateReferenceDocs(ctx context.Context, baseRefPath string) error

GenerateReferenceDocs generates reference docs

func (*MarkdownReference) GenerateTerraformCapabilityProperties added in v1.0.5

func (ref *MarkdownReference) GenerateTerraformCapabilityProperties(capability types.Capability) (string, error)

GenerateTerraformCapabilityProperties generates Capability properties for Terraform ComponentDefinition in a local website

type OssContent added in v1.1.0

type OssContent struct {
	BucketURL string `json:"bucket_url"`
}

OssContent for oss registry

type OssRegistry added in v1.1.0

type OssRegistry struct {
	*http.Client
	// contains filtered or unexported fields
}

OssRegistry is Registry's implementation treat OSS url as resource

func NewOssCenter added in v1.1.0

func NewOssCenter(bucketURL string, centerName string) *OssRegistry

NewOssCenter will create OSS center implementation

func (OssRegistry) GetCap added in v1.1.0

func (o OssRegistry) GetCap(addonName string) (types.Capability, []byte, error)

GetCap return capability object and raw data specified by cap name

func (OssRegistry) ListCaps added in v1.1.0

func (o OssRegistry) ListCaps() ([]types.Capability, error)

ListCaps list all capabilities of registry

func (*OssRegistry) SyncCapabilityFromCenter added in v1.1.0

func (o *OssRegistry) SyncCapabilityFromCenter() error

SyncCapabilityFromCenter will sync capability from oss registry

type ParseReference

type ParseReference struct {
	Client client.Client
}

ParseReference is used to include the common function `parseParameter`

func (*ParseReference) GenerateHelmAndKubeProperties added in v1.1.0

func (ref *ParseReference) GenerateHelmAndKubeProperties(ctx context.Context, capability *types.Capability) ([]CommonReference, []ConsoleReference, error)

GenerateHelmAndKubeProperties get all properties of a Helm/Kube Category type capability

type Reference

type Reference interface {
	// contains filtered or unexported methods
}

Reference is the struct for capability information

type ReferenceParameter

type ReferenceParameter struct {
	types.Parameter `json:",inline,omitempty"`
	// PrintableType is same to `parameter.Type` which could be printable
	PrintableType string `json:"printableType"`
}

ReferenceParameter is the parameter section of CUE template

type ReferenceParameterTable added in v1.0.5

type ReferenceParameterTable struct {
	Name       string
	Parameters []ReferenceParameter
	Depth      *int
}

ReferenceParameterTable stores the information of a bunch of ReferenceParameter in a table style

type Registry added in v1.1.0

type Registry interface {
	GetCap(addonName string) (types.Capability, []byte, error)
	ListCaps() ([]types.Capability, error)
}

Registry define a registry stores trait & component defs

func NewRegistry added in v1.1.0

func NewRegistry(ctx context.Context, token, registryName string, regURL string) (Registry, error)

NewRegistry will create a registry implementation

type RegistryFile added in v1.1.0

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

RegistryFile describes a file item in registry

type StringType

type StringType = string

StringType is string type

Jump to

Keyboard shortcuts

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