kubefox

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: MPL-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigurationErrorCode   = 10
	JetStreamErrorCode       = 11
	RpcServerErrorCode       = 12
	HTTPServerErrorCode      = 13
	TelemetryServerErrorCode = 14
	InterruptCode            = 130
)

OS status codes

View Source
const (
	ComponentRequestType   = "io.kubefox.component_request"
	ComponentResponseType  = "io.kubefox.component_response"
	CronRequestType        = "io.kubefox.cron_request"
	CronResponseType       = "io.kubefox.cron_response"
	DaprRequestType        = "io.kubefox.dapr_request"
	DaprResponseType       = "io.kubefox.dapr_response"
	HTTPRequestType        = "io.kubefox.http_request"
	HTTPResponseType       = "io.kubefox.http_response"
	KubernetesRequestType  = "io.kubefox.kubernetes_request"
	KubernetesResponseType = "io.kubefox.kubernetes_response"
)

Component event types

View Source
const (
	BootstrapRequestType  = "io.kubefox.bootstrap_request"
	BootstrapResponseType = "io.kubefox.bootstrap_response"
	FabricRequestType     = "io.kubefox.fabric_request"
	FabricResponseType    = "io.kubefox.fabric_response"
)

Platform event types

Update `IsPlatformEvent()` in event.go if changes are made.

View Source
const (
	HealthRequestType     = "io.kubefox.health_request"
	HealthResponseType    = "io.kubefox.health_response"
	MetricsRequestType    = "io.kubefox.metrics_request"
	MetricsResponseType   = "io.kubefox.metrics_response"
	TelemetryRequestType  = "io.kubefox.telemetry_request"
	TelemetryResponseType = "io.kubefox.telemetry_response"

	ErrorEventType    = "io.kubefox.error"
	RejectedEventType = "io.kubefox.rejected"
	UnknownEventType  = "io.kubefox.unknown"
)

Internal event types

View Source
const (
	EnvHeader       = "kf-environment"
	EnvHeaderShort  = "kf-env"
	SysHeader       = "kf-system"
	SysHeaderShort  = "kf-sys"
	TargetHeader    = "kf-target"
	EventTypeHeader = "kf-event-type"

	RelEnvHeader       = "kf-release-environment"
	RelSysHeader       = "kf-release-system"
	RelTargetHeader    = "kf-release-target"
	RelEventTypeHeader = "kf-release-event-type"
)

KubeFox headers/query params

Variables

View Source
var (
	ErrChannelNotFound       = errors.New("a channel with that id was not found")
	ErrComponentNameNotFound = errors.New("component name not found, environment variable `UNIT_NAME` should be set")
	ErrDuplicateChannel      = errors.New("a channel with that id already exists")
	ErrEntrypointNotFound    = errors.New("a matching entrypoint was not found")
	ErrInvalidEnvironment    = errors.New("invalid environment")
	ErrInvalidSystem         = errors.New("invalid environment")
	ErrInvalidTarget         = errors.New("provided KubeFox target component is invalid")
	ErrMissingEnvironment    = errors.New("request is missing KubeFox Environment")
	ErrMissingId             = errors.New("id is missing")
	ErrMissingMetadata       = errors.New("request is missing metadata")
	ErrMissingRequestId      = errors.New("request id is missing")
	ErrMissingRequestor      = errors.New("requestor is missing")
	ErrMissingResponder      = errors.New("responder is missing")
	ErrMissingSystem         = errors.New("request is missing KubeFox System")
	ErrMissingSysRef         = errors.New("request is missing KubeFox SysRef")
	ErrMissingTarget         = errors.New("request is missing KubeFox target Component")
	ErrNotFound              = errors.New("not found")
	ErrSubscriptionClosed    = errors.New("subscription closed, unable to fetch")
	ErrSubscriptionExists    = errors.New("a component as already subscribed")
	ErrSubscriptionNotFound  = errors.New("a subscription with that id was not found")
	ErrTypeMismatch          = errors.New("event type mismatch")
	ErrUnsupportedRequest    = errors.New("request type is not supported")
)

Functions

func IsPlatformEvent

func IsPlatformEvent(evt DataEvent) bool

func NewHTTPClient

func NewHTTPClient() *http.Client

Types

type ComponentSvc

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

func (*ComponentSvc) Invoke

func (svc *ComponentSvc) Invoke(req Event) (Event, error)

type ContextKey

type ContextKey string
const (
	KitContextKey ContextKey = "KitContext"
)
const (
	LogContextKey ContextKey = "LogContext"
)

type CustomizeResponse

type CustomizeResponse struct {
	RelatedResourceRules []*RelatedResourceRule `json:"relatedResources,omitempty"`
}

type DataEvent

type DataEvent interface {
	Event

	GetData() *grpc.Data

	ChildEvent() DataEvent
	ChildErrorEvent(error) DataEvent

	SetParent(Event)
	SetParentId(string)

	SetSource(component.Component, string)
	SetTarget(component.Component)

	SetContext(*grpc.EventContext)

	GetFabric() *grpc.Fabric
	SetFabric(*grpc.Fabric)

	SetSpan(*grpc.Span)
	UpdateSpan(trace.Span)

	SetToken(jwt.Token)
	SetValue(string, string)
	SetValueNumber(string, float64)

	HTTPData() HTTPDataEvent
	KubeData() KubeDataEvent

	SetError(error)
	GetError() error
	GetErrorMsg() string
}

