modules

package
v0.12.1-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 20 Imported by: 7

Documentation

Index

Constants

View Source
const (
	DefaultModulePathEnv     = "KUSION_MODULE_PATH"
	KusionModuleBinaryPrefix = "kusion-module-"
	Dir                      = "modules"
)
View Source
const PluginKey = "module-default"

Variables

View Source
var HandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "MODULE_PLUGIN",
	MagicCookieValue: "ON",
}

HandshakeConfig is a common handshake that is shared by plugin and host.

View Source
var IgnoreModules = map[string]bool{
	"service": true,
	"job":     true,
}

IgnoreModules todo@dayuan delete this condition after workload is changed into a module

View Source
var PluginMap = map[string]plugin.Plugin{
	PluginKey: &GRPCPlugin{},
}

PluginMap is the map of plugins we can dispense.

Functions

func AppendToSpec added in v0.11.1

func AppendToSpec(resourceType v1.Type, resourceID string, i *v1.Spec, resource any) error

AppendToSpec adds a Kubernetes resource to the Spec resources slice.

func CallGenerators

func CallGenerators(i *v1.Spec, newGenerators ...NewGeneratorFunc) error

CallGenerators calls the Generate method of each Generator instance returned by the given NewGeneratorFuncs.

func ForeachOrdered

func ForeachOrdered[T any](m map[string]T, f func(key string, value T) error) error

ForeachOrdered executes the given function on each item in the map in order of their keys.

func GenericPtr

func GenericPtr[T any](i T) *T

GenericPtr returns a pointer to the provided value.

func KubernetesResourceID

func KubernetesResourceID(typeMeta metav1.TypeMeta, objectMeta metav1.ObjectMeta) string

KubernetesResourceID returns the unique ID of a Kubernetes resource based on its type and metadata.

func KusionPathDependency

func KusionPathDependency(id, name string) string

KusionPathDependency returns the implicit resource dependency path based on the resource id and name with the "$kusion_path" prefix.

func MergeMaps

func MergeMaps(maps ...map[string]string) map[string]string

MergeMaps merges multiple map[string]string into one map[string]string. If a map is nil, it skips it and moves on to the next one. For each non-nil map, it iterates over its key-value pairs and adds them to the merged map. Finally, it returns the merged map.

func NewPluginClient added in v0.11.1

func NewPluginClient(modulePluginPath, moduleName string) (*plugin.Client, error)

func PatchResource

func PatchResource[T any](resources map[string][]*v1.Resource, gvk string, patchFunc func(*T) error) error

PatchResource patches the resource with the given patch.

func PluginDir added in v0.11.0

func PluginDir() (string, error)

func UniqueAppLabels

func UniqueAppLabels(projectName, appName string) map[string]string

UniqueAppLabels returns a map of labels that identify an app based on its project and name.

func UniqueAppName

func UniqueAppName(projectName, stackName, appName string) string

UniqueAppName returns a unique name for a workload based on its project and app name.

Types

type GRPCClient added in v0.11.0

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

func (*GRPCClient) Generate added in v0.11.0

type GRPCPlugin added in v0.11.0

type GRPCPlugin struct {
	// GRPCPlugin must still implement the Plugin interface
	plugin.Plugin
	// Concrete implementation, written in Go. This is only used for plugins that are written in Go.
	Impl Module
}

func (*GRPCPlugin) GRPCClient added in v0.11.0

func (p *GRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient is going to be invoked by the go-plugin framework

func (*GRPCPlugin) GRPCServer added in v0.11.0

func (p *GRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

GRPCServer is going to be invoked by the go-plugin framework

type GRPCServer added in v0.11.0

type GRPCServer struct {
	// This is the real implementation
	Impl Module
	proto.UnimplementedModuleServer
}

func (*GRPCServer) Generate added in v0.11.0

func (s *GRPCServer) Generate(ctx context.Context, req *proto.GeneratorRequest) (res *proto.GeneratorResponse, err error)

type Generator

type Generator interface {
	// Generate performs the intent generate operation.
	Generate(intent *v1.Spec) error
}

Generator is an interface for things that can generate Intent from input configurations. todo it's for built-in generators and we should consider to convert it to a general Module interface

func CallGeneratorFuncs

func CallGeneratorFuncs(newGenerators ...NewGeneratorFunc) ([]Generator, error)

CallGeneratorFuncs calls each NewGeneratorFunc in the given slice and returns a slice of Generator instances.

type Module added in v0.11.0

type Module interface {
	Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error)
}

Module is the interface that we're exposing as a kusion module plugin.

type NewGeneratorFunc

type NewGeneratorFunc func() (Generator, error)

NewGeneratorFunc is a function that returns a Generator.

type Plugin added in v0.11.0

type Plugin struct {

	// Module represents the real module impl
	Module Module
	// contains filtered or unexported fields
}

func NewPlugin added in v0.11.0

func NewPlugin(key string) (*Plugin, error)

func (*Plugin) KillPluginClient added in v0.11.0

func (p *Plugin) KillPluginClient() error

Directories

Path Synopsis
Package generators contains all codes about the Spec generator mechanism.
Package generators contains all codes about the Spec generator mechanism.

Jump to

Keyboard shortcuts

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