v1

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PluginConfigKey = "operatorBuilder"

Variables

View Source
var (
	ErrNamesMustBeUnique   = errors.New("each workload name must be unique")
	ErrConfigMustExist     = errors.New("no workload config provided - workload config required")
	ErrInvalidKind         = errors.New("unrecognized workload kind in workload config")
	ErrMultipleConfigs     = errors.New("multiple configs found - please provide only one standalone or collection workload")
	ErrCollectionRequired  = errors.New("a WorkloadCollection is required when using WorkloadComponents")
	ErrMissingWorkload     = errors.New("could not find either standalone or collection workload, please provide one")
	ErrMissingDependencies = errors.New("missing dependencies - no workload config provided")
)

Functions

func CloseFile

func CloseFile(file io.ReadCloser)

CloseFile safely closes a file handle.

func InitializeMarkerInspector

func InitializeMarkerInspector() (*inspect.Inspector, error)

func ReadStream

func ReadStream(fileName string) (io.ReadCloser, error)

func SupportedMarkerDataTypes

func SupportedMarkerDataTypes() []string

SupportedMarkerDataTypes returns the supported data types that can be used in workload markers.

func TransformYAML

func TransformYAML(results ...*inspect.YAMLResult) error

Types

type APISpec

type APISpec struct {
	Domain        string `json:"domain" yaml:"domain"`
	Group         string `json:"group" yaml:"group"`
	Version       string `json:"version" yaml:"version"`
	Kind          string `json:"kind" yaml:"kind"`
	ClusterScoped bool   `json:"clusterScoped" yaml:"clusterScoped"`
}

APISpec contains fields shared by all workload specs.

type APISpecField

type APISpecField struct {
	FieldName          string
	ManifestFieldName  string
	DataType           string
	DefaultVal         string
	ZeroVal            string
	APISpecContent     string
	SampleField        string
	DocumentationLines []string
}

APISpecField represents a single field in a custom API type.

type ChildResource

type ChildResource struct {
	Name          string
	UniqueName    string
	Group         string
	Version       string
	Kind          string
	StaticContent string
	SourceCode    string
}

ChildResource contains attributes for resources created by the custom resource. These definitions are inferred from the resource manifests.

type CliCommand

type CliCommand struct {
	Name        string `json:"name" yaml:"name" validate:"required_with=Description"`
	Description string `json:"description" yaml:"description" validate:"required_with=Name"`
	VarName     string
	FileName    string
}

CliCommand defines the command name and description for the root command or subcommand of a companion CLI.

type CollectionFieldMarker

type CollectionFieldMarker FieldMarker

type ComponentWorkload

type ComponentWorkload struct {
	WorkloadShared `yaml:",inline"`
	Spec           ComponentWorkloadSpec `json:"spec" yaml:"spec" validate:"required"`
}

ComponentWorkload defines a workload that is a component of a collection.

func (*ComponentWorkload) GetAPIGroup

func (c *ComponentWorkload) GetAPIGroup() string

func (*ComponentWorkload) GetAPIKind

func (c *ComponentWorkload) GetAPIKind() string

func (*ComponentWorkload) GetAPISpecFields

func (c *ComponentWorkload) GetAPISpecFields() []*APISpecField

func (*ComponentWorkload) GetAPIVersion

func (c *ComponentWorkload) GetAPIVersion() string

func (*ComponentWorkload) GetComponentResource

func (c *ComponentWorkload) GetComponentResource(domain, repo string, clusterScoped bool) *resource.Resource

func (*ComponentWorkload) GetComponents

func (*ComponentWorkload) GetComponents() []*ComponentWorkload

func (*ComponentWorkload) GetDependencies

func (c *ComponentWorkload) GetDependencies() []*ComponentWorkload

func (*ComponentWorkload) GetFuncNames

func (c *ComponentWorkload) GetFuncNames() (createFuncNames, initFuncNames []string)

func (*ComponentWorkload) GetName

func (c *ComponentWorkload) GetName() string

methods that implement WorkloadAPIBuilder.

func (*ComponentWorkload) GetOwnershipRules

func (c *ComponentWorkload) GetOwnershipRules() *[]OwnershipRule

func (*ComponentWorkload) GetPackageName

func (c *ComponentWorkload) GetPackageName() string

