kubefox

package
v0.2.1-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MPL-2.0 Imports: 22 Imported by: 12

Documentation

Overview

+kubebuilder:object:generate=false

Index

Constants

View Source
const (
	LabelK8sComponent       string = "kubefox.xigxog.io/component"
	LabelK8sComponentCommit string = "kubefox.xigxog.io/component-commit"
	LabelK8sPlatform        string = "kubefox.xigxog.io/platform"
	LabelOCIComponent       string = "com.xigxog.kubefox.component"
	LabelOCICreated         string = "org.opencontainers.image.created"
	LabelOCIRevision        string = "org.opencontainers.image.revision"
	LabelOCISource          string = "org.opencontainers.image.source"
)

Labels

View Source
const (
	ValKeyHeader     = "header"
	ValKeyHost       = "host"
	ValKeyMethod     = "method"
	ValKeyPath       = "path"
	ValKeyQuery      = "queryParam"
	ValKeyStatusCode = "statusCode"
	ValKeyStatus     = "status"
	ValKeyURL        = "url"
	ValKeyTraceId    = "traceId"
	ValKeySpanId     = "spanId"
	ValKeyTraceFlags = "traceFlags"
)

Keys for well known values.

View Source
const (
	HeaderAbbrvDep       = "kf-dep"
	HeaderAbbrvEnv       = "kf-env"
	HeaderAbbrvEventType = "kf-type"
	HeaderAdapter        = "kubefox-adapter"
	HeaderDep            = "kubefox-deployment"
	HeaderEnv            = "kubefox-environment"
	HeaderEventType      = "kubefox-type"
	HeaderShortDep       = "kfd"
	HeaderShortEnv       = "kfe"
	HeaderShortEventType = "kft"
	HeaderTraceId        = "kubefox-trace-id"
)

Headers and query params.

View Source
const (
	CharSetUTF8 = "charset=UTF-8"

	DataSchemaKubefox = "xigxog.proto.v1.KubeFoxData"

	ContentTypeHTML     = "text/html"
	ContentTypeJSON     = "application/json"
	ContentTypePlain    = "text/plain"
	ContentTypeProtobuf = "application/protobuf"
)
View Source
const (
	CloudEventId = "ce_id"
)
View Source
const (
	DefaultRouteId = -1
)

Variables

View Source
var (
	ComponentName string
	GitCommit     string
	GitRef        string
)

Injected at build time

View Source
var (
	RegexpCommit = regexp.MustCompile(`^[0-9a-f]{40}$`)
	RegexpGitRef = regexp.MustCompile(`^[a-z0-9][a-z0-9-\\.]{0,28}[a-z0-9]$`)
	RegexpImage  = regexp.MustCompile(`^.*:[a-z0-9-]{7}$`)
	RegexpName   = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,28}[a-z0-9]$`)
	RegexpUUID   = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
)
View Source
var (
	KubeFoxHome = utils.EnvDef("KUBEFOX_HOME", path.Join("/", "tmp", "kubefox"))

	FileCACert  = "ca.crt"
	FileTLSCert = "tls.crt"
	FileTLSKey  = "tls.key"

	PathCACert      = path.Join(KubeFoxHome, FileCACert)
	PathSvcAccToken = "/var/run/secrets/kubernetes.io/serviceaccount/token"
	PathTLSCert     = path.Join(KubeFoxHome, FileTLSCert)
	PathTLSKey      = path.Join(KubeFoxHome, FileTLSKey)
)
View Source
var (
	Category_name = map[int32]string{
		0: "UNKNOWN",
		1: "MESSAGE",
		2: "REQUEST",
		3: "RESPONSE",
	}
	Category_value = map[string]int32{
		"UNKNOWN":  0,
		"MESSAGE":  1,
		"REQUEST":  2,
		"RESPONSE": 3,
	}
)

Enum value maps for Category.

View Source
var (
	ErrUnknownContentType = errors.New("unknown content type")
)
View Source
var File_protobuf_msgs_proto protoreflect.FileDescriptor

Functions

func GetParamOrHeader

func GetParamOrHeader(httpReq *http.Request, keys ...string) string

GetParamOrHeader looks for query parameters and headers for the provided keys. Keys are checked in order. Query parameters take precedence over headers.

func Version

func Version() string

Types

type Category

type Category int32
const (
	Category_UNKNOWN  Category = 0
	Category_MESSAGE  Category = 1
	Category_REQUEST  Category = 2
	Category_RESPONSE Category = 3
)

func (Category) Descriptor

func (Category) Descriptor() protoreflect.EnumDescriptor

func (Category) Enum

func (x Category) Enum() *Category

func (Category) EnumDescriptor deprecated

func (Category) EnumDescriptor() ([]byte, []int)

Deprecated: Use Category.Descriptor instead.

func (Category) Number

func (x Category) Number() protoreflect.EnumNumber

func (Category) String

func (x Category) String() string

func (Category) Type

type Component

type Component struct {
	Name   string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Commit string `protobuf:"bytes,2,opt,name=commit,proto3" json:"commit,omitempty"`
	Id     string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"`
	// contains filtered or unexported fields
}