func EmptyDataEvent

func EmptyDataEvent() DataEvent

func EventFromData

func EventFromData(data *grpc.Data) DataEvent

func NewDataEvent

func NewDataEvent(eventType string) DataEvent

func NewErrorEvent

func NewErrorEvent(err error) DataEvent

type Entrypoint

type Entrypoint func(Kit) error

type EntrypointMatcher

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

func (*EntrypointMatcher) Match

func (m *EntrypointMatcher) Match(evt DataEvent) bool

func (*EntrypointMatcher) Rule

func (m *EntrypointMatcher) Rule() string

type Event

type Event interface {
	GetId() string
	GetParentId() string

	GetType() string
	SetType(string)

	GetToken() *grpc.Token
	GetSpan() *grpc.Span
	GetTraceId() string
	GetSource() component.Component
	GetTarget() component.Component
	GetContext() *grpc.EventContext

	GetArg(string) string
	GetArgVar(string) *common.Var
	SetArg(string, string)
	SetArgNumber(string, float64)
	GetValue(string) string
	GetValueVar(string) *common.Var

	GetContentType() string
	SetContentType(string)
	GetContent() []byte
	SetContent([]byte)
	Marshal(any) error
	Unmarshal(any) error
	UnmarshalStrict(any) error

	HTTP() HTTPEvent
	Kube() KubeEvent
}

TODO create interfaces for grpc stuff

func NewEvent

func NewEvent(eventType string) Event

type EventMatcher

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

func NewEventMatcher

func NewEventMatcher(rule string) (*EventMatcher, error)

func (*EventMatcher) Match

func (m *EventMatcher) Match(e Event) bool

func (*EventMatcher) Rule

func (m *EventMatcher) Rule() string

type HTTPDataEvent

type HTTPDataEvent interface {
	DataEvent
	HTTPEvent

	ParseRequest(*http.Request) error
	ParseResponse(*http.Response) error

	GetHTTPRequest(context.Context) (*http.Request, error)
	GetHTTPResponse() *http.Response

	SetURL(*url.URL)
	SetURLString(string) error
}

type HTTPEvent

type HTTPEvent interface {
	Event

	GetURL() *url.URL
	GetURLString() string
	GetPath() string

	GetStatus() string
	SetStatus(v string)
	GetStatusCode() int
	SetStatusCode(v int)
	GetMethod() string
	SetMethod(method string)

	GetHeaderKeys() []string
	GetHeader(string) string
	GetHeaderValues(string) []string
	AddHeader(string, string)
	SetHeader(string, string)
	GetHTTPHeader() http.Header
	SetHTTPHeader(http.Header)
}

type Hook

type Hook uint8
const (
	Unknown Hook = iota
	Customize
	Sync
)

func (Hook) String

func (h Hook) String() string

type Kit

type Kit interface {
	Env(string) *common.Var

	Request() Event
	Response() Event

	Component(string) *ComponentSvc

	// Organization() string
	Platform() string
	Namespace() string
	DevMode() bool

	Ctx() context.Context
	Log() *logger.Log
}

type KitBroker

type KitBroker interface {
	InvokeTarget(DataEvent) (DataEvent, error)
}

type KitRoundTripper

type KitRoundTripper struct{}

func (*KitRoundTripper) RoundTrip

func (rt *KitRoundTripper) RoundTrip(httpReq *http.Request) (*http.Response, error)

type KitSvc

type KitSvc interface {
	Start()
	Http(string, Entrypoint)
	Kubernetes(string, Entrypoint)
	MatchEvent(string, Entrypoint)
	DefaultEntrypoint(Entrypoint)

	// Organization() string
	Platform() string
	Namespace() string
	DevMode() bool

	Fatal(err error)
	Log() *logger.Log
}

func New

func New() KitSvc

type KubeDataEvent

type KubeDataEvent interface {
	DataEvent
	KubeEvent
}

type KubeEvent

type KubeEvent interface {
	Event

	GetHook() Hook
	GetTargetKind() string
}

type KubeResponse

type KubeResponse struct {
	Attachments []runtime.Object `json:"attachments"`
	Status      any              `json:"status,omitempty"`
}

type ObjectStub

type ObjectStub struct {
	Kind string `json:"kind"`
}

type RelatedResourceRule

type RelatedResourceRule struct {
	APIVersion    string                `json:"apiVersion"`
	Resource      string                `json:"resource"`
	Namespace     string                `json:"namespace,omitempty"`
	Names         []string              `json:"names,omitempty"`
	LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
}

type RequestStub

type RequestStub struct {
	Object *ObjectStub `json:"object"` // for sync requests
	Parent *ObjectStub `json:"parent"` // for customize requests
}

Jump to

Keyboard shortcuts

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