func (*ComponentWorkload) GetRBACRules

func (c *ComponentWorkload) GetRBACRules() *[]RBACRule

func (*ComponentWorkload) GetRootcommandName

func (*ComponentWorkload) GetRootcommandName() string

func (*ComponentWorkload) GetSourceFiles

func (c *ComponentWorkload) GetSourceFiles() *[]SourceFile

func (*ComponentWorkload) GetSubcommandDescr

func (c *ComponentWorkload) GetSubcommandDescr() string

func (*ComponentWorkload) GetSubcommandFileName

func (c *ComponentWorkload) GetSubcommandFileName() string

func (*ComponentWorkload) GetSubcommandName

func (c *ComponentWorkload) GetSubcommandName() string

func (*ComponentWorkload) GetSubcommandVarName

func (c *ComponentWorkload) GetSubcommandVarName() string

func (*ComponentWorkload) GetWorkloadKind

func (c *ComponentWorkload) GetWorkloadKind() WorkloadKind

func (*ComponentWorkload) HasChildResources

func (c *ComponentWorkload) HasChildResources() bool

func (*ComponentWorkload) HasSubCmdName

func (c *ComponentWorkload) HasSubCmdName() bool

func (*ComponentWorkload) IsClusterScoped

func (c *ComponentWorkload) IsClusterScoped() bool

func (*ComponentWorkload) IsCollection

func (*ComponentWorkload) IsCollection() bool

func (*ComponentWorkload) IsComponent

func (*ComponentWorkload) IsComponent() bool

func (*ComponentWorkload) IsStandalone

func (*ComponentWorkload) IsStandalone() bool

func (*ComponentWorkload) SetComponents

func (*ComponentWorkload) SetComponents(components []*ComponentWorkload) error

func (*ComponentWorkload) SetNames

func (c *ComponentWorkload) SetNames()

func (*ComponentWorkload) SetResources

func (c *ComponentWorkload) SetResources(workloadPath string) error

func (*ComponentWorkload) Validate

func (c *ComponentWorkload) Validate() error

type ComponentWorkloadSpec

type ComponentWorkloadSpec struct {
	API                   APISpec    `json:"api" yaml:"api"`
	CompanionCliSubcmd    CliCommand `json:"companionCliSubcmd" yaml:"companionCliSubcmd" validate:"omitempty"`
	Resources             []string   `json:"resources" yaml:"resources"`
	Dependencies          []string   `json:"dependencies" yaml:"dependencies"`
	ConfigPath            string
	ComponentDependencies []*ComponentWorkload
	APISpecFields         []*APISpecField
	SourceFiles           []SourceFile
	RBACRules             []RBACRule
	OwnershipRules        []OwnershipRule
}

ComponentWorkloadSpec defines the attributes for a workload that is a component of a collection.

type FieldMarker

type FieldMarker struct {
	Name        string
	Type        FieldType
	Description *string
	Default     interface{} `marker:",optional"`
	// contains filtered or unexported fields
}

func (FieldMarker) String

func (fm FieldMarker) String() string

type FieldType

type FieldType int
const (
	FieldUnknownType FieldType = iota
	FieldString
	FieldInt
	FieldBool
)

func (FieldType) String

func (f FieldType) String() string

func (*FieldType) UnmarshalMarkerArg

func (f *FieldType) UnmarshalMarkerArg(in string) error

type OwnershipRule

type OwnershipRule struct {
	Version string
	Kind    string
	CoreAPI bool
}

OwnershipRule contains the info needed to create the controller ownership functionality when setting up the controller with the manager. This allows the controller to reconcile the state of a deleted resource that it manages.

type PluginConfig

type PluginConfig struct {
	WorkloadConfigPath string `json:"workloadConfigPath" yaml:"workloadConfigPath"`
	CliRootCommandName string `json:"cliRootCommandName" yaml:"cliRootCommandName"`
}

PluginConfig contains the project config values which are stored in the PROJECT file under plugins.operatorBuilder

type RBACRule

type RBACRule struct {
	Group      string
	Resource   string
	Verbs      []string
	VerbString string
}

RBACRule contains the info needed to create the kubebuilder:rbac markers in the controller.

func (*RBACRule) AddVerb

func (rule *RBACRule) AddVerb(verb string)