func (*Component) Descriptor deprecated

func (*Component) Descriptor() ([]byte, []int)

Deprecated: Use Component.ProtoReflect.Descriptor instead.

func (*Component) DirectSubject

func (c *Component) DirectSubject() string

DirectSubject returns the name of the JetStream subject that Events sent directly from Broker to Component should be placed so they are accessible for replay and lookup. Use of this subject is not required if Events are sent using JetStream as they will be available on that subject.

func (*Component) Equal

func (lhs *Component) Equal(rhs *Component) bool

func (*Component) GetCommit

func (x *Component) GetCommit() string

func (*Component) GetId

func (x *Component) GetId() string

func (*Component) GetName

func (x *Component) GetName() string

func (*Component) GroupKey

func (c *Component) GroupKey() string

func (*Component) GroupSubject

func (c *Component) GroupSubject() string

func (*Component) IsEmpty

func (c *Component) IsEmpty() bool

func (*Component) IsFull

func (c *Component) IsFull() bool

func (*Component) Key

func (c *Component) Key() string

func (*Component) ProtoMessage

func (*Component) ProtoMessage()

func (*Component) ProtoReflect

func (x *Component) ProtoReflect() protoreflect.Message

func (*Component) Reset

func (x *Component) Reset()

func (*Component) ShortCommit

func (c *Component) ShortCommit() string

func (*Component) String

func (x *Component) String() string

func (*Component) Subject

func (c *Component) Subject() string

type ComponentReg

type ComponentReg struct {
	Routes         []*Route `json:"routes"`
	DefaultHandler bool     `json:"defaultHandler"`
}

type Event

