Documentation ¶
Index ¶
- Constants
- Variables
- func AppendToSpec(resourceType v1.Type, resourceID string, i *v1.Spec, resource any) error
- func CallGenerators(i *v1.Spec, newGenerators ...NewGeneratorFunc) error
- func ForeachOrdered[T any](m map[string]T, f func(key string, value T) error) error
- func GenericPtr[T any](i T) *T
- func KubernetesResourceID(typeMeta metav1.TypeMeta, objectMeta metav1.ObjectMeta) string
- func KusionPathDependency(id, name string) string
- func MergeMaps(maps ...map[string]string) map[string]string
- func NewPluginClient(modulePluginPath, moduleName string) (*plugin.Client, error)
- func PatchResource[T any](resources map[string][]*v1.Resource, gvk string, patchFunc func(*T) error) error
- func PluginDir() (string, error)
- func UniqueAppLabels(projectName, appName string) map[string]string
- func UniqueAppName(projectName, stackName, appName string) string
- type GRPCClient
- type GRPCPlugin
- type GRPCServer
- type Generator
- type Module
- type NewGeneratorFunc
- type Plugin
Constants ¶
const ( DefaultModulePathEnv = "KUSION_MODULE_PATH" KusionModuleBinaryPrefix = "kusion-module-" Dir = "modules" )
const PluginKey = "module-default"
Variables ¶
var HandshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "MODULE_PLUGIN",
MagicCookieValue: "ON",
}
HandshakeConfig is a common handshake that is shared by plugin and host.
var IgnoreModules = map[string]bool{ "service": true, "job": true, }
IgnoreModules todo@dayuan delete this condition after workload is changed into a module
var PluginMap = map[string]plugin.Plugin{ PluginKey: &GRPCPlugin{}, }
PluginMap is the map of plugins we can dispense.
Functions ¶
func AppendToSpec ¶
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 ¶
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 ¶
KusionPathDependency returns the implicit resource dependency path based on the resource id and name with the "$kusion_path" prefix.
func MergeMaps ¶
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 ¶
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 UniqueAppLabels ¶
UniqueAppLabels returns a map of labels that identify an app based on its project and name.
func UniqueAppName ¶
UniqueAppName returns a unique name for a workload based on its project and app name.
Types ¶
type GRPCClient ¶
type GRPCClient struct {
// contains filtered or unexported fields
}
func (*GRPCClient) Generate ¶
func (c *GRPCClient) Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error)
type GRPCPlugin ¶
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 ¶
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 ¶
func (p *GRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error
GRPCServer is going to be invoked by the go-plugin framework
type GRPCServer ¶
type GRPCServer struct { // This is the real implementation Impl Module proto.UnimplementedModuleServer }
func (*GRPCServer) Generate ¶
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 ¶
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 ¶
NewGeneratorFunc is a function that returns a Generator.
Directories ¶
Path | Synopsis |
---|---|
Package generators contains all codes about the Spec generator mechanism.
|
Package generators contains all codes about the Spec generator mechanism. |