type SourceCodeTemplateData

type SourceCodeTemplateData struct {
	SpecField     []*APISpecField
	SourceFile    *[]SourceFile
	RBACRule      *[]RBACRule
	OwnershipRule *[]OwnershipRule
}

SourceCodeTemplateData is a collection of variables used to generate source code.

type SourceFile

type SourceFile struct {
	Filename  string
	Children  []ChildResource
	HasStatic bool
}

SourceFile represents a golang source code file that contains one or more child resource objects.

type StandaloneWorkload

type StandaloneWorkload struct {
	WorkloadShared `yaml:",inline"`
	Spec           StandaloneWorkloadSpec `json:"spec" yaml:"spec" validate:"required"`
}

StandaloneWorkload defines a standalone workload.

func (*StandaloneWorkload) GetAPIGroup

func (s *StandaloneWorkload) GetAPIGroup() string

func (*StandaloneWorkload) GetAPIKind

func (s *StandaloneWorkload) GetAPIKind() string

func (*StandaloneWorkload) GetAPISpecFields

func (s *StandaloneWorkload) GetAPISpecFields() []*APISpecField

func (*StandaloneWorkload) GetAPIVersion

func (s *StandaloneWorkload) GetAPIVersion() string

func (*StandaloneWorkload) GetComponentResource

func (*StandaloneWorkload) GetComponentResource(domain, repo string, clusterScoped bool) *resource.Resource

func (*StandaloneWorkload) GetComponents

func (s *StandaloneWorkload) GetComponents() []*ComponentWorkload

func (*StandaloneWorkload) GetDependencies

func (*StandaloneWorkload) GetDependencies() []*ComponentWorkload

func (*StandaloneWorkload) GetDomain

func (s *StandaloneWorkload) GetDomain() string

methods that implement WorkloadInitializer.

func (*StandaloneWorkload) GetFuncNames

func (s *StandaloneWorkload) GetFuncNames() (createFuncNames, initFuncNames []string)

func (*StandaloneWorkload) GetName

func (s *StandaloneWorkload) GetName() string

methods that implement WorkloadAPIBuilder.

func (*StandaloneWorkload) GetOwnershipRules

func (s *StandaloneWorkload) GetOwnershipRules() *[]OwnershipRule

func (*StandaloneWorkload) GetPackageName

func (s *StandaloneWorkload) GetPackageName() string

func (*StandaloneWorkload) GetRBACRules

func (s *StandaloneWorkload) GetRBACRules() *[]RBACRule

func (*StandaloneWorkload) GetRootCmdDescr

func (s *StandaloneWorkload) GetRootCmdDescr() string

func (*StandaloneWorkload) GetRootCmdName

func (s *StandaloneWorkload) GetRootCmdName() string

func (*StandaloneWorkload) GetRootcommandName

func (s *StandaloneWorkload) GetRootcommandName() string

func (*StandaloneWorkload) GetSourceFiles

func (s *StandaloneWorkload) GetSourceFiles() *[]SourceFile

func (*StandaloneWorkload) GetSubcommandDescr

func (*StandaloneWorkload) GetSubcommandDescr() string

func (*StandaloneWorkload) GetSubcommandFileName

func (*StandaloneWorkload) GetSubcommandFileName() string

func (*StandaloneWorkload) GetSubcommandName

func (*StandaloneWorkload) GetSubcommandName() string

func (*StandaloneWorkload) GetSubcommandVarName

func (*StandaloneWorkload) GetSubcommandVarName() string

func (*StandaloneWorkload) GetWorkloadKind

func (s *StandaloneWorkload) GetWorkloadKind() WorkloadKind

func (*StandaloneWorkload) HasChildResources

func (s *StandaloneWorkload) HasChildResources() bool

func (*StandaloneWorkload) HasRootCmdName

func (s *StandaloneWorkload) HasRootCmdName() bool

func (*StandaloneWorkload) HasSubCmdName

func (*StandaloneWorkload) HasSubCmdName() bool

func (*StandaloneWorkload) IsClusterScoped

func (s *StandaloneWorkload) IsClusterScoped() bool

func (*StandaloneWorkload) IsCollection

func (*StandaloneWorkload) IsCollection() bool

func (*StandaloneWorkload) IsComponent

