core

package
v0.8.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ServiceTypeSystem    = "system-service"
	ServiceTypeNamespace = "namespace-service"
	ServiceTypeWorkflow  = "workflow-service"
)
View Source
const SystemNamespace = "system"

Variables

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

Functions

This section is empty.

Types

type App

type App struct {
	Version *Version
	Config  *Config

	ServiceManager  ServiceManager
	RegistryManager RegistryManager
	GatewayManager  GatewayManager
	SyncNamespace   SyncNamespace
}

type Circuit

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

nolint: containedctx

func NewCircuit

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

func (*Circuit) Context

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

func (*Circuit) Done

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

func (*Circuit) IsDone

func (c *Circuit) IsDone() bool

func (*Circuit) OnCancel

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

func (*Circuit) Start

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

func (c *Circuit) Wait()

type Config

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

	LogDebug bool `env:"DIREKTIV_DEBUG"`

	ApiPort int `env:"DIREKTIV_API_PORT" envDefault:"6665"`

	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"`

	DisableServices bool `env:"DIREKTIV_DISABLE_SERVICES" envDefault:"false"`

	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"`

	IsEnterprise bool `env:"DIREKTIV_IS_ENTERPRISE" envDefault:"false"`
}

nolint:revive,stylecheck

func (*Config) GetFunctionsReconcileInterval

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

func (*Config) GetFunctionsTimeout

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

func (*Config) Init

func (conf *Config) Init() error

type Consumer

type Consumer struct {
	ConsumerFile

	Namespace string
	FilePath  string

	Errors []string
}

func ParseConsumerFile

func ParseConsumerFile(ns string, filePath string, data []byte) Consumer

type ConsumerFile

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

type ContextKey

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

type Endpoint struct {
	EndpointFile

	Namespace string
	FilePath  string

	Errors []string
}

func ParseEndpointFile

func ParseEndpointFile(ns string, filePath string, data []byte) Endpoint

type EndpointFile

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

type EnvironmentVariable

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

type GatewayManager

type GatewayManager interface {
	http.Handler

	SetEndpoints(list []Endpoint, cList []Consumer) error
}

type LogEntry

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

type LogStatus

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

type Plugin

type Plugin interface {
	// NewInstance method creates new plugin instance
	NewInstance(config PluginConfig) (Plugin, error)

	Execute(w http.ResponseWriter, r *http.Request) *http.Request
	Type() string
}

type PluginConfig

type PluginConfig struct {
	Typ    string         `json:"type"                    yaml:"type"`
	Config map[string]any `json:"configuration,omitempty" yaml:"configuration"`
}

type PluginsConfig

type PluginsConfig struct {
	Auth     []PluginConfig `yaml:"auth"`
	Inbound  []PluginConfig `yaml:"inbound"`
	Target   PluginConfig   `yaml:"target"`
	Outbound []PluginConfig `yaml:"outbound"`
}

type Registry

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

type RegistryManager

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

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

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

type ServiceFileData

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

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

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

type ServiceManager interface {
	Run(circuit *Circuit) error
	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

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

type SyncNamespace

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

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