core

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceTypeNamespace = "namespace-service"
	ServiceTypeWorkflow  = "workflow-service"
)
View Source
const MagicalGatewayNamespace = "gateway"

Variables

View Source
var ErrNotFound = errors.New("ErrNotFound")

Functions

This section is empty.

Types

type App added in v0.8.1

type App struct {
	Version *Version
	Config  *Config

	ServiceManager  ServiceManager
	RegistryManager RegistryManager
	GatewayManager  GatewayManager
	SyncNamespace   SyncNamespace
}

type Circuit added in v0.8.5

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

nolint: containedctx

func NewCircuit added in v0.8.5

func NewCircuit(parent context.Context, signals ...os.Signal) *Circuit

func (*Circuit) Context added in v0.8.5

func (c *Circuit) Context() context.Context

func (*Circuit) Done added in v0.8.5

func (c *Circuit) Done() <-chan struct{}

func (*Circuit) IsDone added in v0.8.5

func (c *Circuit) IsDone() bool

func (*Circuit) OnCancel added in v0.8.5

func (c *Circuit) OnCancel(f func())

func (*Circuit) Start added in v0.8.5

func (c *Circuit) Start(job func() error)

Start lunches a goroutine and tracking it via a sync.WaitGroup. It enables simplified api to lunch graceful go routines.

func (*Circuit) Wait added in v0.8.5

func (c *Circuit) Wait()

type Config added in v0.8.1

type Config struct {
	DirektivNamespace string `env:"DIREKTIV_NAMESPACE"`

	LogFormat string `env:"DIREKTIV_LOG_FORMAT"`
	LogDebug  bool   `env:"DIREKTIV_DEBUG"`

	ApiV1Port int `env:"DIREKTIV_API_V1_PORT" envDefault:"6665"`
	ApiV2Port int `env:"DIREKTIV_API_V2_PORT" envDefault:"6667"`
	GrpcPort  int `env:"DIREKTIV_GRPC_PORT"   envDefault:"6666"`

	ApiKey    string `env:"DIREKTIV_API_KEY"`
	SecretKey string `env:"DIREKTIV_SECRET_KEY,notEmpty"`
	DB        string `env:"DIREKTIV_DB,notEmpty"`

	FunctionsTimeout int `env:"DIREKTIV_FUNCTIONS_TIMEOUT" envDefault:"7200"`

	Prometheus     string `env:"DIREKTIV_PROMETHEUS_BACKEND"`
	OpenTelemetry  string `env:"DIREKTIV_OPEN_TELEMETRY_BACKEND"`
	EnableEventing bool   `env:"DIREKTIV_ENABLE_EVENTING"`

	EnableDocker bool `env:"DIREKITV_ENABLE_DOCKER"`

	KnativeServiceAccount string `env:"DIREKTIV_KNATIVE_SERVICE_ACCOUNT"`
	KnativeNamespace      string `env:"DIREKTIV_KNATIVE_NAMESPACE"`
	KnativeIngressClass   string `env:"DIREKTIV_KNATIVE_INGRESS_CLASS"`
	KnativeSidecar        string `env:"DIREKTIV_KNATIVE_SIDECAR"`
	KnativeMaxScale       int    `env:"DIREKTIV_KNATIVE_MAX_SCALE"       envDefault:"5"`
	KnativeNetShape       string `env:"DIREKTIV_KNATIVE_NET_SHAPE"`

	KnativeSizeMemorySmall  int `env:"DIREKTIV_KNATIVE_SIZE_MEMORY_SMALL"  envDefault:"512"`
	KnativeSizeMemoryMedium int `env:"DIREKTIV_KNATIVE_SIZE_MEMORY_MEDIUM" envDefault:"1024"`
	KnativeSizeMemoryLarge  int `env:"DIREKTIV_KNATIVE_SIZE_MEMORY_LARGE"  envDefault:"2048"`

	KnativeSizeCPUSmall  string `env:"DIREKTIV_KNATIVE_SIZE_CPU_SMALL"  envDefault:"250m"`
	KnativeSizeCPUMedium string `env:"DIREKTIV_KNATIVE_SIZE_CPU_MEDIUM" envDefault:"500m"`
	KnativeSizeCPULarge  string `env:"DIREKTIV_KNATIVE_SIZE_CPU_LARGE"  envDefault:"1"`

	KnativeSizeDiskSmall  int `env:"DIREKTIV_KNATIVE_SIZE_DISK_SMALL"  envDefault:"256"`
	KnativeSizeDiskMedium int `env:"DIREKTIV_KNATIVE_SIZE_DISK_MEDIUM" envDefault:"1024"`
	KnativeSizeDiskLarge  int `env:"DIREKTIV_KNATIVE_SIZE_DISK_LARGE"  envDefault:"4096"`

	KnativeProxyNo    string `env:"DIREKTIV_KNATIVE_PROXY_NO"`
	KnativeProxyHTTP  string `env:"DIREKTIV_KNATIVE_PROXY_HTTP"`
	KnativeProxyHTTPS string `env:"DIREKTIV_KNATIVE_PROXY_HTTPS"`

	FunctionsReconcileInterval int `env:"DIREKTIV_FUNCTIONS_RECONCILE_INTERVAL" envDefault:"1"`
}

