Documentation
¶
Index ¶
- Constants
- Variables
- func EmptyResponse() *proto.GeneratorResponse
- 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, workingDir string) (*plugin.Client, error)
- func PatchHealthPolicyToExtension(resource *v1.Resource, healthPolicy string) error
- func PatchImportResourcesToExtension(resource *v1.Resource, importedResource string) error
- func PatchKubeConfigPathToExtension(resource *v1.Resource, kubeConfigPath string) error
- func PatchResource[T any](resources map[string][]*v1.Resource, gvk string, patchFunc func(*T) error) error
- func PluginDir() (string, error)
- func TerraformProviderExtensions(providerCfg ProviderConfig, resType string) (map[string]any, error)
- func TerraformProviderRegion(providerCfg ProviderConfig) string
- func TerraformResourceID(providerCfg ProviderConfig, resType, resName string) (string, error)
- func UniqueAppLabels(projectName, appName string) map[string]string
- func UniqueAppName(projectName, stackName, appName string) string
- func WrapK8sResourceToKusionResource(id string, resource runtime.Object) (*v1.Resource, error)
- func WrapTFResourceToKusionResource(providerCfg ProviderConfig, resType string, resourceID string, ...) (*v1.Resource, error)
- type FrameworkModule
- type FrameworkModuleWrapper
- type GRPCClient
- type GRPCPlugin
- type GRPCServer
- type GeneratorRequest
- type GeneratorResponse
- type Module
- type Plugin
- type ProviderConfig
Constants ¶
const ( DefaultModulePathEnv = "KUSION_MODULE_PATH" KusionModuleBinaryPrefix = "kusion-module-" Dir = "modules" )
const (
ImportIDKey = "kusionstack.io/import-id"
)
const PluginKey = "module-default"
Variables ¶
var ErrEmptyTFProviderVersion = errors.New("empty terraform provider version")
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 EmptyResponse ¶
func EmptyResponse() *proto.GeneratorResponse
EmptyResponse represents a legal but empty response. Interfaces should return an EmptyResponse instead of nil when the response is empty
func ForeachOrdered ¶ added in v0.2.3
ForeachOrdered executes the given function on each item in the map in order of their keys.
func GenericPtr ¶ added in v0.2.3
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 ID of a Kubernetes resource based on its type and metadata. Resource ID usually should be unique in one resource list.
func KusionPathDependency ¶ added in v0.2.3
KusionPathDependency returns the implicit resource dependency path based on the resource id and name with the "$kusion_path" prefix.
func MergeMaps ¶ added in v0.2.3
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.2.3
func PatchHealthPolicyToExtension ¶ added in v0.2.3
PatchHealthPolicyToExtension patch the health policy to the `extensions` field of the Kusion resource. Support Kubernetes resource only.
func PatchImportResourcesToExtension ¶ added in v0.2.3
PatchImportResourcesToExtension patch the imported resource to the `extensions` field of the Kusion resource. Support TF resource only.
func PatchKubeConfigPathToExtension ¶ added in v0.2.3
PatchKubeConfigPathToExtension patch the kubeConfig path to the `extensions` field of the Kusion resource. 1. If $KUBECONFIG environment variable is set, then it is used. 2. If not, and the `kubeConfig` in resource extensions is set, then it is used. 3. Otherwise, ${HOME}/.kube/config is used.
func PatchResource ¶ added in v0.2.3
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 TerraformProviderExtensions ¶
func TerraformProviderExtensions(providerCfg ProviderConfig, resType string) (map[string]any, error)
TerraformProviderExtensions returns the Kusion resource extension of the Terraform provider.
func TerraformProviderRegion ¶
func TerraformProviderRegion(providerCfg ProviderConfig) string
TerraformProviderRegion returns the resource region from the Terraform provider configs.
func TerraformResourceID ¶
func TerraformResourceID(providerCfg ProviderConfig, resType, resName string) (string, error)
TerraformResourceID returns the Kusion resource ID of the Terraform resource. Resource ID usually should be unique in one resource list.
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.
func WrapTFResourceToKusionResource ¶
func WrapTFResourceToKusionResource( providerCfg ProviderConfig, resType string, resourceID string, attributes map[string]interface{}, dependsOn []string, ) (*v1.Resource, error)
WrapTFResourceToKusionResource wraps the Terraform resource into the format of the Kusion resource.
Types ¶
type FrameworkModule ¶
type FrameworkModule interface {
Generate(ctx context.Context, req *GeneratorRequest) (*GeneratorResponse, error)
}
type FrameworkModuleWrapper ¶
type FrameworkModuleWrapper struct { // Module is the actual FrameworkModule implemented by platform engineers Module FrameworkModule }
FrameworkModuleWrapper is a module that implements the proto Module interface. It wraps a dev-centric FrameworkModule into a proto Module
func (*FrameworkModuleWrapper) Generate ¶
func (f *FrameworkModuleWrapper) Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error)
type GRPCClient ¶ added in v0.2.3
type GRPCClient struct {
// contains filtered or unexported fields
}
func (*GRPCClient) Generate ¶ added in v0.2.3
func (c *GRPCClient) Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error)
type GRPCPlugin ¶ added in v0.2.3
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.2.3
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.2.3
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.2.3
type GRPCServer struct { // This is the real implementation Impl Module proto.UnimplementedModuleServer }
func (*GRPCServer) Generate ¶ added in v0.2.3
func (s *GRPCServer) Generate(ctx context.Context, req *proto.GeneratorRequest) (res *proto.GeneratorResponse, err error)
type GeneratorRequest ¶
type GeneratorRequest struct { // Project represents the project name Project string `json:"project" yaml:"project"` // Stack represents the stack name Stack string `json:"stack" yaml:"stack"` // App represents the application name, which is typically the same as the namespace of Kubernetes resources App string `json:"app" yaml:"app"` // Workload represents the workload configuration Workload v1.Accessory `json:"workload,omitempty" yaml:"workload,omitempty"` // DevConfig is the developer's inputs of this module DevConfig v1.Accessory `json:"devConfig,omitempty" yaml:"devConfig,omitempty"` // PlatformConfig is the platform engineer's inputs of this module PlatformConfig v1.GenericConfig `json:"platformConfig,omitempty" yaml:"platformConfig,omitempty"` // Context contains workspace-level configurations, such as topologies, server endpoints, metadata, etc. Context v1.GenericConfig `yaml:"context,omitempty" json:"context,omitempty"` // SecretStore represents a secure external location for storing secrets. SecretStore v1.SecretStore `yaml:"secretStore,omitempty" json:"secretStore,omitempty"` }
func NewGeneratorRequest ¶
func NewGeneratorRequest(req *proto.GeneratorRequest) (*GeneratorRequest, error)
type GeneratorResponse ¶
type Module ¶ added in v0.2.3
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 Plugin ¶ added in v0.2.3
type Plugin struct { // Module represents the real module impl Module Module ModuleName string // contains filtered or unexported fields }
func (*Plugin) KillPluginClient ¶ added in v0.2.3
type ProviderConfig ¶ added in v0.2.0
type ProviderConfig struct { // Source of the provider. Source string `yaml:"source" json:"source"` // Version of the provider. Version string `yaml:"version" json:"version"` // ProviderMeta is used to describe configs in the terraform hcl "provider" block. ProviderMeta v1.GenericConfig `yaml:"providerMeta" json:"providerMeta"` }
ProviderConfig contains the full configurations of a specified provider. It is the combination of the specified provider's config in blocks "terraform.required_providers" and "providers" in the terraform hcl file, where the former is described by fields Source and Version, and the latter is described by ProviderMeta.