type Event struct {
	Id       string   `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	ParentId string   `protobuf:"bytes,2,opt,name=parent_id,json=parentId,proto3" json:"parent_id,omitempty"`
	Type     string   `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
	Category Category `protobuf:"varint,4,opt,name=category,proto3,enum=kubefox.proto.v1.Category" json:"category,omitempty"`
	// Unix time in µs
	CreateTime int64 `protobuf:"varint,5,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
	// TTL in µs
	Ttl         int64                      `protobuf:"varint,6,opt,name=ttl,proto3" json:"ttl,omitempty"`
	Context     *EventContext              `protobuf:"bytes,7,opt,name=context,proto3" json:"context,omitempty"`
	Source      *Component                 `protobuf:"bytes,8,opt,name=source,proto3" json:"source,omitempty"`
	Target      *Component                 `protobuf:"bytes,9,opt,name=target,proto3" json:"target,omitempty"`
	Params      map[string]*structpb.Value `` /* 154-byte string literal not displayed */
	Values      map[string]*structpb.Value `` /* 154-byte string literal not displayed */
	ContentType string                     `protobuf:"bytes,14,opt,name=content_type,json=contentType,proto3" json:"content_type,omitempty"`
	Content     []byte                     `protobuf:"bytes,15,opt,name=content,proto3" json:"content,omitempty"`
	// contains filtered or unexported fields
}

func NewEvent

func NewEvent() *Event

func NewMsg

func NewMsg(opts EventOpts) *Event

func NewReq

func NewReq(opts EventOpts) *Event

func NewResp

func NewResp(opts EventOpts) *Event

func (*Event) AddHeader

func (evt *Event) AddHeader(key, value string) EventWriter

func (*Event) Bind

func (evt *Event) Bind(v any) error

func (*Event) BindStrict

func (evt *Event) BindStrict(v any) error

func (*Event) Bytes

func (evt *Event) Bytes() []byte

func (*Event) DelHeader

func (evt *Event) DelHeader(key string) EventWriter

func (*Event) DelQuery

func (evt *Event) DelQuery(key string) EventWriter

func (*Event) DelValueMapKey

func (evt *Event) DelValueMapKey(valKey, key string)

func (*Event) Descriptor deprecated

func (*Event) Descriptor() ([]byte, []int)

Deprecated: Use Event.ProtoReflect.Descriptor instead.

func (*Event) EventType

func (evt *Event) EventType() EventType

func (*Event) GetCategory

func (x *Event) GetCategory() Category

func (*Event) GetContent

func (x *Event) GetContent() []byte

func (*Event) GetContentType

func (x *Event) GetContentType() string

func (*Event) GetContext

func (x *Event) GetContext() *EventContext

func (*Event) GetCreateTime

func (x *Event) GetCreateTime() int64

func (*Event) GetId

func (x *Event) GetId() string

func (*Event) GetParams

func (x *Event) GetParams() map[string]*structpb.Value

func (*Event) GetParentId

func (x *Event) GetParentId() string

func (*Event) GetSource

func (x *Event) GetSource() *Component

func (*Event) GetTarget

func (x *Event) GetTarget() *Component

func (*Event) GetTtl

func (x *Event) GetTtl() int64

func (*Event) GetType

func (x *Event) GetType() string

func (*Event) GetValues

func (x *Event) GetValues() map[string]*structpb.Value

func (*Event) HTTPRequest

func (evt *Event) HTTPRequest(ctx context.Context) (*http.Request, error)

func (*Event) HTTPResponse

func (evt *Event) HTTPResponse() *http.Response

func (*Event) Header

func (evt *Event) Header(key string) string

func (*Event) HeaderAll

func (evt *Event) HeaderAll(key string) []string

func (*Event) HeaderDef

func (evt *Event) HeaderDef(key string, def string) string

func (*Event) HeaderV

func (evt *Event) HeaderV(key string) *Val

func (*Event) Param

func (evt *Event) Param(key string) string

func (*Event) ParamDef

func (evt *Event) ParamDef(key string, def string) string

func (*Event) ParamProto

func (evt *Event) ParamProto(key string) *structpb.Value

func (*Event) ParamV

func (evt *Event) ParamV(key string) *Val

func (*Event) ProtoMessage

func (*Event) ProtoMessage()

func (*Event) ProtoReflect

func (x *Event) ProtoReflect() protoreflect.Message

func (*Event) Query

func (evt *Event) Query(key string) string

func (*Event) QueryAll

func (evt *Event) QueryAll(key string) []string

func (*Event) QueryDef

func (evt *Event) QueryDef(key string, def string) string

func (*Event) QueryV

func (evt *Event) QueryV(key string) *Val

func (*Event) ReduceTTL

func (evt *Event) ReduceTTL(start time.Time) time.Duration

func (*Event) Reset

func (x *Event) Reset()

func (*Event) SetContext

func (evt *Event) SetContext(evtCtx *EventContext)

func (*Event) SetHTTPRequest

func (evt *Event) SetHTTPRequest(httpReq *http.Request) error

func (*Event) SetHTTPResponse

func (evt *Event) SetHTTPResponse(httpResp *http.Response) error

func (*Event) SetHeader

func (evt *Event) SetHeader(key, value string) EventWriter

func (*Event) SetHeaderV

func (evt *Event) SetHeaderV(key string, value *Val) EventWriter

func (*Event) SetJSON

func (evt *Event) SetJSON(v any) error

func (*Event) SetParam

func (evt *Event) SetParam(key string, val string) EventWriter

func (*Event) SetParamProto

func (evt *Event) SetParamProto(key string, val *structpb.Value) EventWriter

func (*Event) SetParamV

func (evt *Event) SetParamV(key string, val *Val) EventWriter

func (*Event) SetParent

func (evt *Event) SetParent(parent *Event)

func (*Event) SetQuery

func (evt *Event) SetQuery(key, value string) EventWriter

func (*Event) SetQueryV

func (evt *Event) SetQueryV(key string, value *Val) EventWriter

func (*Event) SetSpanId

func (evt *Event) SetSpanId(val string)

func (*Event) SetStatus

func (evt *Event) SetStatus(code int) EventWriter

func (*Event) SetStatusV

func (evt *Event) SetStatusV(val *Val) EventWriter

func (*Event) SetTraceFlags

func (evt *Event) SetTraceFlags(val byte)

func (*Event) SetTraceId

func (evt *Event) SetTraceId(val string)

func (*Event) SetValue

func (evt *Event) SetValue(key string, val string)

func (*Event) SetValueMap

func (evt *Event) SetValueMap(key string, m map[string][]string)

func (*Event) SetValueMapKey

func (evt *Event) SetValueMapKey(valKey, key, value string, overwrite bool)

func (*Event) SetValueProto

func (evt *Event) SetValueProto(key string, val *structpb.Value)

func (*Event) SetValueV

func (evt *Event) SetValueV(key string, val *Val)

func (*Event) SpanId

func (evt *Event) SpanId() string

func (*Event) Status

func (evt *Event) Status() int

func (*Event) StatusV

func (evt *Event) StatusV() *Val

func (*Event) Str

func (evt *Event) Str() string

func (*Event) String

func (x *Event) String() string

func (*Event) TTL

func (evt *Event) TTL() time.Duration

func (*Event) TraceFlags

func (evt *Event) TraceFlags() byte

func (*Event) TraceId

func (evt *Event) TraceId() string

func (*Event) Value

func (evt *Event) Value(key string) string

func (*Event) ValueMap

func (evt *Event) ValueMap(key string) map[string][]string

func (*Event) ValueMapKey

func (evt *Event) ValueMapKey(valKey, key string) string

func (*Event) ValueMapKeyAll

func (evt *Event) ValueMapKeyAll(valKey, key string) []string

func (*Event) ValueProto

func (evt *Event) ValueProto(key string) *structpb.Value

func (*Event) ValueV

func (evt *Event) ValueV(key string) *Val

type EventContext

type EventContext struct {
	Deployment  string `protobuf:"bytes,1,opt,name=deployment,proto3" json:"deployment,omitempty"`
	Environment string `protobuf:"bytes,2,opt,name=environment,proto3" json:"environment,omitempty"`
	Release     string `protobuf:"bytes,3,opt,name=release,proto3" json:"release,omitempty"`
	// contains filtered or unexported fields
}

func (*EventContext) Descriptor deprecated

func (*EventContext) Descriptor() ([]byte, []int)

Deprecated: Use EventContext.ProtoReflect.Descriptor instead.

func (*EventContext) GetDeployment

func (x *EventContext) GetDeployment() string

func (*EventContext) GetEnvironment

func (x *EventContext) GetEnvironment() string

func (*EventContext) GetRelease

func (x *EventContext) GetRelease() string

func (*EventContext) IsDeployment

func (ctx *EventContext) IsDeployment() bool

func (*EventContext) IsRelease

func (ctx *EventContext) IsRelease() bool

func (*EventContext) ProtoMessage

func (*EventContext) ProtoMessage()

func (*EventContext) ProtoReflect

func (x *EventContext) ProtoReflect() protoreflect.Message

func (*EventContext) Reset

func (x *EventContext) Reset()

func (*EventContext) String

func (x *EventContext) String() string

type EventOpts

type EventOpts struct {
	Type   EventType
	Parent *Event
	Source *Component
	Target *Component
}

type EventPredicate

type EventPredicate func(e *Event) bool

Takes an Event and returns true or false if rule matches.

type EventReader

type EventReader interface {
	EventType() EventType

	Param(key string) string
	ParamV(key string) *Val
	ParamDef(key string, def string) string

	Query(key string) string
	QueryV(key string) *Val
	QueryDef(key string, def string) string
	QueryAll(key string) []string

	Header(key string) string
	HeaderV(key string) *Val
	HeaderDef(key string, def string) string
	HeaderAll(key string) []string

	Status() int
	StatusV() *Val

	Bind(v any) error
	Str() string
	Bytes() []byte
}

type EventType

type EventType string
const (
	EventTypeComponent  EventType = "io.kubefox.component"
	EventTypeCron       EventType = "io.kubefox.cron"
	EventTypeDapr       EventType = "io.kubefox.dapr"
	EventTypeHTTP       EventType = "io.kubefox.http"
	EventTypeKubernetes EventType = "io.kubefox.kubernetes"
)

Component event types

const (
	EventTypeAck       EventType = "io.kubefox.ack"
	EventTypeBootstrap EventType = "io.kubefox.bootstrap"
	EventTypeError     EventType = "io.kubefox.error"
	EventTypeHealth    EventType = "io.kubefox.health"
	EventTypeMetrics   EventType = "io.kubefox.metrics"
	EventTypeNack      EventType = "io.kubefox.nack"
	EventTypeRegister  EventType = "io.kubefox.register"
	EventTypeRejected  EventType = "io.kubefox.rejected"
	EventTypeTelemetry EventType = "io.kubefox.telemetry"
	EventTypeUnknown   EventType = "io.kubefox.unknown"
)

Platform event types

type EventWriter

type EventWriter interface {
	EventReader

	SetParam(key, value string) EventWriter
	SetParamV(key string, value *Val) EventWriter

	SetQuery(key, value string) EventWriter
	SetQueryV(key string, value *Val) EventWriter
	DelQuery(key string) EventWriter

	SetHeader(key, value string) EventWriter
	SetHeaderV(key string, value *Val) EventWriter
	AddHeader(key, value string) EventWriter
	DelHeader(key string) EventWriter

	SetStatus(code int) EventWriter
	SetStatusV(val *Val) EventWriter
}

type MatchedEvent

type MatchedEvent struct {
	Event   *Event                     `protobuf:"bytes,1,opt,name=event,proto3" json:"event,omitempty"`
	Env     map[string]*structpb.Value `` /* 147-byte string literal not displayed */
	RouteId int64                      `protobuf:"varint,3,opt,name=route_id,json=routeId,proto3" json:"route_id,omitempty"`
	// contains filtered or unexported fields
}

func (*MatchedEvent) Descriptor deprecated

func (*MatchedEvent) Descriptor() ([]byte, []int)

Deprecated: Use MatchedEvent.ProtoReflect.Descriptor instead.

func (*MatchedEvent) GetEnv

func (x *MatchedEvent) GetEnv() map[string]*structpb.Value

func (*MatchedEvent) GetEvent

func (x *MatchedEvent) GetEvent() *Event

func (*MatchedEvent) GetRouteId

func (x *MatchedEvent) GetRouteId() int64

func (*MatchedEvent) ProtoMessage

func (*MatchedEvent) ProtoMessage()

func (*MatchedEvent) ProtoReflect

func (x *MatchedEvent) ProtoReflect() protoreflect.Message

func (*MatchedEvent) Reset

func (x *MatchedEvent) Reset()

func (*MatchedEvent) String

func (x *MatchedEvent) String() string

type Route

type Route struct {
	Id       int    `json:"id"`
	Rule     string `json:"rule"`
	Priority int    `json:"priority"`

	ResolvedRule string         `json:"-"`
	Predicate    EventPredicate `json:"-"`
	ParseErr     error          `json:"-"`

	Component    *Component    `json:"-"`
	EventContext *EventContext `json:"-"`
	// contains filtered or unexported fields
}

func (*Route) Match

func (r *Route) Match(evt *Event) (bool, error)

func (*Route) Resolve

func (r *Route) Resolve(envVars map[string]*Val) error

type Val

type Val struct {
	Type ValType `json:"-"`
	// contains filtered or unexported fields
}

+kubebuilder:object:generate=true

func ValArrayFloat

func ValArrayFloat(val []float64) *Val

func ValArrayInt

func ValArrayInt(val []int) *Val

func ValArrayString

func ValArrayString(val []string) *Val

func ValBool

func ValBool(val bool) *Val

func ValFloat

func ValFloat(val float64) *Val

func ValInt

func ValInt(val int) *Val

func ValNil

func ValNil() *Val

func ValProto

func ValProto(val *structpb.Value) (*Val, error)

func ValString

func ValString(val string) *Val

func (*Val) Any

func (val *Val) Any() any

func (*Val) ArrayFloat

func (val *Val) ArrayFloat() []float64

ArrayFloat returns the array value if type is ArrayNumber. Otherwise nil is returned.

func (*Val) ArrayInt

func (val *Val) ArrayInt() []int

ArrayInt returns the array value if type is ArrayNumber. Otherwise nil is returned.

func (*Val) ArrayString

func (val *Val) ArrayString() []string

ArrayString returns the array value if type is ArrayString or ArrayNumber. Otherwise nil is returned.

func (*Val) Bool

func (val *Val) Bool() bool

Bool returns the boolean value if type is Bool. If type is Number, false will be returned if value is 0, otherwise true is returned. If type is String, an attempt to parse the boolean value will be made. If parsing fails or type is Array false will be returned.

func (*Val) BoolDef

func (val *Val) BoolDef(def bool) bool

func (*Val) DeepCopy

func (in *Val) DeepCopy() *Val

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Val.

func (*Val) DeepCopyInto

func (in *Val) DeepCopyInto(out *Val)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Val) Float

func (val *Val) Float() float64

Float returns the float64 value if type is Number. If type is Bool 1 will be returned if true, otherwise 0 is returned. If type is String an attempt to parse the number will be made. If parsing fails or type is Array 0 will be returned.

func (*Val) FloatDef

func (val *Val) FloatDef(def float64) float64

func (*Val) Int

func (val *Val) Int() int

Int returns the int value if type is Number. If type is Bool 1 will be returned if true, otherwise 0 is returned. If type is String an attempt to parse the number will be made. If parsing fails or type is Array 0 will be returned.

func (*Val) IntDef

func (val *Val) IntDef(def int) int

func (*Val) IsArrayNumber

func (val *Val) IsArrayNumber() bool

func (*Val) IsArrayString

func (val *Val) IsArrayString() bool

func (*Val) IsBool

func (val *Val) IsBool() bool

func (*Val) IsNil

func (val *Val) IsNil() bool

func (*Val) IsNumber

func (val *Val) IsNumber() bool

func (*Val) IsString

func (val *Val) IsString() bool

func (*Val) IsUnknown

func (val *Val) IsUnknown() bool

func (*Val) MarshalJSON

func (val *Val) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*Val) Proto

func (val *Val) Proto() *structpb.Value

func (*Val) String

func (val *Val) String() string

String returns the string value if type is String. If type is Bool the `fmt.Sprintf("%t", bool)` of the bool value is returned. If type is Number the `fmt.Sprintf("%f", float)` of the number value is returned. If type is Array the JSON representation of the array is returned.

func (*Val) StringDef

func (val *Val) StringDef(def string) string

func (*Val) UnmarshalJSON

func (val *Val) UnmarshalJSON(value []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

type ValType

type ValType int

ValType represents the stored type of Var.

const (
	Unknown     ValType = iota // holds an unknown
	Nil                        // holds a null
	Bool                       // holds a boolean
	Number                     // holds an int or float
	String                     // holds a string
	ArrayNumber                // holds an array of ints or floats
	ArrayString                // holds an array of strings
)

Jump to

Keyboard shortcuts

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