nolint:revive,stylecheck

func (*Config) GetFunctionsReconcileInterval added in v0.8.1

func (conf *Config) GetFunctionsReconcileInterval() time.Duration

func (*Config) GetFunctionsTimeout added in v0.8.1

func (conf *Config) GetFunctionsTimeout() time.Duration

func (*Config) Init added in v0.8.5

func (conf *Config) Init() error

type ConsumerFile added in v0.8.1

type ConsumerFile struct {
	DirektivAPI string   `json:"-"        yaml:"direktiv_api"`
	Username    string   `json:"username" yaml:"username"`
	Password    string   `json:"password" yaml:"password"`
	APIKey      string   `json:"api_key"  yaml:"api_key"`
	Tags        []string `json:"tags"     yaml:"tags"`
	Groups      []string `json:"groups"   yaml:"groups"`
}

func ParseConsumerFile added in v0.8.1

func ParseConsumerFile(data []byte) (*ConsumerFile, error)

type ContextKey added in v0.8.4

type ContextKey string
const (
	// LogTrackKey is used for tracking related log entries, facilitating the organization of logs in sequences or chains.
	LogTrackKey ContextKey = "track"
	// LogTagsKey allows for adding structural metadata to log entries, for categorization based on their origin and context.
	LogTagsKey ContextKey = "tags"
)

type Endpoint added in v0.8.1

type Endpoint struct {
	Namespace  string `json:"-"`
	FilePath   string `json:"file_path,omitempty"`
	Path       string `json:"path,omitempty"`
	ServerPath string `json:"server_path"`

	Methods        []string `json:"methods"`
	AllowAnonymous bool     `json:"allow_anonymous"`
	Timeout        int      `json:"timeout"`

	AuthPluginInstances     []PluginInstance `json:"-"`
	InboundPluginInstances  []PluginInstance `json:"-"`
	TargetPluginInstance    PluginInstance   `json:"-"`
	OutboundPluginInstances []PluginInstance `json:"-"`
	Errors                  []string         `json:"errors"`
	Warnings                []string         `json:"warnings"`

	Plugins Plugins `json:"plugins"`
}

type EndpointFile added in v0.8.1

type EndpointFile struct {
	DirektivAPI    string   `json:"-"               yaml:"direktiv_api"`
	Methods        []string `json:"methods"         yaml:"methods"`
	Path           string   `json:"path"            yaml:"path"`
	AllowAnonymous bool     `json:"allow_anonymous" yaml:"allow_anonymous"`
	Plugins        Plugins  `json:"plugins"         yaml:"plugins"`
	Timeout        int      `json:"timeout"         yaml:"timeout"`
}

func ParseEndpointFile added in v0.8.1

func ParseEndpointFile(data []byte) (*EndpointFile, error)

type EnvironmentVariable added in v0.8.1

type EnvironmentVariable struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type GatewayManager added in v0.8.1

type GatewayManager interface {
	http.Handler

	DeleteNamespace(namespace string)
	UpdateNamespace(namespace string)
	UpdateAll()

	GetConsumers(namespace string) ([]*ConsumerFile, error)
	GetRoutes(namespace string, filteredPath string) ([]*Endpoint, error)
}

type LogEntry added in v0.8.4