func (*StandaloneWorkload) IsComponent() bool

func (*StandaloneWorkload) IsStandalone

func (*StandaloneWorkload) IsStandalone() bool

func (*StandaloneWorkload) SetComponents

func (*StandaloneWorkload) SetComponents(components []*ComponentWorkload) error

func (*StandaloneWorkload) SetNames

func (s *StandaloneWorkload) SetNames()

func (*StandaloneWorkload) SetResources

func (s *StandaloneWorkload) SetResources(workloadPath string) error

func (*StandaloneWorkload) Validate

func (s *StandaloneWorkload) Validate() error

type StandaloneWorkloadSpec

type StandaloneWorkloadSpec struct {
	API                 APISpec    `json:"api" yaml:"api"`
	CompanionCliRootcmd CliCommand `json:"companionCliRootcmd" yaml:"companionCliRootcmd" validate:"omitempty"`
	Resources           []string   `json:"resources" yaml:"resources"`
	APISpecFields       []*APISpecField
	SourceFiles         []SourceFile
	RBACRules           []RBACRule
	OwnershipRules      []OwnershipRule
}

StandaloneWorkloadSpec defines the attributes for a standalone workload.

type WorkloadAPIBuilder

type WorkloadAPIBuilder interface {
	Validate() error

	IsClusterScoped() bool
	IsStandalone() bool
	IsComponent() bool
	IsCollection() bool

	HasSubCmdName() bool
	HasChildResources() bool

	GetName() string
	GetPackageName() string
	GetDomain() string
	GetAPIGroup() string
	GetAPIVersion() string
	GetAPIKind() string
	GetSubcommandName() string
	GetSubcommandDescr() string
	GetSubcommandVarName() string
	GetSubcommandFileName() string
	GetRootcommandName() string
	GetDependencies() []*ComponentWorkload
	GetComponents() []*ComponentWorkload
	GetSourceFiles() *[]SourceFile
	GetAPISpecFields() []*APISpecField
	GetRBACRules() *[]RBACRule
	GetOwnershipRules() *[]OwnershipRule
	GetComponentResource(domain, repo string, clusterScoped bool) *resource.Resource
	GetFuncNames() (createFuncNames, initFuncNames []string)

	SetNames()
	SetResources(workloadPath string) error
	SetComponents(components []*ComponentWorkload) error
}

WorkloadAPIBuilder defines the interface that must be implemented by a workload being used to configure API and controller creation.

func ProcessAPIConfig

func ProcessAPIConfig(workloadConfig string) (WorkloadAPIBuilder, error)

type WorkloadCollection

type WorkloadCollection struct {
	WorkloadShared `yaml:",inline"`
	Spec           WorkloadCollectionSpec `json:"spec" yaml:"spec" validate:"required"`
}

WorkloadCollection defines a workload collection.

func (*WorkloadCollection) GetAPIGroup

func (c *WorkloadCollection) GetAPIGroup() string

func (*WorkloadCollection) GetAPIKind

func (c *WorkloadCollection) GetAPIKind() string

func (*WorkloadCollection) GetAPISpecFields

func (c *WorkloadCollection) GetAPISpecFields() []*APISpecField

func (*WorkloadCollection) GetAPIVersion

func (c *WorkloadCollection) GetAPIVersion() string

func (*WorkloadCollection) GetComponentResource

func (*WorkloadCollection) GetComponentResource(domain, repo string, clusterScoped bool) *resource.Resource

func (*WorkloadCollection) GetComponents

func (c *WorkloadCollection) GetComponents() []*ComponentWorkload

func (*WorkloadCollection) GetDependencies

func (c *WorkloadCollection) GetDependencies() []*ComponentWorkload

func (*WorkloadCollection) GetDomain

func (c *WorkloadCollection) GetDomain() string

methods that implement WorkloadInitializer.

func (*WorkloadCollection) GetFuncNames

func (c *WorkloadCollection) GetFuncNames() (createFuncNames, initFuncNames []string)

func (*WorkloadCollection) GetName

func (c *WorkloadCollection) GetName() string

methods that implement WorkloadAPIBuilder.

func (*WorkloadCollection) GetOwnershipRules

func (*WorkloadCollection) GetOwnershipRules() *[]OwnershipRule

func (*WorkloadCollection) GetPackageName