type LogEntry struct {
	ID   int
	Time time.Time
	Tag  string
	Data map[string]interface{}
}

type LogStatus added in v0.8.4

type LogStatus string
const (
	LogErrStatus       LogStatus = "error"
	LogUnknownStatus   LogStatus = "unknown"
	LogRunningStatus   LogStatus = "running"
	LogFailedStatus    LogStatus = "failed"
	LogCompletedStatus LogStatus = "completed"
)

type PluginConfig added in v0.8.1

type PluginConfig struct {
	Type          string                 `json:"type,omitempty"          yaml:"type"`
	Configuration map[string]interface{} `json:"configuration,omitempty" yaml:"configuration"`
}

type PluginInstance added in v0.8.1

type PluginInstance interface {
	ExecutePlugin(c *ConsumerFile,
		w http.ResponseWriter, r *http.Request) bool
	Config() interface{}
	Type() string
}

type Plugins added in v0.8.1

type Plugins struct {
	Auth     []PluginConfig `json:"auth,omitempty"     yaml:"auth"`
	Inbound  []PluginConfig `json:"inbound,omitempty"  yaml:"inbound"`
	Target   *PluginConfig  `json:"target,omitempty"   yaml:"target"`
	Outbound []PluginConfig `json:"outbound,omitempty" yaml:"outbound"`
}

type Registry added in v0.8.1

type Registry struct {
	Namespace string `json:"namespace"`
	ID        string `json:"id"`
	URL       string `json:"url"`
	User      string `json:"user"`
	Password  string `json:"password,omitempty"`
}

type RegistryManager added in v0.8.1

type RegistryManager interface {
	ListRegistries(namespace string) ([]*Registry, error)
	DeleteRegistry(namespace string, id string) error
	DeleteNamespace(namespace string) error
	StoreRegistry(registry *Registry) (*Registry, error)
	TestLogin(registry *Registry) error
}

type ServiceFile added in v0.8.3

type ServiceFile struct {
	DirektivAPI string                `yaml:"direktiv_api"`
	Image       string                `json:"image"        yaml:"image"`
	Cmd         string                `json:"cmd"          yaml:"cmd"`
	Size        string                `json:"size"         yaml:"size"`
	Scale       int                   `json:"scale"        yaml:"scale"`
	Envs        []EnvironmentVariable `json:"envs"         yaml:"envs"`
	Patches     []ServicePatch        `json:"patches"      yaml:"patches"`
}

func ParseServiceFile added in v0.8.3

func ParseServiceFile(data []byte) (*ServiceFile, error)

type ServiceFileData added in v0.8.3

type ServiceFileData struct {
	// identification fields:
	ID        string `json:"id"`
	Typ       string `json:"type"`
	Namespace string `json:"namespace"`
	FilePath  string `json:"filePath"`
	Name      string `json:"name"`

	// data fields:
	ServiceFile

	// status fields:
	Error      *string `json:"error"`
	Conditions any     `json:"conditions"`
}

ServiceFileData extends ServiceFile with identifications and status fields.

func (*ServiceFileData) GetID added in v0.8.3

func (c *ServiceFileData) GetID() string

GetID calculates a unique id string based on identification fields. This id helps in comparison different lists of objects.

func (*ServiceFileData) GetValueHash added in v0.8.3

func (c *ServiceFileData) GetValueHash() string

GetValueHash calculates a unique hash string based on the settings fields. This hash helps in comparing different lists of objects.

type ServiceManager added in v0.8.1

type ServiceManager interface {
	Start(circuit *Circuit)
	SetServices(list []*ServiceFileData)
	GeAll(namespace string) ([]*ServiceFileData, error)
	GetPods(namespace string, serviceID string) (any, error)
	StreamLogs(namespace string, serviceID string, podID string) (io.ReadCloser, error)
	Rebuild(namespace string, serviceID string) error
}

type ServicePatch added in v0.8.1

type ServicePatch struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value"`
}

type SyncNamespace added in v0.8.5

type SyncNamespace func(namespace any, mirrorConfig any) (any, error)

TODO: Fix this temp type. SyncNamespace is a temporary type until we fix mirroring logic.

type Version added in v0.8.1

type Version struct {
	UnixTime int64 `json:"unix_time"`
}

Jump to

Keyboard shortcuts

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