func (c *WorkloadCollection) GetPackageName() string

func (*WorkloadCollection) GetRBACRules

func (*WorkloadCollection) GetRBACRules() *[]RBACRule

func (*WorkloadCollection) GetRootCmdDescr

func (c *WorkloadCollection) GetRootCmdDescr() string

func (*WorkloadCollection) GetRootCmdName

func (c *WorkloadCollection) GetRootCmdName() string

func (*WorkloadCollection) GetRootcommandName

func (c *WorkloadCollection) GetRootcommandName() string

func (*WorkloadCollection) GetSourceFiles

func (c *WorkloadCollection) GetSourceFiles() *[]SourceFile

func (*WorkloadCollection) GetSubcommandDescr

func (*WorkloadCollection) GetSubcommandDescr() string

func (*WorkloadCollection) GetSubcommandFileName

func (*WorkloadCollection) GetSubcommandFileName() string

func (*WorkloadCollection) GetSubcommandName

func (*WorkloadCollection) GetSubcommandName() string

func (*WorkloadCollection) GetSubcommandVarName

func (*WorkloadCollection) GetSubcommandVarName() string

func (*WorkloadCollection) GetWorkloadKind

func (c *WorkloadCollection) GetWorkloadKind() WorkloadKind

func (*WorkloadCollection) HasChildResources

func (*WorkloadCollection) HasChildResources() bool

func (*WorkloadCollection) HasRootCmdName

func (c *WorkloadCollection) HasRootCmdName() bool

func (*WorkloadCollection) HasSubCmdName

func (*WorkloadCollection) HasSubCmdName() bool

func (*WorkloadCollection) IsClusterScoped

func (c *WorkloadCollection) IsClusterScoped() bool

func (*WorkloadCollection) IsCollection

func (c *WorkloadCollection) IsCollection() bool

func (*WorkloadCollection) IsComponent

func (c *WorkloadCollection) IsComponent() bool

func (*WorkloadCollection) IsStandalone

func (c *WorkloadCollection) IsStandalone() bool

func (*WorkloadCollection) SetComponents

func (c *WorkloadCollection) SetComponents(components []*ComponentWorkload) error

func (*WorkloadCollection) SetNames

func (c *WorkloadCollection) SetNames()

func (*WorkloadCollection) SetResources

func (c *WorkloadCollection) SetResources(workloadPath string) error

func (*WorkloadCollection) Validate

func (c *WorkloadCollection) Validate() error

type WorkloadCollectionSpec

type WorkloadCollectionSpec struct {
	API                 APISpec    `json:"api" yaml:"api"`
	CompanionCliRootcmd CliCommand `json:"companionCliRootcmd" yaml:"companionCliRootcmd" validate:"omitempty"`
	ComponentFiles      []string   `json:"componentFiles" yaml:"componentFiles"`
	Components          []*ComponentWorkload
	APISpecFields       []*APISpecField
}

WorkloadCollectionSpec defines the attributes for a workload collection.

type WorkloadIdentifier

type WorkloadIdentifier interface {
	GetName() string
	GetWorkloadKind() WorkloadKind
}

WorkloadIdentifier defines an interface for identifying any workload.

type WorkloadInitializer

type WorkloadInitializer interface {
	Validate() error

	HasRootCmdName() bool

	GetDomain() string
	GetRootCmdName() string
	GetRootCmdDescr() string

	SetNames()
}

WorkloadInitializer defines the interface that must be implemented by a workload being used to configure project initialization.

func ProcessInitConfig

func ProcessInitConfig(workloadConfig string) (WorkloadInitializer, error)

type WorkloadKind

type WorkloadKind string

WorkloadKind indicates which of the supported workload kinds are being used.

const (
	WorkloadKindStandalone WorkloadKind = "StandaloneWorkload"
	WorkloadKindCollection WorkloadKind = "WorkloadCollection"
	WorkloadKindComponent  WorkloadKind = "ComponentWorkload"
)

type WorkloadShared

type WorkloadShared struct {
	Name        string       `json:"name"  yaml:"name" validate:"required"`
	Kind        WorkloadKind `json:"kind"  yaml:"kind" validate:"required"`
	PackageName string
}

WorkloadShared contains fields shared by all workloads.

Jump to

Keyboard shortcuts

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